Skip to contentSkip to conversation

ui/gtk: enable fullscreen hotkey for detached windows

PATCH In review [email protected] 2 participants 6 messages Sep 14 – Sep 15

lore
Share & tools
lore
#1 lore raw

PATCH 2/2 ui/gtk: register "Grab Input" shortcut to accel_group

In reply to [email protected]

From: Dongwon Kim <[email protected]>

The "Grab Input" shortcut key currently fails to trigger when the window is in fullscreen mode because the menubar is hidden, which disables GtkAccelMap-based shortcuts associated with it.

To ensure the accelerator remains active in fullscreen, connect it directly to s->accel_group and explicitly set the hotkey display on the menu item label.

Cc Marc-André Lureau <[email protected]>
---
 ui/gtk.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
ui/gtk.c +15 -5
index 3c9720a330..2f83c557d8 100644
@@ -1878,6 +1878,12 @@ static void gd_menu_grab_input(GtkMenuItem *item, void *opaque)
     gd_update_cursor(vc);
 }
 
+static void gd_accel_grab_input(void *opaque)
+{
+    GtkDisplayState *s = opaque;
+    gtk_menu_item_activate(GTK_MENU_ITEM(s->grab_item));
+}
+
 static void gd_change_page(GtkNotebook *nb, gpointer arg1, guint arg2,
                            gpointer data)
 {
@@ -2557,6 +2563,7 @@ static void gd_create_menu_view(GtkDisplayState *s, DisplayOptions *opts)
 {
     GtkWidget *view_menu;
     GtkWidget *separator;
+    GtkWidget *child;
     QemuConsole *con;
     bool zoom_to_fit = false;
     int vc, i;
@@ -2615,12 +2622,15 @@ static void gd_create_menu_view(GtkDisplayState *s, DisplayOptions *opts)
     gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_on_hover_item);
 
     s->grab_item = gtk_check_menu_item_new_with_mnemonic(_("_Grab Input"));
-    gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->grab_item),
-                                 "<QEMU>/View/Grab Input");
-    gtk_accel_map_add_entry("<QEMU>/View/Grab Input", GDK_KEY_g,
-                            HOTKEY_MODIFIERS);
     gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_item);
-
+    gtk_accel_group_connect(s->accel_group, GDK_KEY_g, HOTKEY_MODIFIERS, 0,
+                            g_cclosure_new_swap(G_CALLBACK(gd_accel_grab_input),
+                                                s, NULL));
+    child = gtk_bin_get_child(GTK_BIN(s->grab_item));
+    if (GTK_IS_ACCEL_LABEL(child)) {
+        gtk_accel_label_set_accel(GTK_ACCEL_LABEL(child),
+                                  GDK_KEY_g, HOTKEY_MODIFIERS);
+    }
     separator = gtk_separator_menu_item_new();
     gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
 
Signature · 1 line
2.43.0
#0 lore raw

PATCH 1/2 ui/gtk: enable fullscreen hotkey for detached windows

From: Dongwon Kim <[email protected]>

Currently, the fullscreen toggle hotkey (Ctrl+Alt+f by default) only functions for the main QEMU window. When a Virtual Console (VC) is detached into its own separate window (untabified), it loses this capability.

Implement a toggle helper, gd_win_fullscreen, and connect it to the 'f' accelerator when a detached window is created in gd_menu_untabify. This allows individual detached windows to be toggled fullscreen independently.

Cc Marc-André Lureau <[email protected]>
---
 ui/gtk.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)
ui/gtk.c +43 -3
index a723c8215d..3c9720a330 100644
@@ -1556,6 +1556,42 @@ static gboolean gd_win_grab(void *opaque)
     return TRUE;
 }
 
