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); +}