From bd81e3e89efc67e4016087fef8c74fe3a6c2efdc Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Wed, 25 Dec 2024 19:45:10 +0200 Subject: [PATCH] Fix workaround for maximizing Editor window --- Source/Engine/Platform/SDL/SDLPlatform.cpp | 4 ++-- Source/Engine/Platform/SDL/SDLWindow.cpp | 17 +++++------------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Source/Engine/Platform/SDL/SDLPlatform.cpp b/Source/Engine/Platform/SDL/SDLPlatform.cpp index 59048628c..5a214acf8 100644 --- a/Source/Engine/Platform/SDL/SDLPlatform.cpp +++ b/Source/Engine/Platform/SDL/SDLPlatform.cpp @@ -60,10 +60,10 @@ bool SDLPlatform::Init() SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); // Fixes context menu focus issues when clicking unfocused menus SDL_SetHint(SDL_HINT_WINDOWS_ERASE_BACKGROUND_MODE, "0"); SDL_SetHint(SDL_HINT_TIMER_RESOLUTION, "0"); // Already handled during platform initialization - SDL_SetHint("SDL_BORDERLESS_RESIZABLE_STYLE", "1"); // Allow borderless windows to be resizable on Windows + SDL_SetHint("SDL_BORDERLESS_RESIZABLE_STYLE", "1"); // Allow borderless windows to be resizable on Windows, currently breaks maximize window functionality SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_WARP_MOTION, "0"); SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_CURSOR_VISIBLE, "1"); // Needed for tracking mode - SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_CENTER, "1"); + SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_CENTER, "1"); // Is this needed? //SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1"); // Disables raw mouse input SDL_SetHint(SDL_HINT_WINDOWS_RAW_KEYBOARD, "1"); diff --git a/Source/Engine/Platform/SDL/SDLWindow.cpp b/Source/Engine/Platform/SDL/SDLWindow.cpp index e3c92a1ec..60abf4234 100644 --- a/Source/Engine/Platform/SDL/SDLWindow.cpp +++ b/Source/Engine/Platform/SDL/SDLWindow.cpp @@ -548,9 +548,11 @@ void SDLWindow::HandleEvent(SDL_Event& event) _maximized = true; #if PLATFORM_WINDOWS + // This shouldn't be needed anymore, but maximize blocks any resize operations if (!_settings.HasBorder && _settings.HasSizingFrame) { - // Borderless window doesn't maximize properly, manually force the window into correct location and size + // Borderless editor window doesn't maximize properly, + // manually force the window into correct location and size. SDL_Rect rect; SDL_DisplayID display = SDL_GetDisplayForWindow(_window); SDL_GetDisplayUsableBounds(display, &rect); // Excludes taskbar etc. @@ -560,20 +562,11 @@ void SDLWindow::HandleEvent(SDL_Event& event) auto size = GetClientSize(); if (pos.X < rect.x || pos.Y < rect.y || size.X > rect.w || size.Y > rect.h) { - // Disable resizable flag so SDL updates the client rectangle to expected values during WM_NCCALCSIZE - SDL_SetWindowResizable(_window, false); - SDL_MaximizeWindow(_window); + SDL_RestoreWindow(_window); // Set the internal floating window rectangle to expected position SetClientBounds(Rectangle((float)rect.x, (float)rect.y, (float)rect.w, (float)rect.h)); - - // Flush and handle the events again - ::SetWindowPos((HWND)_handle, HWND_TOP, rect.x, rect.y, rect.w, rect.h, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER); - SDL_PumpEvents(); - - // Restore previous values - SDL_SetWindowResizable(_window, true); - SetClientBounds(_cachedClientRectangle); + _cachedClientRectangle.Size = Float2((float)rect.w, (float)rect.h); } } #endif