diff mbox series

gtk: Add show_menubar=on|off command line option.

Message ID ABCl6OVdH-uJRTTHQW03cUzQV49DpAlfES0YCgGQlOljvmVYqFNQjBKZ0CPNmduU1RWn9iOEiQxYyNQ0BOHw3sv3RKpsXQn2pv4oJIbUZ0Y=@proton.me
State New
Headers show
Series gtk: Add show_menubar=on|off command line option. | expand

Commit Message

Bryce Mills Sept. 24, 2022, 9:09 p.m. UTC
The patch adds "show_menubar" command line option for GTK UI similar to
"show_tabs". This option allows to hide menu bar initially, it still can
be toggled by shortcut and other shortcuts still work.

(First-time contributor)

Signed-off-by: Bryce Mills <brycemills@proton.me>
---
 qapi/ui.json    |  6 +++++-
 qemu-options.hx |  4 +++-
 ui/gtk.c        | 15 ++++++++++-----
 3 files changed, 18 insertions(+), 7 deletions(-)

--
2.37.3

Comments

Markus Armbruster Sept. 26, 2022, 8:51 a.m. UTC | #1
Bryce Mills <brycemills@proton.me> writes:

> The patch adds "show_menubar" command line option for GTK UI similar to
> "show_tabs". This option allows to hide menu bar initially, it still can
> be toggled by shortcut and other shortcuts still work.
>
> (First-time contributor)
>
> Signed-off-by: Bryce Mills <brycemills@proton.me>
> ---
>  qapi/ui.json    |  6 +++++-
>  qemu-options.hx |  4 +++-
>  ui/gtk.c        | 15 ++++++++++-----
>  3 files changed, 18 insertions(+), 7 deletions(-)
>
> diff --git a/qapi/ui.json b/qapi/ui.json
> index 286c5731d1..124975d724 100644
> --- a/qapi/ui.json
> +++ b/qapi/ui.json
> @@ -1200,12 +1200,16 @@
>  #               by default.
>  #               Since 7.1
>  #
> +# @show-menubar:  Display the main window menubar
> +#                 Since 8.0

Please mention the default.

Not your patch's fault: @grab-on-hover and @show-tabs should mention
their default.

> +#
>  # Since: 2.12
>  ##
>  { 'struct'  : 'DisplayGTK',
>    'data'    : { '*grab-on-hover' : 'bool',
>                  '*zoom-to-fit'   : 'bool',
> -                '*show-tabs'     : 'bool'  } }
> +                '*show-tabs'     : 'bool',
> +                '*show-menubar'  : 'bool'  } }
>
>  ##
>  # @DisplayEGLHeadless:

[...]
Bryce Mills Sept. 26, 2022, 5:32 p.m. UTC | #2
The patch adds "show_menubar" command line option for GTK UI similar to
"show_tabs". This option allows to hide menu bar initially, it still can
be toggled by shortcut and other shortcuts still work.

Signed-off-by: Bryce Mills <brycemills@proton.me>
---
 qapi/ui.json    |  6 +++++-
 qemu-options.hx |  3 +++
 ui/gtk.c        | 15 ++++++++++-----
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/qapi/ui.json b/qapi/ui.json
index 286c5731d1..cb252bdf86 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -1200,12 +1200,16 @@
 #               by default.
 #               Since 7.1
 #
+# @show-menubar:  Display the main window menubar. Defaults to "on".
+#                 Since 8.0
+#
 # Since: 2.12
 ##
 { 'struct'  : 'DisplayGTK',
   'data'    : { '*grab-on-hover' : 'bool',
                 '*zoom-to-fit'   : 'bool',
-                '*show-tabs'     : 'bool'  } }
+                '*show-tabs'     : 'bool',
+                '*show-menubar'  : 'bool'  } }
 
 ##
 # @DisplayEGLHeadless:
diff --git a/qemu-options.hx b/qemu-options.hx
index d8b5ce5b43..62d3ce10bf 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1947,6 +1947,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
 #if defined(CONFIG_GTK)
     "-display gtk[,full-screen=on|off][,gl=on|off][,grab-on-hover=on|off]\n"
     "            [,show-tabs=on|off][,show-cursor=on|off][,window-close=on|off]\n"
+    "            [,show-menubar=on|off]\n"
 #endif
 #if defined(CONFIG_VNC)
     "-display vnc=<display>[,<optargs>]\n"
@@ -2039,6 +2040,8 @@ SRST
 
         ``window-close=on|off`` : Allow to quit qemu with window close button
 
+        ``show-menubar=on|off`` : Display then main window menubar
+
     ``curses[,charset=<encoding>]``
         Display video output via curses. For graphics device models
         which support a text mode, QEMU can display this output using a
