From: bones_was_here Date: Wed, 10 Apr 2024 19:39:17 +0000 (+1000) Subject: vid: apply vid_width and vid_height cvar changes immediately X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c03b106680122333189e42294c4fb3c385307631;p=xonotic%2Fdarkplaces.git vid: apply vid_width and vid_height cvar changes immediately This uses an SDL feature to avoid a bogus hardware modesets (eg when one cvar is changed before the other). Signed-off-by: bones_was_here --- diff --git a/vid_sdl.c b/vid_sdl.c index c3f49f6a..9f921a30 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -1373,6 +1373,7 @@ qbool GL_ExtensionSupported(const char *name) return SDL_GL_ExtensionSupported(name); } +/// Applies display settings immediately (no vid_restart required). static void VID_ApplyDisplaySettings_c(cvar_t *var) { unsigned int fullscreenwanted, fullscreencurrent; @@ -1442,6 +1443,26 @@ static void VID_ApplyDisplaySettings_c(cvar_t *var) // switching to a fullscreen mode if (fullscreenwanted) { + if (fullscreenwanted == SDL_WINDOW_FULLSCREEN) + { + // When starting in desktop/window mode no hardware mode is set so do it now, + // this also applies vid_width and vid_height changes immediately without bogus modesets. + SDL_DisplayMode modewanted, modeclosest; + modewanted.w = vid_width.integer; + modewanted.h = vid_height.integer; + modewanted.refresh_rate = vid_userefreshrate.integer ? vid_refreshrate.integer : 0; + if (!SDL_GetClosestDisplayMode(vid.displayindex, &modewanted, &modeclosest)) + { + Con_Printf(CON_ERROR "Error getting closest mode to %ix%i@%ihz for display %i: \"%s\"\n", modewanted.w, modewanted.h, modewanted.refresh_rate, vid.displayindex, SDL_GetError()); + return; + } + if (SDL_SetWindowDisplayMode(window, &modeclosest) < 0) + { + Con_Printf(CON_ERROR "Error setting mode %ix%i@%ihz for display %i: \"%s\"\n", modeclosest.w, modeclosest.h, modeclosest.refresh_rate, vid.displayindex, SDL_GetError()); + return; + } + } + if (SDL_SetWindowFullscreen(window, fullscreenwanted) < 0) { Con_Printf(CON_ERROR "ERROR: can't activate fullscreen on display %i because %s\n", vid.displayindex, SDL_GetError()); @@ -1502,6 +1523,8 @@ void VID_Init (void) Cvar_RegisterCallback(&vid_fullscreen, VID_ApplyDisplaySettings_c); Cvar_RegisterCallback(&vid_desktopfullscreen, VID_ApplyDisplaySettings_c); Cvar_RegisterCallback(&vid_display, VID_ApplyDisplaySettings_c); + Cvar_RegisterCallback(&vid_width, VID_ApplyDisplaySettings_c); + Cvar_RegisterCallback(&vid_height, VID_ApplyDisplaySettings_c); Cvar_RegisterCallback(&vid_resizable, VID_ApplyDisplaySettings_c); Cvar_RegisterCallback(&vid_borderless, VID_ApplyDisplaySettings_c); Cvar_RegisterCallback(&vid_vsync, VID_SetVsync_c);