diff --git a/client/SDL/SDL3/sdl_context.cpp b/client/SDL/SDL3/sdl_context.cpp index b38537bbc..c887b6515 100644 --- a/client/SDL/SDL3/sdl_context.cpp +++ b/client/SDL/SDL3/sdl_context.cpp @@ -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()) diff --git a/client/SDL/SDL3/sdl_window.cpp b/client/SDL/SDL3/sdl_window.cpp index 1e49ef9cf..0c9094b38 100644 --- a/client/SDL/SDL3/sdl_window.cpp +++ b/client/SDL/SDL3/sdl_window.cpp @@ -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(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(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); diff --git a/client/SDL/SDL3/sdl_window.hpp b/client/SDL/SDL3/sdl_window.hpp index 0b4a4ec44..eb22895a4 100644 --- a/client/SDL/SDL3/sdl_window.hpp +++ b/client/SDL/SDL3/sdl_window.hpp @@ -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; };