From 565bbeddebc3e553bf810de3cd069f61caa0aac2 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 7 Jun 2023 07:06:21 +0300 Subject: [PATCH 29/29] gtk: Apply changes to 'fullscreen' option changes immediately When 'fullscreen' option was changed via options dialog, it was taken to use only after a client restart. Add an option changed callback to gtk-clients that apply the change immediately. Reported by onluntuva See osdn #47531 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.0/gui_main.c | 14 ++++++++++++++ client/gui-gtk-3.0/gui_main.h | 3 +++ client/gui-gtk-3.0/menu.c | 6 +----- client/gui-gtk-3.22/gui_main.c | 14 ++++++++++++++ client/gui-gtk-3.22/gui_main.h | 3 +++ client/gui-gtk-3.22/menu.c | 6 +----- client/gui-gtk-4.0/gui_main.c | 14 ++++++++++++++ client/gui-gtk-4.0/gui_main.h | 3 +++ client/gui-gtk-4.0/menu.c | 6 +----- 9 files changed, 54 insertions(+), 15 deletions(-) diff --git a/client/gui-gtk-3.0/gui_main.c b/client/gui-gtk-3.0/gui_main.c index 236c10e6bc..da99fdc4ca 100644 --- a/client/gui-gtk-3.0/gui_main.c +++ b/client/gui-gtk-3.0/gui_main.c @@ -2228,6 +2228,18 @@ static void allied_chat_only_callback(struct option *poption) option_bool_get(poption)); } +/**********************************************************************//** + Option callback for the 'fullscreen' gtk-gui option. +**************************************************************************/ +void fullscreen_opt_refresh(struct option *poption) +{ + if (GUI_GTK_OPTION(fullscreen)) { + gtk_window_fullscreen(GTK_WINDOW(toplevel)); + } else { + gtk_window_unfullscreen(GTK_WINDOW(toplevel)); + } +} + /**********************************************************************//** Change the city names font. **************************************************************************/ @@ -2278,6 +2290,8 @@ void options_extra_init(void) option_var_set_callback(allied_chat_only, allied_chat_only_callback); + option_var_set_callback(fullscreen, + fullscreen_opt_refresh); option_var_set_callback(font_city_names, apply_city_names_font); diff --git a/client/gui-gtk-3.0/gui_main.h b/client/gui-gtk-3.0/gui_main.h index 68612b7c62..7288fafb04 100644 --- a/client/gui-gtk-3.0/gui_main.h +++ b/client/gui-gtk-3.0/gui_main.h @@ -17,6 +17,7 @@ /* client */ #include "gui_main_g.h" +#include "options.h" #define GUI_GTK_OPTION(optname) gui_options.gui_gtk3_##optname #define GUI_GTK_OPTION_STR(optname) "gui_gtk3_" #optname @@ -83,6 +84,8 @@ int screen_width(void); int screen_height(void); struct video_mode *resolution_request_get(void); +void fullscreen_opt_refresh(struct option *poption); + bool is_gui_up(void); void update_turn_done_tooltip(void); diff --git a/client/gui-gtk-3.0/menu.c b/client/gui-gtk-3.0/menu.c index 93a4a07731..1aec1f1a38 100644 --- a/client/gui-gtk-3.0/menu.c +++ b/client/gui-gtk-3.0/menu.c @@ -1445,11 +1445,7 @@ static void full_screen_callback(GtkCheckMenuItem *item, gpointer data) if (GUI_GTK_OPTION(fullscreen) ^ gtk_check_menu_item_get_active(item)) { GUI_GTK_OPTION(fullscreen) ^= 1; - if (GUI_GTK_OPTION(fullscreen)) { - gtk_window_fullscreen(GTK_WINDOW(toplevel)); - } else { - gtk_window_unfullscreen(GTK_WINDOW(toplevel)); - } + fullscreen_opt_refresh(NULL); } } diff --git a/client/gui-gtk-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c index 4d0f40f94a..f28a31069c 100644 --- a/client/gui-gtk-3.22/gui_main.c +++ b/client/gui-gtk-3.22/gui_main.c @@ -2386,6 +2386,18 @@ static void allied_chat_only_callback(struct option *poption) option_bool_get(poption)); } +/**********************************************************************//** + Option callback for the 'fullscreen' gtk-gui option. +**************************************************************************/ +void fullscreen_opt_refresh(struct option *poption) +{ + if (GUI_GTK_OPTION(fullscreen)) { + gtk_window_fullscreen(GTK_WINDOW(toplevel)); + } else { + gtk_window_unfullscreen(GTK_WINDOW(toplevel)); + } +} + /**********************************************************************//** Change the city names font. **************************************************************************/ @@ -2437,6 +2449,8 @@ void options_extra_init(void) option_var_set_callback(allied_chat_only, allied_chat_only_callback); + option_var_set_callback(fullscreen, + fullscreen_opt_refresh); option_var_set_callback(font_city_names, apply_city_names_font); diff --git a/client/gui-gtk-3.22/gui_main.h b/client/gui-gtk-3.22/gui_main.h index 94fe58367c..c28adeea87 100644 --- a/client/gui-gtk-3.22/gui_main.h +++ b/client/gui-gtk-3.22/gui_main.h @@ -17,6 +17,7 @@ /* client */ #include "gui_main_g.h" +#include "options.h" #define GUI_GTK_OPTION(optname) gui_options.gui_gtk3_22_##optname #define GUI_GTK_OPTION_STR(optname) "gui_gtk3_22_" #optname @@ -83,6 +84,8 @@ int screen_width(void); int screen_height(void); struct video_mode *resolution_request_get(void); +void fullscreen_opt_refresh(struct option *poption); + bool is_gui_up(void); void update_turn_done_tooltip(void); diff --git a/client/gui-gtk-3.22/menu.c b/client/gui-gtk-3.22/menu.c index 6b8e3ab003..8a53afa87d 100644 --- a/client/gui-gtk-3.22/menu.c +++ b/client/gui-gtk-3.22/menu.c @@ -1454,11 +1454,7 @@ static void full_screen_callback(GtkCheckMenuItem *item, gpointer data) if (GUI_GTK_OPTION(fullscreen) ^ gtk_check_menu_item_get_active(item)) { GUI_GTK_OPTION(fullscreen) ^= 1; - if (GUI_GTK_OPTION(fullscreen)) { - gtk_window_fullscreen(GTK_WINDOW(toplevel)); - } else { - gtk_window_unfullscreen(GTK_WINDOW(toplevel)); - } + fullscreen_opt_refresh(NULL); } } diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c index 59724b6cdc..446038f261 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -2383,6 +2383,18 @@ static void allied_chat_only_callback(struct option *poption) option_bool_get(poption)); } +/**********************************************************************//** + Option callback for the 'fullscreen' gtk-gui option. +**************************************************************************/ +void fullscreen_opt_refresh(struct option *poption) +{ + if (GUI_GTK_OPTION(fullscreen)) { + gtk_window_fullscreen(GTK_WINDOW(toplevel)); + } else { + gtk_window_unfullscreen(GTK_WINDOW(toplevel)); + } +} + /**********************************************************************//** Change the city names font. **************************************************************************/ @@ -2434,6 +2446,8 @@ void options_extra_init(void) option_var_set_callback(allied_chat_only, allied_chat_only_callback); + option_var_set_callback(fullscreen, + fullscreen_opt_refresh); option_var_set_callback(font_city_names, apply_city_names_font); diff --git a/client/gui-gtk-4.0/gui_main.h b/client/gui-gtk-4.0/gui_main.h index dbd8c8a417..1f094f0fed 100644 --- a/client/gui-gtk-4.0/gui_main.h +++ b/client/gui-gtk-4.0/gui_main.h @@ -17,6 +17,7 @@ /* client */ #include "gui_main_g.h" +#include "options.h" #define GUI_GTK_OPTION(optname) gui_options.gui_gtk4_##optname #define GUI_GTK_OPTION_STR(optname) "gui_gtk4_" #optname @@ -77,6 +78,8 @@ int screen_width(void); int screen_height(void); struct video_mode *resolution_request_get(void); +void fullscreen_opt_refresh(struct option *poption); + GtkApplication *gui_app(void); bool is_gui_up(void); diff --git a/client/gui-gtk-4.0/menu.c b/client/gui-gtk-4.0/menu.c index ec623880c6..7f4cd95cc8 100644 --- a/client/gui-gtk-4.0/menu.c +++ b/client/gui-gtk-4.0/menu.c @@ -2057,11 +2057,7 @@ static void full_screen_callback(GSimpleAction *action, GVariant *parameter, info->state ^= 1; GUI_GTK_OPTION(fullscreen) = info->state; - if (GUI_GTK_OPTION(fullscreen)) { - gtk_window_fullscreen(GTK_WINDOW(toplevel)); - } else { - gtk_window_unfullscreen(GTK_WINDOW(toplevel)); - } + fullscreen_opt_refresh(NULL); g_menu_remove(view_menu, VMENU_FULL_SCREEN); -- 2.39.2