+static void gd_win_fullscreen(void *opaque)
+{
+    VirtualConsole *vc = opaque;
+    GtkDisplayState *s = vc->s;
+    GdkWindow *window;
+    GdkWindowState state;
+
+    if (!vc->window || !gtk_widget_get_realized(vc->window)) {
+        return;
+    }
+
+    window = gtk_widget_get_window(vc->window);
+    if (!window) {
+        return;
+    }
+
+    state = gdk_window_get_state(window);
+
+    if (state & GDK_WINDOW_STATE_FULLSCREEN) {
+        gtk_window_unfullscreen(GTK_WINDOW(vc->window));
+
+        if (vc->type == GD_VC_GFX) {
+            if (!s->free_scale) {
+                vc->gfx.scale_x = 1.0;
+                vc->gfx.scale_y = 1.0;
+            }
+            gd_update_windowsize(vc);
+        }
+    } else {
+        if (vc->type == GD_VC_GFX) {
+            gtk_widget_set_size_request(vc->gfx.drawing_area, -1, -1);
+        }
+        gtk_window_fullscreen(GTK_WINDOW(vc->window));
+    }
+}
+
 static void gd_menu_untabify(GtkMenuItem *item, void *opaque)
 {
     GtkDisplayState *s = opaque;
@@ -1590,9 +1626,13 @@ static void gd_menu_untabify(GtkMenuItem *item, void *opaque)
             GtkAccelGroup *ag = gtk_accel_group_new();
             gtk_window_add_accel_group(GTK_WINDOW(vc->window), ag);
 
-            GClosure *cb = g_cclosure_new_swap(G_CALLBACK(gd_win_grab),
-                                               vc, NULL);
-            gtk_accel_group_connect(ag, GDK_KEY_g, HOTKEY_MODIFIERS, 0, cb);
+            GClosure *cb_grab = g_cclosure_new_swap(G_CALLBACK(gd_win_grab),
+                                                    vc, NULL);
+            gtk_accel_group_connect(ag, GDK_KEY_g, HOTKEY_MODIFIERS, 0, cb_grab);
+            GClosure *cb_fullscreen = g_cclosure_new_swap(
+                                             G_CALLBACK(gd_win_fullscreen),
+                                             vc, NULL);
+            gtk_accel_group_connect(ag, GDK_KEY_f, HOTKEY_MODIFIERS, 0, cb_fullscreen);
         }
 
         gd_rebuild_vc_menu(s);
Signature · 1 line
2.43.0
#4 lore raw

Hi

Quoted 42 lines · On Mon, Sep 14, 2026 at 10:50 PM <[email protected]> wrote:

From: Dongwon Kim <[email protected]>

Currently, the fullscreen toggle hotkey (Ctrl+Alt+f by default) only functions for the main QEMU window. When a Virtual Console (VC) is detached into its own separate window (untabified), it loses this capability.

Implement a toggle helper, gd_win_fullscreen, and connect it to the 'f' accelerator when a detached window is created in gd_menu_untabify. This allows individual detached windows to be toggled fullscreen independently.

Cc Marc-André Lureau <[email protected]>
---
 ui/gtk.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)
ui/gtk.c +15 -0
index a723c8215d..3c9720a330 100644
@@ -1556,6 +1556,42 @@ static gboolean gd_win_grab(void *opaque)
     return TRUE;
 }
 
+static void gd_win_fullscreen(void *opaque)
+{
+    VirtualConsole *vc = opaque;
+    GtkDisplayState *s = vc->s;
+    GdkWindow *window;
+    GdkWindowState state;
+
+    if (!vc->window || !gtk_widget_get_realized(vc->window)) {
+        return;
+    }
+
+    window = gtk_widget_get_window(vc->window);
+    if (!window) {
+        return;
+    }

ui/gtk.c static gboolean gd_win_grab(void *opaque) · line 1583

Quoted 10 lines
ui/gtk.c +10 -0
+
+    state = gdk_window_get_state(window);
+
+    if (state & GDK_WINDOW_STATE_FULLSCREEN) {
+        gtk_window_unfullscreen(GTK_WINDOW(vc->window));
+
+        if (vc->type == GD_VC_GFX) {
+            if (!s->free_scale) {
+                vc->gfx.scale_x = 1.0;
+                vc->gfx.scale_y = 1.0;

gd_menu_full_screen restores it to gfx.preferred_scale

ui/gtk.c static gboolean gd_win_grab(void *opaque) · line 1593

Quoted 10 lines
ui/gtk.c +10 -0
+            }
+            gd_update_windowsize(vc);
+        }
+    } else {
+        if (vc->type == GD_VC_GFX) {
+            gtk_widget_set_size_request(vc->gfx.drawing_area, -1, -1);
+        }
+        gtk_window_fullscreen(GTK_WINDOW(vc->window));
+    }
+}

For consistency with gd_menu_full_screen() it should call gd_update_cursor

