From 8d469feda09b57049401f94931b11196fbbc9023 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Wed, 26 Mar 2025 20:01:44 +0100 Subject: [PATCH] [client,sdl] fix initial window size * on high dpi displays set appropriate initial display size (divide pixel size with scale) * send display resize on window resize events * send display resize on any window event (minimize/maximize/expose/...) --- client/SDL/SDL3/sdl_disp.cpp | 6 ++++-- client/SDL/SDL3/sdl_window.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/client/SDL/SDL3/sdl_disp.cpp b/client/SDL/SDL3/sdl_disp.cpp index 9c32dc1a3..02cd09d3d 100644 --- a/client/SDL/SDL3/sdl_disp.cpp +++ b/client/SDL/SDL3/sdl_disp.cpp @@ -358,10 +358,12 @@ BOOL sdlDispContext::handle_window_event(const SDL_WindowEvent* ev) auto ctx = _sdl->context(); if (ctx && ctx->gdi) gdi_send_suppress_output(ctx->gdi, FALSE); - return TRUE; } + /* fallthrough */ + WINPR_FALLTHROUGH case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED: case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED: + case SDL_EVENT_WINDOW_RESIZED: { if (freerdp_settings_get_bool(_sdl->context()->settings, FreeRDP_DynamicResolutionUpdate)) @@ -370,7 +372,7 @@ BOOL sdlDispContext::handle_window_event(const SDL_WindowEvent* ev) const auto factor = SDL_GetWindowDisplayScale(window.window()); _targetDesktopScaleFactor = static_cast(100 * factor); } - assert(SDL_GetWindowSizeInPixels(it->second.window(), &_targetWidth, &_targetHeight)); + SDL_GetWindowSizeInPixels(it->second.window(), &_targetWidth, &_targetHeight); return addTimer(); } case SDL_EVENT_WINDOW_MOUSE_LEAVE: diff --git a/client/SDL/SDL3/sdl_window.cpp b/client/SDL/SDL3/sdl_window.cpp index eefc7e558..61c4c4e70 100644 --- a/client/SDL/SDL3/sdl_window.cpp +++ b/client/SDL/SDL3/sdl_window.cpp @@ -33,6 +33,12 @@ SdlWindow::SdlWindow(const std::string& title, Sint32 startupX, Sint32 startupY, // SDL_SetProperty(props, SDL_PROP_WINDOW_CREATE_FL); _window = SDL_CreateWindowWithProperties(props); SDL_DestroyProperties(props); + + auto scale = SDL_GetWindowPixelDensity(_window); + const int iscale = static_cast(scale * 100.0f); + auto w = 100 * width / iscale; + auto h = 100 * height / iscale; + SDL_SetWindowSize(_window, w, h); } SdlWindow::SdlWindow(SdlWindow&& other) noexcept