From 6cf6ab8f2529e5cf257714993533e5724debf869 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Fri, 29 Mar 2024 23:00:25 +0100 Subject: [PATCH] Add a workaround for Windows's initial window size Fixes #1714 --- src/love.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/love.cpp b/src/love.cpp index a94779753..2bfe707a1 100644 --- a/src/love.cpp +++ b/src/love.cpp @@ -299,6 +299,35 @@ static DoneAction runlove(int argc, char **argv, int &retval, love::Variant &res return done; } +#ifdef LOVE_WINDOWS +static INT_PTR CALLBACK EmptyDlgProc(HWND, UINT, WPARAM, LPARAM) +{ + return 0; +} + +// Windows stores an initial window state passed in by the shell (or another process) if STARTF_USESHOWWINDOW is set. +// This state is applied to the first window that receives a 'ShowWindow' call. +// To ensure our window is not influenced by this, we create a dummy window to catch this initial state. +// Ideally we would use SDL for this, but it skips calls to 'ShowWindow' if the window is hidden... +static void love_windows_ignore_initial_wShowWindow() +{ + // Build up a dialog template + enum { DlgX = 0, DlgY = 0, DlgW = 100, DlgH = 60, ChildCount = 0, MenuId = 0, ClassName = 0, Title = 0 }; + const UINT DialogStyle = DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU; + const UINT DialogStyleEx = 0; + static const WORD DialogTemplate[] = + { + LOWORD(DialogStyle), HIWORD(DialogStyle), LOWORD(DialogStyleEx), HIWORD(DialogStyleEx), ChildCount, DlgX, DlgY, DlgW, DlgH, MenuId, ClassName, Title, + }; + // Create a window using the template + HWND hWnd = CreateDialogIndirectParamW(NULL, (LPCDLGTEMPLATE)DialogTemplate, NULL, EmptyDlgProc, NULL); + // Now catch the window state provided + ShowWindow(hWnd, SW_HIDE); + // We are done + DestroyWindow(hWnd); +} +#endif + int main(int argc, char **argv) { if (strcmp(LOVE_VERSION_STRING, love_version()) != 0) @@ -312,6 +341,10 @@ int main(int argc, char **argv) DoneAction done = DONE_QUIT; love::Variant restartvalue; +#ifdef LOVE_WINDOWS + love_windows_ignore_initial_wShowWindow(); +#endif + do { done = runlove(argc, argv, retval, restartvalue);