diff --git a/ui/gtk.c b/ui/gtk.c
index 1467b8c7d7..0c54600592 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -2167,7 +2167,7 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
     return group;
 }
 
-static GtkWidget *gd_create_menu_view(GtkDisplayState *s)
+static GtkWidget *gd_create_menu_view(GtkDisplayState *s, DisplayOptions *opts)
 {
     GSList *group = NULL;
     GtkWidget *view_menu;
@@ -2265,7 +2265,8 @@ static GtkWidget *gd_create_menu_view(GtkDisplayState *s)
     s->show_menubar_item = gtk_check_menu_item_new_with_mnemonic(
             _("Show Menubar"));
     gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->show_menubar_item),
-                                   TRUE);
+                                   !opts->u.gtk.has_show_menubar ||
+                                   opts->u.gtk.show_menubar);
     gtk_accel_group_connect(s->accel_group, GDK_KEY_m, HOTKEY_MODIFIERS, 0,
             g_cclosure_new_swap(G_CALLBACK(gd_accel_show_menubar), s, NULL));
     gtk_accel_label_set_accel(
@@ -2276,13 +2277,13 @@ static GtkWidget *gd_create_menu_view(GtkDisplayState *s)
     return view_menu;
 }
 
-static void gd_create_menus(GtkDisplayState *s)
+static void gd_create_menus(GtkDisplayState *s, DisplayOptions *opts)
 {
     GtkSettings *settings;
 
     s->accel_group = gtk_accel_group_new();
     s->machine_menu = gd_create_menu_machine(s);
-    s->view_menu = gd_create_menu_view(s);
+    s->view_menu = gd_create_menu_view(s, opts);
 
     s->machine_menu_item = gtk_menu_item_new_with_mnemonic(_("_Machine"));
     gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->machine_menu_item),
@@ -2359,7 +2360,7 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
 
     gtk_window_set_icon_name(GTK_WINDOW(s->window), "qemu");
 
-    gd_create_menus(s);
+    gd_create_menus(s, opts);
 
     gd_connect_signals(s);
 
@@ -2374,6 +2375,10 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
     gtk_container_add(GTK_CONTAINER(s->window), s->vbox);
 
     gtk_widget_show_all(s->window);
+    if (opts->u.gtk.has_show_menubar &&
+        !opts->u.gtk.show_menubar) {
+        gtk_widget_hide(s->menu_bar);
+    }
 
     vc = gd_vc_find_current(s);
     gtk_widget_set_sensitive(s->view_menu, vc != NULL);
Markus Armbruster Sept. 27, 2022, 6:12 a.m. UTC | #3
Please post revisions in a new thread (not in reply to anything), and
with a subject like [PATCH v2].  You can use "git format-patch -v2" to
get such subjects.

Bryce Mills <brycemills@proton.me> writes:

> The patch adds "show_menubar" command line option for GTK UI similar to
> "show_tabs". This option allows to hide menu bar initially, it still can
> be toggled by shortcut and other shortcuts still work.
>
> Signed-off-by: Bryce Mills <brycemills@proton.me>
> ---
>  qapi/ui.json    |  6 +++++-
>  qemu-options.hx |  3 +++
>  ui/gtk.c        | 15 ++++++++++-----
>  3 files changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/qapi/ui.json b/qapi/ui.json
> index 286c5731d1..cb252bdf86 100644
> --- a/qapi/ui.json
> +++ b/qapi/ui.json
> @@ -1200,12 +1200,16 @@
>  #               by default.
>  #               Since 7.1
>  #

Drop the blank line, please.

> +# @show-menubar:  Display the main window menubar. Defaults to "on".
> +#                 Since 8.0
> +#
>  # Since: 2.12
>  ##
>  { 'struct'  : 'DisplayGTK',
>    'data'    : { '*grab-on-hover' : 'bool',
>                  '*zoom-to-fit'   : 'bool',
> -                '*show-tabs'     : 'bool'  } }
> +                '*show-tabs'     : 'bool',
> +                '*show-menubar'  : 'bool'  } }
>  
>  ##
>  # @DisplayEGLHeadless:

With that done, QAPI schema
Acked-by: Markus Armbruster <armbru@redhat.com>

Two more remarks below.

> diff --git a/qemu-options.hx b/qemu-options.hx
> index d8b5ce5b43..62d3ce10bf 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -1947,6 +1947,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
>  #if defined(CONFIG_GTK)
>      "-display gtk[,full-screen=on|off][,gl=on|off][,grab-on-hover=on|off]\n"
>      "            [,show-tabs=on|off][,show-cursor=on|off][,window-close=on|off]\n"
> +    "            [,show-menubar=on|off]\n"

Not this patch's fault: help neglects to explain the option parameters.

