From: bones_was_here Date: Mon, 30 Oct 2023 01:15:36 +0000 (+1000) Subject: vid: add cvar vid_minimize_on_focus_loss X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=83c1da9c25329f63b7667bbce062692ef7c75668;p=xonotic%2Fdarkplaces.git vid: add cvar vid_minimize_on_focus_loss Default of 0 matches current SDL default behaviour. If set, the environment variable SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS will override the cvar. Changes apply immediately. Also makes changes to vid_mouse_clickthrough apply immediately. Signed-off-by: bones_was_here --- diff --git a/vid.h b/vid.h index cab74969..3ede535d 100644 --- a/vid.h +++ b/vid.h @@ -154,6 +154,7 @@ extern cvar_t vid_touchscreen_ydpi; extern cvar_t vid_vsync; extern cvar_t vid_mouse; extern cvar_t vid_mouse_clickthrough; +extern cvar_t vid_minimize_on_focus_loss; extern cvar_t vid_grabkeyboard; extern cvar_t vid_touchscreen; extern cvar_t vid_touchscreen_showkeyboard; diff --git a/vid_sdl.c b/vid_sdl.c index 6f39dd5f..88ec122e 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -1489,6 +1489,12 @@ static void VID_SetVsync_c(cvar_t *var) Con_Printf(CON_ERROR "ERROR: can't %s vsync because %s\n", vsyncwanted ? "activate" : "deactivate", SDL_GetError()); } +static void VID_SetHints_c(cvar_t *var) +{ + SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, vid_mouse_clickthrough.integer ? "1" : "0"); + SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, vid_minimize_on_focus_loss.integer ? "1" : "0"); +} + void VID_Init (void) { SDL_version version; @@ -1519,6 +1525,8 @@ void VID_Init (void) Cvar_RegisterCallback(&vid_resizable, VID_ChangeDisplay_c); Cvar_RegisterCallback(&vid_borderless, VID_ChangeDisplay_c); Cvar_RegisterCallback(&vid_vsync, VID_SetVsync_c); + Cvar_RegisterCallback(&vid_mouse_clickthrough, VID_SetHints_c); + Cvar_RegisterCallback(&vid_minimize_on_focus_loss, VID_SetHints_c); if (SDL_Init(SDL_INIT_VIDEO) < 0) Sys_Error ("Failed to init SDL video subsystem: %s", SDL_GetError()); @@ -1720,8 +1728,7 @@ static qbool VID_InitModeGL(viddef_mode_t *mode) SDL_SetHint(SDL_HINT_WINDOWS_DPI_AWARENESS, "1"); #endif - if (vid_mouse_clickthrough.integer) - SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); + VID_SetHints_c(NULL); SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 8); diff --git a/vid_shared.c b/vid_shared.c index 5e216845..aa34a1e3 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -150,6 +150,7 @@ cvar_t vid_touchscreen_ydpi = {CF_CLIENT, "vid_touchscreen_ydpi", "300", "Vertic cvar_t vid_vsync = {CF_CLIENT | CF_ARCHIVE, "vid_vsync", "0", "sync to vertical blank, prevents 'tearing' (seeing part of one frame and part of another on the screen at the same time) at the cost of latency, 1 always syncs and -1 is adaptive (stops syncing if the framerate drops, unsupported by some platforms), automatically disabled when doing timedemo benchmarks"}; cvar_t vid_mouse = {CF_CLIENT | CF_ARCHIVE, "vid_mouse", "1", "whether to use the mouse in windowed mode (fullscreen always does)"}; cvar_t vid_mouse_clickthrough = {CF_CLIENT | CF_ARCHIVE, "vid_mouse_clickthrough", "0", "mouse behavior in windowed mode: 0 = click to focus, 1 = allow interaction even if the window is not focused (click-through behaviour, can be useful when using third-party game overlays)"}; +cvar_t vid_minimize_on_focus_loss = {CF_CLIENT | CF_ARCHIVE, "vid_minimize_on_focus_loss", "0", "whether to minimize the fullscreen window if it loses focus (such as by alt+tab)"}; cvar_t vid_grabkeyboard = {CF_CLIENT | CF_ARCHIVE, "vid_grabkeyboard", "0", "whether to grab the keyboard when mouse is active (prevents use of volume control keys, music player keys, etc on some keyboards)"}; cvar_t vid_minwidth = {CF_CLIENT, "vid_minwidth", "0", "minimum vid_width that is acceptable (to be set in default.cfg in mods)"}; cvar_t vid_minheight = {CF_CLIENT, "vid_minheight", "0", "minimum vid_height that is acceptable (to be set in default.cfg in mods)"}; @@ -1312,6 +1313,7 @@ void VID_Shared_Init(void) Cvar_RegisterVariable(&vid_vsync); Cvar_RegisterVariable(&vid_mouse); Cvar_RegisterVariable(&vid_mouse_clickthrough); + Cvar_RegisterVariable(&vid_minimize_on_focus_loss); Cvar_RegisterVariable(&vid_grabkeyboard); Cvar_RegisterVariable(&vid_touchscreen); Cvar_RegisterVariable(&vid_touchscreen_showkeyboard);