From 1153238e2c7700287293024144e6d02d4c6f2e16 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Mon, 29 Jan 2024 17:08:10 +0100 Subject: [PATCH] sdl: (linux) fix window position at startup/recreation Window decorations dimensions aren't taken into account on linux when creating a window. So reposition it after it's shown. --- core/sdl/sdl.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/sdl/sdl.cpp b/core/sdl/sdl.cpp index 662af8f9e..8fcaf7f2a 100644 --- a/core/sdl/sdl.cpp +++ b/core/sdl/sdl.cpp @@ -642,6 +642,18 @@ bool sdl_recreate_window(u32 flags) settings.display.width = windowPos.w * hdpiScaling; settings.display.height = windowPos.h * hdpiScaling; +#ifdef __linux__ + if (flags & SDL_WINDOW_RESIZABLE) + { + // The position passed to SDL_CreateWindow doesn't take decorations into account on linux. + // SDL_ShowWindow retrieves the border dimensions and SDL_SetWindowPosition uses them + // to correctly (re)position the window if needed. + // TODO a similar issue happens when switching back from fullscreen + SDL_ShowWindow(window); + SDL_SetWindowPosition(window, windowPos.x, windowPos.y); + } +#endif + #if !defined(GLES) && !defined(_WIN32) && !defined(__SWITCH__) && !defined(__APPLE__) // Set the window icon u32 pixels[48 * 48];