Quoted 5 lines
ui/gtk.c +1 -0
+
 static void gd_menu_untabify(GtkMenuItem *item, void *opaque)
 {
     GtkDisplayState *s = opaque;

ui/gtk.c static void gd_menu_untabify(GtkMenuItem *item, void *opaque) · line 1631

Quoted 9 lines
ui/gtk.c +3 -3
@@ -1590,9 +1626,13 @@ static void gd_menu_untabify(GtkMenuItem *item, void *opaque)
             GtkAccelGroup *ag = gtk_accel_group_new();
             gtk_window_add_accel_group(GTK_WINDOW(vc->window), ag);
 
-            GClosure *cb = g_cclosure_new_swap(G_CALLBACK(gd_win_grab),
-                                               vc, NULL);
-            gtk_accel_group_connect(ag, GDK_KEY_g, HOTKEY_MODIFIERS, 0, cb);
+            GClosure *cb_grab = g_cclosure_new_swap(G_CALLBACK(gd_win_grab),
+                                                    vc, NULL);
+            gtk_accel_group_connect(ag, GDK_KEY_g, HOTKEY_MODIFIERS, 0, cb_grab);

You also hook grab, this should be mentionned in the commit message.

btw, it would be nice to remove the stderr printf there..

Why not add the zoom keys while at it?

thanks

Quoted 11 lines
ui/gtk.c +4 -1
+            GClosure *cb_fullscreen = g_cclosure_new_swap(
+                                             G_CALLBACK(gd_win_fullscreen),
+                                             vc, NULL);
+            gtk_accel_group_connect(ag, GDK_KEY_f, HOTKEY_MODIFIERS, 0, cb_fullscreen);
         }
 
         gd_rebuild_vc_menu(s);
--

2.43.0

Signature · 1 line
Marc-André Lureau
#2 lore raw

Re: [PATCH 2/2] ui/gtk: register "Grab Input" shortcut to accel_group

In reply to [email protected]

Hi

Quoted 22 lines · On Mon, Sep 14, 2026 at 10:51 PM <[email protected]> wrote:

From: Dongwon Kim <[email protected]>

The "Grab Input" shortcut key currently fails to trigger when the window is in fullscreen mode because the menubar is hidden, which disables GtkAccelMap-based shortcuts associated with it.

To ensure the accelerator remains active in fullscreen, connect it directly to s->accel_group and explicitly set the hotkey display on the menu item label.

Cc Marc-André Lureau <[email protected]>
---
 ui/gtk.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
ui/gtk.c +0 -0
index 3c9720a330..2f83c557d8 100644

ui/gtk.c static void gd_menu_grab_input(GtkMenuItem *item, void *opaque) · line 1882

Quoted 5 lines
ui/gtk.c +2 -0
@@ -1878,6 +1878,12 @@ static void gd_menu_grab_input(GtkMenuItem *item, void *opaque)
     gd_update_cursor(vc);
 }
 
+static void gd_accel_grab_input(void *opaque)
+{

https://docs.gtk.org/gtk3/method.AccelGroup.connect.html
The signature used for the closure is that of GtkAccelGroupActivate.

This means that other key events could potentially be triggered. It should return true (handled).

Quoted 37 lines
ui/gtk.c +13 -6
+    GtkDisplayState *s = opaque;
+    gtk_menu_item_activate(GTK_MENU_ITEM(s->grab_item));
+}
+
 static void gd_change_page(GtkNotebook *nb, gpointer arg1, guint arg2,
                            gpointer data)
 {
@@ -2557,6 +2563,7 @@ static void gd_create_menu_view(GtkDisplayState *s, DisplayOptions *opts)
 {
     GtkWidget *view_menu;
     GtkWidget *separator;
+    GtkWidget *child;
     QemuConsole *con;
     bool zoom_to_fit = false;
     int vc, i;
@@ -2615,12 +2622,15 @@ static void gd_create_menu_view(GtkDisplayState *s, DisplayOptions *opts)
     gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_on_hover_item);
 
     s->grab_item = gtk_check_menu_item_new_with_mnemonic(_("_Grab Input"));
-    gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->grab_item),
-                                 "<QEMU>/View/Grab Input");
-    gtk_accel_map_add_entry("<QEMU>/View/Grab Input", GDK_KEY_g,
-                            HOTKEY_MODIFIERS);
     gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_item);
-
+    gtk_accel_group_connect(s->accel_group, GDK_KEY_g, HOTKEY_MODIFIERS, 0,
+                            g_cclosure_new_swap(G_CALLBACK(gd_accel_grab_input),
+                                                s, NULL));
+    child = gtk_bin_get_child(GTK_BIN(s->grab_item));
+    if (GTK_IS_ACCEL_LABEL(child)) {
+        gtk_accel_label_set_accel(GTK_ACCEL_LABEL(child),
+                                  GDK_KEY_g, HOTKEY_MODIFIERS);
+    }
     separator = gtk_separator_menu_item_new();
     gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
 
--
Quoted 3 lines

2.43.0

--
Marc-André Lureau

#5 lore raw
In reply to Marc-André Lureau

Hi Marc-André,

Quoted 51 lines

Subject: Re: [PATCH 1/2] ui/gtk: enable fullscreen hotkey for detached windows

