From 27977a87dcbe2f9d773363560bfb462a095d3e66 Mon Sep 17 00:00:00 2001 From: John Cranston Date: Tue, 13 Oct 2026 19:29:45 -0700 Subject: [PATCH] Keep Windows borderless mode from taking exclusive fullscreen NVIDIA's OpenGL driver can treat SDL's popup fullscreen window as exclusive even when no display mode is selected, blanking the monitor on Alt+Tab. Clear popup and topmost styles for borderless windows before context creation and presentation, including after SDL restores them. Explicit fullscreen keeps its existing behavior. Checked: Windows release build; hidden native window probe covering styles, bounds, focus, repeated application and mode isolation; git diff --check. Live Alt+Tab was not tested. Android and web targets were unavailable; pytest was not installed. --- port/linux/src/sdl_platform.c | 12 ++++++++++++ port/windows/src/win32_window.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 port/windows/src/win32_window.c diff --git a/port/linux/src/sdl_platform.c b/port/linux/src/sdl_platform.c index 7384b6040d..55d47e378f 100644 --- a/port/linux/src/sdl_platform.c +++ b/port/linux/src/sdl_platform.c @@ -21,6 +21,10 @@ and the debug keyboard that the game's console reads. #include #include #include +#ifdef HALO_WINDOWS +/* port/windows/src/win32_window.c, compiled with the Windows SDK */ +void win32_window_borderless_apply(SDL_Window *window); +#endif #if !defined(_WIN32) && !defined(HALO_ANDROID) #include #endif @@ -839,6 +843,9 @@ BOOL platform_video_initialize(unsigned long width, unsigned long height) #endif platform_fullscreen_requested = platform_fullscreen_setting(); platform_fullscreen_kind_apply(); +#endif +#ifdef HALO_WINDOWS + win32_window_borderless_apply(platform_window); #endif platform_gl_context = SDL_GL_CreateContext(platform_window); #ifdef HALO_GLES @@ -950,6 +957,11 @@ void platform_video_swap(void) static Uint64 next_frame; Uint64 interval, now; +#endif +#ifdef HALO_WINDOWS + /* SDL can restore its fullscreen styles on a mode or focus change. + Keep borderless on the desktop before the driver presents a frame. */ + win32_window_borderless_apply(platform_window); #endif SDL_GL_SwapWindow(platform_window); #ifdef HALO_WEB diff --git a/port/windows/src/win32_window.c b/port/windows/src/win32_window.c new file mode 100644 index 0000000000..e038765a62 --- /dev/null +++ b/port/windows/src/win32_window.c @@ -0,0 +1,28 @@ +/* +WIN32_WINDOW.C + +Keep borderless OpenGL windows on the desktop. NVIDIA's driver treats +SDL's WS_POPUP fullscreen window as exclusive even without a display mode, +which blanks the monitor when the player switches to another application. +*/ + +#include +#include + +void win32_window_borderless_apply(SDL_Window *window) +{ + HWND handle; + LONG_PTR style; + + if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) || SDL_GetWindowFullscreenMode(window)) + return; + handle = SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL); + if (!handle) + return; + style = GetWindowLongPtr(handle, GWL_STYLE); + if (!(style & WS_POPUP) && !(GetWindowLongPtr(handle, GWL_EXSTYLE) & WS_EX_TOPMOST)) + return; + SetWindowLongPtr(handle, GWL_STYLE, style & ~WS_POPUP); + SetWindowPos(handle, HWND_NOTOPMOST, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_FRAMECHANGED); +}