Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(main): make -borderless a real borderless fullscreen mode

Olcay Seygan4a18343a164a
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
index fd08b3fb0..5d4a81881 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
@@ -138,6 +138,34 @@ Int parseWin(char *args[], int)
return 1;
}
+//=============================================================================
+/* -borderless is fullscreen without the display mode change: a windowed device the size of the
+ desktop, in a window with no caption and no frame, so it covers the screen exactly the way an
+ exclusive fullscreen device does but alt-tabs instantly, never loses the device on focus change,
+ and leaves a second monitor usable. The window style and size are decided in WinMain, which
+ preparses -borderless off the raw command line long before this parser runs - the window has to
+ exist before the engine does. What is left here is the back buffer, which has to match the
+ window or the picture is a stretched blit and the cursor no longer lands where it is drawn.
+
+ -xres/-yres after -borderless still win, for a smaller back buffer in a borderless window.
+
+ Edge scrolling goes back on because retail turns it off for windowed play - the cursor can
+ legitimately sit on the border while you reach for another window - and a window covering the
+ whole display has no such border. Options.ini's EdgeScrollInWindowedMode is read before the
+ command line, so a player who set it either way is overridden here on purpose. */
+//=============================================================================
+Int parseBorderless(char *args[], int)
+{
+ if (TheWritableGlobalData)
+ {
+ TheWritableGlobalData->m_windowed = true;
+ TheWritableGlobalData->m_xResolution = GetSystemMetrics( SM_CXSCREEN );
+ TheWritableGlobalData->m_yResolution = GetSystemMetrics( SM_CYSCREEN );
+ TheWritableGlobalData->m_edgeScrollInWindowedMode = TRUE;
+ }
+ return 1;
+}
+
//=============================================================================
//=============================================================================
Int parseNoMusic(char *args[], int)
@@ -1417,6 +1445,7 @@ static CommandLineParam params[] =
{
{ "-noshellmap", parseNoShellMap },
{ "-win", parseWin },
+ { "-borderless", parseBorderless },
{ "-xres", parseXRes },
{ "-yres", parseYRes },
{ "-fullscreen", parseNoWin },
diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cpp
index b5ef9464e..1eea40059 100644
--- a/GeneralsMD/Code/Main/WinMain.cpp
+++ b/GeneralsMD/Code/Main/WinMain.cpp
@@ -439,8 +439,20 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
//-------------------------------------------------------------------------
case WM_SIZE:
// When W3D initializes, it resizes the window. So stop repainting.
- if (!gInitializing)
+ if (!gInitializing)
+ {
gDoPaint = false;
+ //
+ // That resize is also the moment borderless becomes fullscreen. The window is born
+ // small and centred, so the splash sits on the desktop the way it always has instead
+ // of a screen of black; W3D then grows it to the back buffer, which is the desktop
+ // resolution. It grows it with SWP_NOMOVE, keeping the top left corner where the
+ // small window was, which would hang the thing off the bottom right of the screen.
+ // Put it at the origin instead.
+ //
+ if (ApplicationIsBorderless)
+ ::SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
+ }
break;
//-------------------------------------------------------------------------
@@ -705,16 +717,27 @@ static Bool initializeAppWindows( HINSTANCE hInstance, Int nCmdShow, Bool runWin
RegisterClass( &wndClass );
// Create our main window
+ // a headless run has no picture at all, so there is nothing for borderless to mean
+ if (ApplicationIsHeadless)
+ ApplicationIsBorderless = false;
+
windowStyle = WS_POPUP|WS_VISIBLE;
if (ApplicationIsHeadless)
windowStyle = WS_POPUP; // born hidden, no frame, and stays that way
- else if (runWindowed && !ApplicationIsBorderless)
- windowStyle |= WS_DLGFRAME | WS_CAPTION | WS_SYSMENU;
+ else if (ApplicationIsBorderless)
+ windowStyle |= WS_SYSMENU; // no caption, no frame; system menu so alt+F4 still closes it
else if (runWindowed)
- windowStyle |= WS_SYSMENU; // borderless: keep the system menu for alt+F4, drop the frame
+ windowStyle |= WS_DLGFRAME | WS_CAPTION | WS_SYSMENU;
else
windowStyle |= WS_EX_TOPMOST | WS_SYSMENU;
+ //
+ // Borderless is born at the splash's own 800x600, centred, with the desktop still showing round
+ // it, and only becomes fullscreen when W3D resizes it to the back buffer - which parseBorderless
+ // in CommandLine.cpp has already set to the desktop resolution. WM_SIZE puts it at the origin
+ // when that happens. Filling the screen with black for the several seconds the game takes to
+ // load buys nothing and hides the desktop for no reason.
+ //
RECT rect;
rect.left = 0;
rect.top = 0;
@@ -962,8 +985,9 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
//added a preparse step for this flag because it affects window creation style
if (stricmp(token,"-win")==0)
ApplicationIsWindowed=true;
- // same reason: -borderless drops the caption and frame, and implies -win. Parsed here
- // rather than from Options.ini because the window exists long before the engine's
+ // same reason: -borderless is borderless fullscreen - a windowed device with no caption
+ // or frame, covering the display at the desktop resolution - so it implies -win. Parsed
+ // here rather than from Options.ini because the window exists long before the engine's
// preferences do.
if (stricmp(token,"-borderless")==0)
{