Hi

Quoted 45 lines · On Mon, Sep 14, 2026 at 10:50 PM <[email protected]> wrote:

From: Dongwon Kim <[email protected]>

Currently, the fullscreen toggle hotkey (Ctrl+Alt+f by default) only functions for the main QEMU window. When a Virtual Console (VC) is detached into its own separate window (untabified), it loses this capability.

Implement a toggle helper, gd_win_fullscreen, and connect it to the 'f' accelerator when a detached window is created in gd_menu_untabify. This allows individual detached windows to be toggled fullscreen independently.

Cc Marc-André Lureau <[email protected]>
---
 ui/gtk.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)
ui/gtk.c +18 -0
index a723c8215d..3c9720a330 100644
@@ -1556,6 +1556,42 @@ static gboolean gd_win_grab(void *opaque)
     return TRUE;
 }
 
+static void gd_win_fullscreen(void *opaque) {
+    VirtualConsole *vc = opaque;
+    GtkDisplayState *s = vc->s;
+    GdkWindow *window;
+    GdkWindowState state;
+
+    if (!vc->window || !gtk_widget_get_realized(vc->window)) {
+        return;
+    }
+
+    window = gtk_widget_get_window(vc->window);
+    if (!window) {
+        return;
+    }
+
+    state = gdk_window_get_state(window);
+
+    if (state & GDK_WINDOW_STATE_FULLSCREEN) {
Quoted 8 lines

ui/gtk.c static gboolean gd_win_grab(void *opaque) · line 1583

Quoted 6 lines
ui/gtk.c +6 -0
+        gtk_window_unfullscreen(GTK_WINDOW(vc->window));
+
+        if (vc->type == GD_VC_GFX) {
+            if (!s->free_scale) {
+                vc->gfx.scale_x = 1.0;
+                vc->gfx.scale_y = 1.0;

gd_menu_full_screen restores it to gfx.preferred_scale

I will change this. This was based on what was done in menu_full_screen a while ago. I didn't notice it was changed there. In addition to that, I will take out check on free_scale as well.

Quoted 12 lines

ui/gtk.c static gboolean gd_win_grab(void *opaque) · line 1593

Quoted 11 lines
ui/gtk.c +10 -0
+            }
+            gd_update_windowsize(vc);
+        }
+    } else {
+        if (vc->type == GD_VC_GFX) {
+            gtk_widget_set_size_request(vc->gfx.drawing_area, -1, -1);
+        }
+        gtk_window_fullscreen(GTK_WINDOW(vc->window));
+    }
+}
Quoted 1 line

For consistency with gd_menu_full_screen() it should call gd_update_cursor

Yes

Quoted 14 lines

