Remember the last used window display

This commit is contained in:
Lach 2024-05-18 23:55:19 +10:00
parent c44790749d
commit 3d8a3e581c
3 changed files with 33 additions and 4 deletions

View file

@ -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();

View file

@ -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;

View file

@ -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