From 8cbbfaae9e99fa1a23a0febf605e9a10e991d51b Mon Sep 17 00:00:00 2001 From: Rykita Date: Wed, 24 May 2023 16:42:36 +0200 Subject: [PATCH 1/3] Pause on Minimized/Focus Lost is now in the options menu --- src/client/input/sdl.c | 6 +++--- src/client/menu/menu.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/client/input/sdl.c b/src/client/input/sdl.c index b121eca8..8b6e025e 100644 --- a/src/client/input/sdl.c +++ b/src/client/input/sdl.c @@ -732,8 +732,8 @@ IN_Update(void) Cvar_SetValue("paused", 0); } } - else if (event.window.event == SDL_WINDOWEVENT_MINIMIZED || - event.window.event == SDL_WINDOWEVENT_HIDDEN) + else if (event.window.event == SDL_WINDOWEVENT_MINIMIZED && windowed_pauseonfocuslost->value > 0 || + event.window.event == SDL_WINDOWEVENT_HIDDEN && windowed_pauseonfocuslost->value > 0) { Cvar_SetValue("paused", 1); } @@ -2322,7 +2322,7 @@ IN_Init(void) gyro_active = true; } - windowed_pauseonfocuslost = Cvar_Get("windowed_pauseonfocuslost", "0", CVAR_USERINFO | CVAR_ARCHIVE); + windowed_pauseonfocuslost = Cvar_Get("w_pauseonfocuslost", "0", CVAR_USERINFO | CVAR_ARCHIVE); windowed_mouse = Cvar_Get("windowed_mouse", "1", CVAR_USERINFO | CVAR_ARCHIVE); Cmd_AddCommand("+mlook", IN_MLookDown); diff --git a/src/client/menu/menu.c b/src/client/menu/menu.c index 8af0625c..effe8cb9 100644 --- a/src/client/menu/menu.c +++ b/src/client/menu/menu.c @@ -2154,6 +2154,7 @@ static menuslider_s s_options_oggvolume_slider; static menulist_s s_options_oggenable_box; static menulist_s s_options_quality_list; static menulist_s s_options_console_action; +static menulist_s s_options_pauseonfocus_box; static void CrosshairFunc(void *unused) @@ -2161,6 +2162,12 @@ CrosshairFunc(void *unused) Cvar_SetValue("crosshair", (float)s_options_crosshair_box.curvalue); } +static void +PauseFocusFunc() +{ + Cvar_SetValue("w_pauseonfocuslost", (float)s_options_pauseonfocus_box.curvalue); +} + static void CustomizeControlsFunc(void *unused) { @@ -2432,6 +2439,13 @@ Options_MenuInit(void) s_options_crosshair_box.generic.name = "crosshair"; s_options_crosshair_box.generic.callback = CrosshairFunc; s_options_crosshair_box.itemnames = crosshair_names; + + s_options_pauseonfocus_box.generic.type = MTYPE_SPINCONTROL; + s_options_pauseonfocus_box.generic.x = 0; + s_options_pauseonfocus_box.generic.y = (y += 10); + s_options_pauseonfocus_box.generic.name = "pause on minimized"; + s_options_pauseonfocus_box.generic.callback = PauseFocusFunc; + s_options_pauseonfocus_box.itemnames = yesno_names; y += 10; if (show_gamepad) @@ -2475,6 +2489,7 @@ Options_MenuInit(void) Menu_AddItem(&s_options_menu, (void *)&s_options_lookstrafe_box); Menu_AddItem(&s_options_menu, (void *)&s_options_freelook_box); Menu_AddItem(&s_options_menu, (void *)&s_options_crosshair_box); + Menu_AddItem(&s_options_menu, (void*)&s_options_pauseonfocus_box); if (show_gamepad) { From be1e6e1743d9d5ad7fb7fbf395df6155435bd58f Mon Sep 17 00:00:00 2001 From: apartfromtime <42292382+apartfromtime@users.noreply.github.com> Date: Thu, 25 May 2023 15:33:12 +1000 Subject: [PATCH 2/3] Fix pause/un-pause on window focus gained or lost Fixed pause/un-pause on window focus gained or lost in pull request #1017. Fixed ogg playback when switching video options, missed in #1004. Fixed ogg playback when the last menu closed, misplaced in #1004. --- src/client/input/sdl.c | 20 +++++++++++++++++--- src/client/menu/menu.c | 13 ++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/client/input/sdl.c b/src/client/input/sdl.c index 8b6e025e..ec8c14c9 100644 --- a/src/client/input/sdl.c +++ b/src/client/input/sdl.c @@ -693,7 +693,7 @@ IN_Update(void) { S_Activate(false); - if (windowed_pauseonfocuslost->value == 1) + if (windowed_pauseonfocuslost->value != 2) { Cvar_SetValue("paused", 1); } @@ -710,6 +710,11 @@ IN_Update(void) { S_Activate(true); + if (windowed_pauseonfocuslost->value == 0) + { + Cvar_SetValue("paused", 0); + } + /* play music */ if (Cvar_VariableValue("ogg_pausewithgame") == 1 && OGG_Status() == PAUSE && cl.attractloop == false && @@ -731,9 +736,18 @@ IN_Update(void) { Cvar_SetValue("paused", 0); } + + /* play music */ + if (Cvar_VariableValue("ogg_pausewithgame") == 1 && + OGG_Status() == PAUSE && cl.attractloop == false && + cl_paused->value == 0) + { + Cbuf_AddText("ogg toggle\n"); + } + } - else if (event.window.event == SDL_WINDOWEVENT_MINIMIZED && windowed_pauseonfocuslost->value > 0 || - event.window.event == SDL_WINDOWEVENT_HIDDEN && windowed_pauseonfocuslost->value > 0) + else if (event.window.event == SDL_WINDOWEVENT_MINIMIZED || + event.window.event == SDL_WINDOWEVENT_HIDDEN) { Cvar_SetValue("paused", 1); } diff --git a/src/client/menu/menu.c b/src/client/menu/menu.c index effe8cb9..580b9831 100644 --- a/src/client/menu/menu.c +++ b/src/client/menu/menu.c @@ -124,13 +124,6 @@ M_ForceMenuOff(void) void M_PopMenu(void) { - /* play music */ - if (Cvar_VariableValue("ogg_pausewithgame") == 1 && - OGG_Status() == PAUSE && cl.attractloop == false) - { - Cbuf_AddText("ogg toggle\n"); - } - S_StartLocalSound(menu_out_sound); if (m_menudepth < 1) @@ -146,6 +139,12 @@ M_PopMenu(void) if (!m_menudepth) { M_ForceMenuOff(); + /* play music */ + if (Cvar_VariableValue("ogg_pausewithgame") == 1 && + OGG_Status() == PAUSE && cl.attractloop == false) + { + Cbuf_AddText("ogg toggle\n"); + } } } From cd351a06023ecbbbb7e2a99d40684a65688a0a3f Mon Sep 17 00:00:00 2001 From: Rykita Date: Thu, 25 May 2023 23:51:58 +0200 Subject: [PATCH 3/3] Fixed vid_pauseonfocuslost, final. --- src/client/input/sdl.c | 12 +++--------- src/client/menu/menu.c | 13 +++++++++++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/client/input/sdl.c b/src/client/input/sdl.c index ec8c14c9..fc634b7b 100644 --- a/src/client/input/sdl.c +++ b/src/client/input/sdl.c @@ -693,7 +693,7 @@ IN_Update(void) { S_Activate(false); - if (windowed_pauseonfocuslost->value != 2) + if (windowed_pauseonfocuslost->value != 1) { Cvar_SetValue("paused", 1); } @@ -710,7 +710,7 @@ IN_Update(void) { S_Activate(true); - if (windowed_pauseonfocuslost->value == 0) + if (windowed_pauseonfocuslost->value == 2) { Cvar_SetValue("paused", 0); } @@ -744,12 +744,6 @@ IN_Update(void) { Cbuf_AddText("ogg toggle\n"); } - - } - else if (event.window.event == SDL_WINDOWEVENT_MINIMIZED || - event.window.event == SDL_WINDOWEVENT_HIDDEN) - { - Cvar_SetValue("paused", 1); } break; @@ -2336,7 +2330,7 @@ IN_Init(void) gyro_active = true; } - windowed_pauseonfocuslost = Cvar_Get("w_pauseonfocuslost", "0", CVAR_USERINFO | CVAR_ARCHIVE); + windowed_pauseonfocuslost = Cvar_Get("vid_pauseonfocuslost", "0", CVAR_USERINFO | CVAR_ARCHIVE); windowed_mouse = Cvar_Get("windowed_mouse", "1", CVAR_USERINFO | CVAR_ARCHIVE); Cmd_AddCommand("+mlook", IN_MLookDown); diff --git a/src/client/menu/menu.c b/src/client/menu/menu.c index 580b9831..ba7eac4c 100644 --- a/src/client/menu/menu.c +++ b/src/client/menu/menu.c @@ -2164,7 +2164,7 @@ CrosshairFunc(void *unused) static void PauseFocusFunc() { - Cvar_SetValue("w_pauseonfocuslost", (float)s_options_pauseonfocus_box.curvalue); + Cvar_SetValue("vid_pauseonfocuslost", (float)s_options_pauseonfocus_box.curvalue); } static void @@ -2202,6 +2202,7 @@ ControlsSetMenuItemValues(void) s_options_lookstrafe_box.curvalue = (lookstrafe->value != 0); s_options_freelook_box.curvalue = (freelook->value != 0); s_options_crosshair_box.curvalue = ClampCvar(0, 3, crosshair->value); + s_options_pauseonfocus_box.curvalue = ClampCvar(0, 2, Cvar_VariableValue("vid_pauseonfocuslost")); } static void @@ -2341,6 +2342,14 @@ Options_MenuInit(void) 0 }; + static const char* pause_names[] = + { + "yes", + "no", + "unpause on re-focus", + 0 + }; + static const char *crosshair_names[] = { "none", @@ -2444,7 +2453,7 @@ Options_MenuInit(void) s_options_pauseonfocus_box.generic.y = (y += 10); s_options_pauseonfocus_box.generic.name = "pause on minimized"; s_options_pauseonfocus_box.generic.callback = PauseFocusFunc; - s_options_pauseonfocus_box.itemnames = yesno_names; + s_options_pauseonfocus_box.itemnames = pause_names; y += 10; if (show_gamepad)