]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
vid: add cvar vid_minimize_on_focus_loss
authorbones_was_here <bones_was_here@xonotic.au>
Mon, 30 Oct 2023 01:15:36 +0000 (11:15 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Wed, 8 Nov 2023 17:27:00 +0000 (03:27 +1000)
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 <bones_was_here@xonotic.au>
vid.h
vid_sdl.c
vid_shared.c

diff --git a/vid.h b/vid.h
index cab749693ec3744dd6151752e3012f1b6e8c8f71..3ede535d9238c7c179a87b12ea27024e4ab377b5 100644 (file)
--- 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;
index 6f39dd5f72791d069c9d311bfb95e83eb618c30c..88ec122efb485eaabc925f6daa14e2f7db59461f 100644 (file)
--- 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);
index 5e216845c774deaa930d7406ca277e66679e069b..aa34a1e38ab54be17cea6b9cdf6799f76e049698 100644 (file)
@@ -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);