diff --git a/Source/Engine/Platform/SDL/SDLPlatform.Windows.cpp b/Source/Engine/Platform/SDL/SDLPlatform.Windows.cpp index e11d5d93c..ce60d76de 100644 --- a/Source/Engine/Platform/SDL/SDLPlatform.Windows.cpp +++ b/Source/Engine/Platform/SDL/SDLPlatform.Windows.cpp @@ -12,20 +12,24 @@ #include "Engine/Platform/Win32/IncludeWindowsHeaders.h" #include "Engine/Input/Mouse.h" #include "Engine/Core/Log.h" +#include "Engine/Engine/Engine.h" #include #include #include #include +#if USE_EDITOR +#include +#endif + +#define STYLE_RESIZABLE (WS_THICKFRAME | WS_MAXIMIZEBOX) + namespace WinImpl { Window* DraggedWindow; Float2 DraggedWindowStartPosition = Float2::Zero; Float2 DraggedWindowMousePosition = Float2::Zero; -#if BORDERLESS_MAXIMIZE_WORKAROUND == 2 - int SkipMaximizeEventsCount = 0; -#endif } // The events for releasing the mouse during window dragging are missing, handle the mouse release event here @@ -47,11 +51,6 @@ bool SDLCALL SDLPlatform::EventMessageHook(void* userdata, MSG* msg) ASSERT((window) != nullptr); \ } while (false) - if (WinImpl::DraggedWindow != nullptr) - { - LOG(Info, "event hook message: {}", msg->message); - } - if (msg->message == WM_NCLBUTTONDOWN) { Window* window; @@ -117,7 +116,7 @@ bool SDLPlatform::InitInternal() return false; } -bool EventFilterCallback(void* userdata, SDL_Event* event) +bool SDLPlatform::EventFilterCallback(void* userdata, SDL_Event* event) { Window* draggedWindow = *(Window**)userdata; if (draggedWindow == nullptr) @@ -184,7 +183,7 @@ void SDLPlatform::PreHandleEvents() void SDLPlatform::PostHandleEvents() { - SDL_RemoveEventWatch(watch, &WinImpl::DraggedWindow); + SDL_RemoveEventWatch(EventFilterCallback, &WinImpl::DraggedWindow); // Handle window dragging release here if (WinImpl::DraggedWindow != nullptr) @@ -221,48 +220,6 @@ bool SDLWindow::HandleEventInternal(SDL_Event& event) if (result != S_OK) LOG(Warning, "Window drag and drop service error: 0x{0:x}:{1}", result, 2); } -#endif - break; - } - case SDL_EVENT_WINDOW_MAXIMIZED: - { -#if BORDERLESS_MAXIMIZE_WORKAROUND == 2 - if (SkipMaximizeEventsCount > 0) - { - SkipMaximizeEventsCount--; - return; - } - - if (!_settings.HasBorder && _settings.HasSizingFrame) - { - // Restore the window back to previous state - SDL_RestoreWindow(_window); - - // Remove the resizable flags from borderless windows and maximize the window again - auto style = ::GetWindowLong((HWND)_handle, GWL_STYLE); - style &= ~STYLE_RESIZABLE; - ::SetWindowLong((HWND)_handle, GWL_STYLE, style); - - SDL_MaximizeWindow(_window); - - // Re-enable the resizable borderless flags - style = ::GetWindowLong((HWND)_handle, GWL_STYLE) | STYLE_RESIZABLE; - ::SetWindowLong((HWND)_handle, GWL_STYLE, style); - - // The next SDL_EVENT_WINDOW_RESTORED and SDL_EVENT_WINDOW_MAXIMIZED events should be ignored - SkipMaximizeEventsCount = 2; - } -#endif - break; - } - case SDL_EVENT_WINDOW_RESTORED: - { -#if BORDERLESS_MAXIMIZE_WORKAROUND == 2 - if (SkipMaximizeEventsCount > 0) - { - SkipMaximizeEventsCount--; - return true; - } #endif break; } @@ -305,43 +262,6 @@ bool SDLPlatform::UsesX11() return false; } -void SDLWindow::Maximize() -{ - if (!_settings.AllowMaximize) - return; - -#if BORDERLESS_MAXIMIZE_WORKAROUND == 1 - // Workaround for "SDL_BORDERLESS_RESIZABLE_STYLE" hint not working as expected when maximizing windows - auto style = ::GetWindowLong((HWND)_handle, GWL_STYLE); - style &= ~STYLE_RESIZABLE; - ::SetWindowLong((HWND)_handle, GWL_STYLE, style); - - SDL_MaximizeWindow(_window); - - style = ::GetWindowLong((HWND)_handle, GWL_STYLE) | STYLE_RESIZABLE; - ::SetWindowLong((HWND)_handle, GWL_STYLE, style); -#else - SDL_MaximizeWindow(_window); -#endif -} - -void SDLWindow::Restore() -{ -#if BORDERLESS_MAXIMIZE_WORKAROUND == 1 - // Workaround for "SDL_BORDERLESS_RESIZABLE_STYLE" hint not working as expected when maximizing windows - auto style = ::GetWindowLong((HWND)_handle, GWL_STYLE); - style &= ~STYLE_RESIZABLE; - ::SetWindowLong((HWND)_handle, GWL_STYLE, style); - - SDL_RestoreWindow(_window); - - style = ::GetWindowLong((HWND)_handle, GWL_STYLE) | STYLE_RESIZABLE; - ::SetWindowLong((HWND)_handle, GWL_STYLE, style); -#else - SDL_RestoreWindow(_window); -#endif -} - void SDLWindow::Focus() { auto activateWhenRaised = SDL_GetHint(SDL_HINT_WINDOW_ACTIVATE_WHEN_RAISED); diff --git a/Source/Engine/Platform/SDL/SDLPlatform.h b/Source/Engine/Platform/SDL/SDLPlatform.h index ce0207b1a..8f374e400 100644 --- a/Source/Engine/Platform/SDL/SDLPlatform.h +++ b/Source/Engine/Platform/SDL/SDLPlatform.h @@ -42,6 +42,7 @@ private: static bool HandleEvent(SDL_Event& event); #if PLATFORM_WINDOWS static bool EventMessageHook(void* userdata, MSG* msg); + static bool SDLPlatform::EventFilterCallback(void* userdata, SDL_Event* event); #elif PLATFORM_LINUX static bool X11EventHook(void* userdata, _XEvent* xevent); #endif diff --git a/Source/Engine/Platform/SDL/SDLWindow.cpp b/Source/Engine/Platform/SDL/SDLWindow.cpp index c0ca3a958..15d3fa418 100644 --- a/Source/Engine/Platform/SDL/SDLWindow.cpp +++ b/Source/Engine/Platform/SDL/SDLWindow.cpp @@ -25,8 +25,6 @@ #if PLATFORM_WINDOWS #include "Engine/Platform/Win32/IncludeWindowsHeaders.h" -#define STYLE_RESIZABLE (WS_THICKFRAME | WS_MAXIMIZEBOX) -#define BORDERLESS_MAXIMIZE_WORKAROUND 2 #if USE_EDITOR #include #endif @@ -530,8 +528,6 @@ void SDLWindow::Minimize() SDL_MinimizeWindow(_window); } -#if !PLATFORM_WINDOWS - void SDLWindow::Maximize() { if (!_settings.AllowMaximize) @@ -540,8 +536,6 @@ void SDLWindow::Maximize() SDL_MaximizeWindow(_window); } -#endif - void SDLWindow::SetBorderless(bool isBorderless, bool maximized) { if (IsFullscreen()) @@ -564,15 +558,11 @@ void SDLWindow::SetBorderless(bool isBorderless, bool maximized) CheckForWindowResize(); } -#if !PLATFORM_WINDOWS - void SDLWindow::Restore() { SDL_RestoreWindow(_window); } -#endif - bool SDLWindow::IsClosed() const { return _handle == nullptr; @@ -586,20 +576,7 @@ bool SDLWindow::IsForegroundWindow() const void SDLWindow::BringToFront(bool force) { -#if PLATFORM_WINDOWS // FIXME - auto activateWhenRaised = SDL_GetHint(SDL_HINT_WINDOW_ACTIVATE_WHEN_RAISED); - SDL_SetHint(SDL_HINT_WINDOW_ACTIVATE_WHEN_RAISED, "0"); SDL_RaiseWindow(_window); - SDL_SetHint(SDL_HINT_WINDOW_ACTIVATE_WHEN_RAISED, activateWhenRaised); -#endif - //if (SDLPlatform::UsesX11()) - { - auto activateWhenRaised = SDL_GetHint(SDL_HINT_WINDOW_ACTIVATE_WHEN_RAISED); - SDL_SetHint(SDL_HINT_WINDOW_ACTIVATE_WHEN_RAISED, "0"); - SDL_RaiseWindow(_window); - SDL_SetHint(SDL_HINT_WINDOW_ACTIVATE_WHEN_RAISED, activateWhenRaised); - SDL_SyncWindow(_window); - } } void SDLWindow::SetClientBounds(const Rectangle& clientArea)