ui/gtk.c static void gd_menu_untabify(GtkMenuItem

Quoted 5 lines
ui/gtk.c +1 -0
+
 static void gd_menu_untabify(GtkMenuItem *item, void *opaque)  {
     GtkDisplayState *s = opaque;
@@ -1590,9 +1626,13 @@ static void gd_menu_untabify(GtkMenuItem

*item, void *opaque)

ui/gtk.c static void gd_menu_untabify(GtkMenuItem *item, void *opaque)

Quoted 6 lines
ui/gtk.c +0 -3
             GtkAccelGroup *ag = gtk_accel_group_new();
             gtk_window_add_accel_group(GTK_WINDOW(vc->window), ag);
 
-            GClosure *cb = g_cclosure_new_swap(G_CALLBACK(gd_win_grab),
-                                               vc, NULL);
-            gtk_accel_group_connect(ag, GDK_KEY_g, HOTKEY_MODIFIERS, 0,

cb);

ui/gtk.c static void gd_menu_untabify(GtkMenuItem · line 1629

Quoted 1 line
ui/gtk.c +1 -0
+            GClosure *cb_grab =
Quoted 8 lines

g_cclosure_new_swap(G_CALLBACK(gd_win_grab),

ui/gtk.c static void gd_menu_untabify(GtkMenuItem · line 1632

Quoted 3 lines
ui/gtk.c +3 -0
+                                                    vc, NULL);
+            gtk_accel_group_connect(ag, GDK_KEY_g, HOTKEY_MODIFIERS,
+ 0, cb_grab);

You also hook grab, this should be mentionned in the commit message.

btw, it would be nice to remove the stderr printf there..

Yes, I will remove it.

Quoted 2 lines

Why not add the zoom keys while at it?

Yes, we can enable other hotkeys. I am going to add zoom in/out/reset keys. I think it's better to create a new commit with all these major changes included rather than going with v2.

Thanks,
DW

Quoted 19 lines

thanks

Quoted 9 lines
ui/gtk.c +5 -1
+            GClosure *cb_fullscreen = g_cclosure_new_swap(
+                                             G_CALLBACK(gd_win_fullscreen),
+                                             vc, NULL);
+            gtk_accel_group_connect(ag, GDK_KEY_f, HOTKEY_MODIFIERS,
+ 0, cb_fullscreen);
         }
 
         gd_rebuild_vc_menu(s);
--
Quoted 3 lines

2.43.0

--
Marc-André Lureau

#3 lore raw

RE: [PATCH 2/2] ui/gtk: register "Grab Input" shortcut to accel_group

In reply to Marc-André Lureau

Hi Marc-André,

Quoted 31 lines

Subject: Re: [PATCH 2/2] ui/gtk: register "Grab Input" shortcut to accel_group

Hi

ui/gtk.c static void gd_menu_grab_input(GtkMenuItem

Quoted 22 lines · On Mon, Sep 14, 2026 at 10:51 PM <[email protected]> wrote:

From: Dongwon Kim <[email protected]>

The "Grab Input" shortcut key currently fails to trigger when the window is in fullscreen mode because the menubar is hidden, which disables GtkAccelMap-based shortcuts associated with it.

To ensure the accelerator remains active in fullscreen, connect it directly to s->accel_group and explicitly set the hotkey display on the menu item label.

Cc Marc-André Lureau <[email protected]>
---
 ui/gtk.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
ui/gtk.c +0 -0
index 3c9720a330..2f83c557d8 100644
@@ -1878,6 +1878,12 @@ static void gd_menu_grab_input(GtkMenuItem

*item, void *opaque)

Quoted 3 lines
ui/gtk.c +0 -0
     gd_update_cursor(vc);
 }
 
Quoted 7 lines

ui/gtk.c static void gd_menu_grab_input(GtkMenuItem · line 1881

Quoted 1 line
ui/gtk.c +1 -0
+static void gd_accel_grab_input(void *opaque) {

https://docs.gtk.org/gtk3/method.AccelGroup.connect.html
The signature used for the closure is that of GtkAccelGroupActivate.

This means that other key events could potentially be triggered. It should return true (handled).

Yeah This will be updated in v2.

Thanks,
DW

Quoted 49 lines

ui/gtk.c static void

Quoted 17 lines
ui/gtk.c +4 -0
+    GtkDisplayState *s = opaque;
+    gtk_menu_item_activate(GTK_MENU_ITEM(s->grab_item));
+}
+
 static void gd_change_page(GtkNotebook *nb, gpointer arg1, guint arg2,
                            gpointer data)  { @@ -2557,6 +2563,7 @@

static void gd_create_menu_view(GtkDisplayState *s, DisplayOptions

*opts)  {
     GtkWidget *view_menu;
     GtkWidget *separator;
ui/gtk.c +1 -0
+    GtkWidget *child;
     QemuConsole *con;
     bool zoom_to_fit = false;
     int vc, i;
@@ -2615,12 +2622,15 @@ static void

gd_create_menu_view(GtkDisplayState *s, DisplayOptions *opts)

ui/gtk.c static void · line 2625

Quoted 4 lines
ui/gtk.c +0 -0
     gtk_menu_shell_append(GTK_MENU_SHELL(view_menu),
 s->grab_on_hover_item);
 
     s->grab_item = gtk_check_menu_item_new_with_mnemonic(_("_Grab

Input"));

ui/gtk.c static void gd_create_menu_view(GtkDisplayState *s, DisplayOptions *opts)

Quoted 7 lines
ui/gtk.c +1 -5
-    gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->grab_item),
-                                 "<QEMU>/View/Grab Input");
-    gtk_accel_map_add_entry("<QEMU>/View/Grab Input", GDK_KEY_g,
-                            HOTKEY_MODIFIERS);
     gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_item);
-
+    gtk_accel_group_connect(s->accel_group, GDK_KEY_g,

HOTKEY_MODIFIERS, 0,

Quoted 11 lines
ui/gtk.c +7 -1
+                            g_cclosure_new_swap(G_CALLBACK(gd_accel_grab_input),
+                                                s, NULL));
+    child = gtk_bin_get_child(GTK_BIN(s->grab_item));
+    if (GTK_IS_ACCEL_LABEL(child)) {
+        gtk_accel_label_set_accel(GTK_ACCEL_LABEL(child),
+                                  GDK_KEY_g, HOTKEY_MODIFIERS);
+    }
     separator = gtk_separator_menu_item_new();
     gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
 
--
Quoted 3 lines

2.43.0

--
Marc-André Lureau