From 3d8a3e581c5c2c0359df309b7e2ede57447e74fd Mon Sep 17 00:00:00 2001 From: Lach Date: Sat, 18 May 2024 23:55:19 +1000 Subject: [PATCH] Remember the last used window display --- src/cvars.cpp | 2 ++ src/screen.h | 1 + src/sdl/i_video.cpp | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/cvars.cpp b/src/cvars.cpp index 83c360eb2..73dbde390 100644 --- a/src/cvars.cpp +++ b/src/cvars.cpp @@ -446,6 +446,8 @@ consvar_t cv_scr_scale = Player("scr_scale", "1.0").floating_point(); consvar_t cv_scr_x = Player("scr_x", "0.0").floating_point(); consvar_t cv_scr_y = Player("scr_y", "0.0").floating_point(); +consvar_t cv_display = Player("display", "0").values(CV_Unsigned).save(); + consvar_t cv_seenames = Player("seenames", "On").on_off(); consvar_t cv_shadow = Player("shadow", "On").on_off(); consvar_t cv_showfocuslost = Player("showfocuslost", "Yes").yes_no(); diff --git a/src/screen.h b/src/screen.h index 341edba9a..39828a03a 100644 --- a/src/screen.h +++ b/src/screen.h @@ -138,6 +138,7 @@ extern UINT8 *scr_borderpatch; // patch used to fill the view borders extern consvar_t cv_scr_width, cv_scr_height, cv_scr_depth, cv_renderview, cv_renderer, cv_renderhitbox, cv_fullscreen; extern consvar_t cv_scr_effect; extern consvar_t cv_parallelsoftware; +extern consvar_t cv_display; // wait for page flipping to end or not extern consvar_t cv_vidwait; diff --git a/src/sdl/i_video.cpp b/src/sdl/i_video.cpp index 065ee3958..70d70e3c7 100644 --- a/src/sdl/i_video.cpp +++ b/src/sdl/i_video.cpp @@ -171,6 +171,23 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); //static void Impl_SetWindowName(const char *title); static void Impl_SetWindowIcon(void); +static void ValidateDisplay(void) +{ + // Validate display index, otherwise use main display + if (cv_display.value >= SDL_GetNumVideoDisplays()) + { + CV_SetValue(&cv_display, 0); + } +} + +static void CenterWindow(void) +{ + SDL_SetWindowPosition(window, + SDL_WINDOWPOS_CENTERED_DISPLAY(cv_display.value), + SDL_WINDOWPOS_CENTERED_DISPLAY(cv_display.value) + ); +} + static void SDLSetMode(int width, int height, SDL_bool fullscreen, SDL_bool reposition) { static SDL_bool wasfullscreen = SDL_FALSE; @@ -182,6 +199,14 @@ static void SDLSetMode(int width, int height, SDL_bool fullscreen, SDL_bool repo { if (fullscreen) { + if (reposition) + { + ValidateDisplay(); + if (SDL_GetWindowDisplayIndex(window) != cv_display.value) + { + CenterWindow(); + } + } wasfullscreen = SDL_TRUE; SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); } @@ -196,10 +221,8 @@ static void SDLSetMode(int width, int height, SDL_bool fullscreen, SDL_bool repo SDL_SetWindowSize(window, width, height); if (reposition) { - SDL_SetWindowPosition(window, - SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)), - SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)) - ); + ValidateDisplay(); + CenterWindow(); } } } @@ -504,6 +527,9 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) vid.realwidth = evt.data1; vid.realheight = evt.data2; break; + case SDL_WINDOWEVENT_DISPLAY_CHANGED: + CV_SetValue(&cv_display, evt.data1); + break; } if (FOCUSUNION == oldfocus) // No state change