>  #endif
>  #if defined(CONFIG_VNC)
>      "-display vnc=<display>[,<optargs>]\n"
> @@ -2039,6 +2040,8 @@ SRST
>  
>          ``window-close=on|off`` : Allow to quit qemu with window close button
>  
> +        ``show-menubar=on|off`` : Display then main window menubar
> +

Please specify the default here as well.

>      ``curses[,charset=<encoding>]``
>          Display video output via curses. For graphics device models
>          which support a text mode, QEMU can display this output using a

[...]
diff mbox series

Patch

diff --git a/qapi/ui.json b/qapi/ui.json
index 286c5731d1..124975d724 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -1200,12 +1200,16 @@ 
 #               by default.
 #               Since 7.1
 #
+# @show-menubar:  Display the main window menubar
+#                 Since 8.0
+#
 # Since: 2.12
 ##
 { 'struct'  : 'DisplayGTK',
   'data'    : { '*grab-on-hover' : 'bool',
                 '*zoom-to-fit'   : 'bool',
-                '*show-tabs'     : 'bool'  } }
+                '*show-tabs'     : 'bool',
+                '*show-menubar'  : 'bool'  } }

 ##
 # @DisplayEGLHeadless:
diff --git a/qemu-options.hx b/qemu-options.hx
index d8b5ce5b43..d90ecc20a7 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1946,7 +1946,7 @@  DEF("display", HAS_ARG, QEMU_OPTION_display,
 #endif
 #if defined(CONFIG_GTK)
     "-display gtk[,full-screen=on|off][,gl=on|off][,grab-on-hover=on|off]\n"
-    "            [,show-tabs=on|off][,show-cursor=on|off][,window-close=on|off]\n"
+    "            [,show-tabs=on|off][,show-cursor=on|off][,window-close=on|off][,show-menubar=on|off]\n"
 #endif
 #if defined(CONFIG_VNC)
     "-display vnc=<display>[,<optargs>]\n"
@@ -2039,6 +2039,8 @@  SRST

         ``window-close=on|off`` : Allow to quit qemu with window close button

+        ``show-menubar=on|off`` : Display then main window menubar
+
     ``curses[,charset=<encoding>]``
         Display video output via curses. For graphics device models
         which support a text mode, QEMU can display this output using a
diff --git a/ui/gtk.c b/ui/gtk.c
index 1467b8c7d7..0c54600592 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -2167,7 +2167,7 @@  static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
     return group;
 }

-static GtkWidget *gd_create_menu_view(GtkDisplayState *s)
+static GtkWidget *gd_create_menu_view(GtkDisplayState *s, DisplayOptions *opts)
 {
     GSList *group = NULL;
     GtkWidget *view_menu;
@@ -2265,7 +2265,8 @@  static GtkWidget *gd_create_menu_view(GtkDisplayState *s)
     s->show_menubar_item = gtk_check_menu_item_new_with_mnemonic(
             _("Show Menubar"));
     gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->show_menubar_item),
-                                   TRUE);
+                                   !opts->u.gtk.has_show_menubar ||
+                                   opts->u.gtk.show_menubar);
     gtk_accel_group_connect(s->accel_group, GDK_KEY_m, HOTKEY_MODIFIERS, 0,
             g_cclosure_new_swap(G_CALLBACK(gd_accel_show_menubar), s, NULL));
     gtk_accel_label_set_accel(
@@ -2276,13 +2277,13 @@  static GtkWidget *gd_create_menu_view(GtkDisplayState *s)
     return view_menu;
 }

-static void gd_create_menus(GtkDisplayState *s)
+static void gd_create_menus(GtkDisplayState *s, DisplayOptions *opts)
 {
     GtkSettings *settings;

     s->accel_group = gtk_accel_group_new();
     s->machine_menu = gd_create_menu_machine(s);
-    s->view_menu = gd_create_menu_view(s);
+    s->view_menu = gd_create_menu_view(s, opts);

     s->machine_menu_item = gtk_menu_item_new_with_mnemonic(_("_Machine"));
     gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->machine_menu_item),
@@ -2359,7 +2360,7 @@  static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)

     gtk_window_set_icon_name(GTK_WINDOW(s->window), "qemu");

-    gd_create_menus(s);
+    gd_create_menus(s, opts);

     gd_connect_signals(s);

@@ -2374,6 +2375,10 @@  static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
     gtk_container_add(GTK_CONTAINER(s->window), s->vbox);

     gtk_widget_show_all(s->window);
+    if (opts->u.gtk.has_show_menubar &&
+        !opts->u.gtk.show_menubar) {
+        gtk_widget_hide(s->menu_bar);
+    }

     vc = gd_vc_find_current(s);
     gtk_widget_set_sensitive(s->view_menu, vc != NULL);