mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-14 00:14:11 +09:00
[client,SDL] Handle window sizing on scaled displays
This commit is contained in:
@@ -1084,6 +1084,7 @@ bool SdlContext::handleEvent(const SDL_WindowEvent& ev)
|
||||
case SDL_EVENT_WINDOW_MOUSE_ENTER:
|
||||
return restoreCursor();
|
||||
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
|
||||
window->resizeToScale();
|
||||
if (isConnected())
|
||||
{
|
||||
if (!window->fill())
|
||||
|
||||
@@ -49,20 +49,20 @@ SdlWindow::SdlWindow(SDL_DisplayID id, const std::string& title, const SDL_Rect&
|
||||
_window = SDL_CreateWindowWithProperties(props);
|
||||
SDL_DestroyProperties(props);
|
||||
|
||||
auto sc = scale();
|
||||
const int iscale = static_cast<int>(sc * 100.0f);
|
||||
auto w = 100 * rect.w / iscale;
|
||||
auto h = 100 * rect.h / iscale;
|
||||
std::ignore = resize({ w, h });
|
||||
SDL_SetHint(SDL_HINT_APP_NAME, "");
|
||||
std::ignore = SDL_SyncWindow(_window);
|
||||
|
||||
_monitor = query(_window, id, true);
|
||||
|
||||
_intended_w = rect.w;
|
||||
_intended_h = rect.h;
|
||||
resizeToScale();
|
||||
}
|
||||
|
||||
SdlWindow::SdlWindow(SdlWindow&& other) noexcept
|
||||
: _window(other._window), _displayID(other._displayID), _offset_x(other._offset_x),
|
||||
_offset_y(other._offset_y), _monitor(other._monitor)
|
||||
_offset_y(other._offset_y), _monitor(other._monitor), _intended_w(other._intended_w),
|
||||
_intended_h(other._intended_h)
|
||||
{
|
||||
other._window = nullptr;
|
||||
}
|
||||
@@ -218,6 +218,22 @@ bool SdlWindow::resize(const SDL_Point& size)
|
||||
return SDL_SetWindowSize(_window, size.x, size.y);
|
||||
}
|
||||
|
||||
void SdlWindow::resizeToScale()
|
||||
{
|
||||
if (!_window)
|
||||
return;
|
||||
if (_intended_w <= 0 || _intended_h <= 0)
|
||||
return;
|
||||
if (SDL_GetWindowFlags(_window) & SDL_WINDOW_FULLSCREEN)
|
||||
return;
|
||||
|
||||
auto sc = scale();
|
||||
const int iscale = static_cast<int>(sc * 100.0f);
|
||||
auto w = 100 * _intended_w / iscale;
|
||||
auto h = 100 * _intended_h / iscale;
|
||||
std::ignore = resize({ w, h });
|
||||
}
|
||||
|
||||
bool SdlWindow::drawRect(SDL_Surface* surface, SDL_Point offset, const SDL_Rect& srcRect)
|
||||
{
|
||||
WINPR_ASSERT(surface);
|
||||
|
||||
@@ -67,6 +67,7 @@ class SdlWindow
|
||||
void minimize();
|
||||
|
||||
[[nodiscard]] bool resize(const SDL_Point& size);
|
||||
void resizeToScale();
|
||||
|
||||
[[nodiscard]] bool drawRect(SDL_Surface* surface, SDL_Point offset, const SDL_Rect& srcRect);
|
||||
[[nodiscard]] bool drawRects(SDL_Surface* surface, SDL_Point offset,
|
||||
@@ -107,4 +108,6 @@ class SdlWindow
|
||||
Sint32 _offset_x = 0;
|
||||
Sint32 _offset_y = 0;
|
||||
rdpMonitor _monitor{};
|
||||
Sint32 _intended_w = 0;
|
||||
Sint32 _intended_h = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user