Skip to contentSkip to conversation

ui/gtk: Hotkey and fullscreen handling fixes

PATCH Superseded [email protected] 2 participants 6 messages Sep 21 – Oct 13

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover ui/gtk: Hotkey and fullscreen handling fixes

From: Dongwon Kim <[email protected]>

This series resolves several issues regarding keyboard shortcuts and fullscreen behavior in the QEMU GTK UI.

1. Detached (untabified) windows properly support fullscreen and zoom accelerators.
2. The "Grab Input" accelerator remains functional in fullscreen mode when the menubar is hidden.
3. Initial fullscreen setup is deferred until the window is properly realized to avoid display configuration race conditions.

v2:
- Return TRUE in accelerator callbacks (gd_accel_grab_input, gd_win_*) to comply with the GtkAccelGroupActivate prototype.
- Restore scale to preferred_scale and trigger gd_update_cursor() on fullscreen exit.
- Deduplicate zoom handling by sharing gd_win_zoom_* across menu actions.
- Guard zoom helpers against NULL / non-GFX consoles.
- Remove leftover debug fprintf in gd_win_grab.

Dongwon Kim (3):
ui/gtk: Enable fullscreen and zoom hotkeys for detached windows ui/gtk: Register "Grab Input" shortcut to accel_group ui/gtk: Defer initial fullscreen activation until window is mapped

 ui/gtk.c | 188 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 146 insertions(+), 42 deletions(-)
Signature · 1 line
2.43.0
#3 lore raw

PATCH v2 3/3 ui/gtk: Defer initial fullscreen activation until window is mapped

From: Dongwon Kim <[email protected]>

When QEMU is started with '-display gtk,full-screen=on', the fullscreen state is currently requested in gtk_display_init() before the window is realized or mapped by the display server.

On certain compositors (such as GNOME/Mutter under Wayland or X11), requesting fullscreen on an unmapped window can be overridden or dropped when the window is subsequently mapped and assigned its initial windowed geometry constraints.

Resolve this by deferring the initial fullscreen toggle until the window's "map-event" signal fires. Once the native surface is fully mapped and acknowledged by the compositor, activate the fullscreen action and disconnect the one-shot handler.

Cc Marc-André Lureau <[email protected]>
---
 ui/gtk.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
ui/gtk.c +18 -1
index f20edc5c5b..cace30114e 100644
@@ -2861,6 +2861,22 @@ static void gd_vc_free(void *p)
 static GtkDisplayState *gtk_display_state;
 static gboolean gtkinit;
 
+static gboolean gd_window_map_event(GtkWidget *widget, GdkEvent *event, gpointer opaque)
+{
+    GtkDisplayState *s = opaque;
+
+    if (s->opts->has_full_screen &&
+        s->opts->full_screen) {
+        if (!s->full_screen) {
+            gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item));
+        }
+    }
+
+    /* Disconnect or ensure it runs only once at launch */
+    g_signal_handlers_disconnect_by_func(widget, gd_window_map_event, s);
+    return FALSE;
+}
+
 static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
 {
     VirtualConsole *vc;
@@ -2960,7 +2976,8 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
 
     if (opts->has_full_screen &&
         opts->full_screen) {
-        gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item));
+        g_signal_connect(s->window, "map-event",
+                         G_CALLBACK(gd_window_map_event), s);
     }
     if (opts->u.gtk.has_grab_on_hover &&
         opts->u.gtk.grab_on_hover) {
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/3 ui/gtk: Enable fullscreen and zoom hotkeys for detached windows

In reply to [email protected]

From: Dongwon Kim <[email protected]>

Currently, the fullscreen toggle hotkey (Ctrl+Alt+f by default) and zoom hotkeys (Ctrl+Alt++, Ctrl+Alt+-, Ctrl+Alt+0) only function for the main QEMU window. When a VC is detached (untabified), it loses these capabilities.

Implement toggle helpers, gd_win_full_screen and zoom helpers (gd_win_zoom_in, gd_win_zoom_out, gd_win_zoom_fixed) and connect them to the detached window's accelerator group in gd_menu_untabify.

Also remove a leftover debug fprintf in gd_win_grab.

v2:
- Reuse gd_win_zoom_* in gd_menu_zoom_* to avoid duplicated scaling logic
- Guard zoom helpers against NULL or non-GFX consoles
(!vc || vc->type != GD_VC_GFX)
- Keep both GDK_KEY_plus and GDK_KEY_equal accelerators

Cc Marc-André Lureau <[email protected]>
---
 ui/gtk.c | 148 +++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 111 insertions(+), 37 deletions(-)
ui/gtk.c +111 -37
index ed7ffc06b1..5427c2f174 100644
@@ -1562,7 +1562,6 @@ static gboolean gd_win_grab(void *opaque)
 {
     VirtualConsole *vc = opaque;
 
-    fprintf(stderr, "%s: %s\n", __func__, vc->label);
     if (vc->s->ptr_owner) {
         gd_ungrab_pointer(vc->s);
     } else {
@@ -1571,6 +1570,96 @@ static gboolean gd_win_grab(void *opaque)
     return TRUE;
 }
 
+static gboolean gd_win_full_screen(void *opaque)
+{
+    VirtualConsole *vc = opaque;
+    GdkWindow *window;
+    GdkWindowState state;
+
+    if (!vc || !vc->window || !gtk_widget_get_realized(vc->window)) {
+        return TRUE;
+    }
+
+    window = gtk_widget_get_window(vc->window);
+    if (!window) {
+        return TRUE;
+    }
+
+    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) {
+            vc->gfx.scale_x = vc->gfx.preferred_scale;
+            vc->gfx.scale_y = vc->gfx.preferred_scale;
+            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));
+    }
+
+    gd_update_cursor(vc);
+    return TRUE;
+}
+
+static gboolean gd_win_zoom_in(void *opaque)
+{
+    VirtualConsole *vc = opaque;
+
+    if (!vc || vc->type != GD_VC_GFX) {
+        return TRUE;
+    }
+
+    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc->s->zoom_fit_item),
+                                   FALSE);
+
+    vc->gfx.scale_x += VC_SCALE_STEP;
+    vc->gfx.scale_y += VC_SCALE_STEP;
+
+    gd_update_windowsize(vc);
+    return TRUE;
+}
+
+static gboolean gd_win_zoom_out(void *opaque)
+{
+    VirtualConsole *vc = opaque;
+
+    if (!vc || vc->type != GD_VC_GFX) {
+        return TRUE;
+    }
+
+    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc->s->zoom_fit_item),
+                                   FALSE);
+
+    vc->gfx.scale_x -= VC_SCALE_STEP;
+    vc->gfx.scale_y -= VC_SCALE_STEP;
+
+    vc->gfx.scale_x = MAX(vc->gfx.scale_x, VC_SCALE_MIN);
+    vc->gfx.scale_y = MAX(vc->gfx.scale_y, VC_SCALE_MIN);
+
+    gd_update_windowsize(vc);
+    return TRUE;
+}
+
+static gboolean gd_win_zoom_fixed(void *opaque)
+{
+    VirtualConsole *vc = opaque;
+
+    if (!vc || vc->type != GD_VC_GFX) {
+        return TRUE;
+    }
+
+    vc->gfx.scale_x = vc->gfx.preferred_scale;
+    vc->gfx.scale_y = vc->gfx.preferred_scale;
+
+    gd_update_windowsize(vc);
+    return TRUE;
+}
+
 static void gd_menu_untabify(GtkMenuItem *item, void *opaque)
 {
     GtkDisplayState *s = opaque;
@@ -1609,9 +1698,24 @@ 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);
+            gtk_accel_group_connect(ag, GDK_KEY_g, HOTKEY_MODIFIERS, 0,
+                    g_cclosure_new_swap(G_CALLBACK(gd_win_grab),
+                                        vc, NULL));
+            gtk_accel_group_connect(ag, GDK_KEY_f, HOTKEY_MODIFIERS, 0,
+                    g_cclosure_new_swap(G_CALLBACK(gd_win_full_screen),
+                                        vc, NULL));
+            gtk_accel_group_connect(ag, GDK_KEY_plus, HOTKEY_MODIFIERS, 0,
+                    g_cclosure_new_swap(G_CALLBACK(gd_win_zoom_in),
+                                        vc, NULL));
+            gtk_accel_group_connect(ag, GDK_KEY_equal, HOTKEY_MODIFIERS, 0,
+                    g_cclosure_new_swap(G_CALLBACK(gd_win_zoom_in),
+                                        vc, NULL));
+            gtk_accel_group_connect(ag, GDK_KEY_minus, HOTKEY_MODIFIERS, 0,
+                    g_cclosure_new_swap(G_CALLBACK(gd_win_zoom_out),
+                                        vc, NULL));
+            gtk_accel_group_connect(ag, GDK_KEY_0, HOTKEY_MODIFIERS, 0,
+                    g_cclosure_new_swap(G_CALLBACK(gd_win_zoom_fixed),
+                                        vc, NULL));
         }
 
         gd_rebuild_vc_menu(s);
@@ -1691,17 +1795,7 @@ static void gd_menu_zoom_in(GtkMenuItem *item, void *opaque)
     GtkDisplayState *s = opaque;
     VirtualConsole *vc = gd_vc_find_current(s);
 
-    if (!vc) {
-        return;
-    }
-
-    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->zoom_fit_item),
-                                   FALSE);
-
-    vc->gfx.scale_x += VC_SCALE_STEP;
-    vc->gfx.scale_y += VC_SCALE_STEP;
-
-    gd_update_windowsize(vc);
+    gd_win_zoom_in(vc);
 }
 
 static void gd_accel_zoom_in(void *opaque)
@@ -1715,20 +1809,7 @@ static void gd_menu_zoom_out(GtkMenuItem *item, void *opaque)
     GtkDisplayState *s = opaque;
     VirtualConsole *vc = gd_vc_find_current(s);
 
-    if (!vc) {
-        return;
-    }
-
-    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->zoom_fit_item),
-                                   FALSE);
-
-    vc->gfx.scale_x -= VC_SCALE_STEP;
-    vc->gfx.scale_y -= VC_SCALE_STEP;
-
-    vc->gfx.scale_x = MAX(vc->gfx.scale_x, VC_SCALE_MIN);
-    vc->gfx.scale_y = MAX(vc->gfx.scale_y, VC_SCALE_MIN);
-
-    gd_update_windowsize(vc);
+    gd_win_zoom_out(vc);
 }
 
 static void gd_menu_zoom_fixed(GtkMenuItem *item, void *opaque)
@@ -1736,14 +1817,7 @@ static void gd_menu_zoom_fixed(GtkMenuItem *item, void *opaque)
     GtkDisplayState *s = opaque;
     VirtualConsole *vc = gd_vc_find_current(s);
 
-    if (!vc) {
-        return;
-    }
-
-    vc->gfx.scale_x = vc->gfx.preferred_scale;
-    vc->gfx.scale_y = vc->gfx.preferred_scale;
-
-    gd_update_windowsize(vc);
+    gd_win_zoom_fixed(vc);
 }
 
 static void gd_menu_zoom_fit(GtkMenuItem *item, void *opaque)
Signature · 1 line
2.43.0
#2 lore raw

PATCH v2 2/3 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.

v2: gd_accel_grab_input returns TRUE

Cc Marc-André Lureau <[email protected]>
---
 ui/gtk.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
ui/gtk.c +17 -4
index 5427c2f174..f20edc5c5b 100644
@@ -1959,6 +1959,14 @@ static void gd_menu_grab_input(GtkMenuItem *item, void *opaque)
     }
 }
 
+static gboolean gd_accel_grab_input(void *opaque)
+{
+    GtkDisplayState *s = opaque;
+
+    gtk_menu_item_activate(GTK_MENU_ITEM(s->grab_item));
+    return TRUE;
+}
+
 static void gd_change_page(GtkNotebook *nb, gpointer arg1, guint arg2,
                            gpointer data)
 {
@@ -2643,6 +2651,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;
@@ -2701,12 +2710,16 @@ 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
#4 lore raw
In reply to [email protected]

Hi Marc-André,

Quoted 35 lines

-----Original Message-----
From: [email protected] <qemu- [email protected]> On Behalf Of [email protected]
Sent: Tuesday, August 11, 2026 3:24 AM
To: [email protected]
Subject: [PATCH v2 0/3] ui/gtk: Hotkey and fullscreen handling fixes

From: Dongwon Kim <[email protected]>

This series resolves several issues regarding keyboard shortcuts and fullscreen behavior in the QEMU GTK UI.

1. Detached (untabified) windows properly support fullscreen and zoom accelerators.
2. The "Grab Input" accelerator remains functional in fullscreen mode when the menubar is hidden.
3. Initial fullscreen setup is deferred until the window is properly realized to avoid display configuration race conditions.

v2:
- Return TRUE in accelerator callbacks (gd_accel_grab_input, gd_win_*) to comply with the GtkAccelGroupActivate prototype.
- Restore scale to preferred_scale and trigger gd_update_cursor() on fullscreen exit.
- Deduplicate zoom handling by sharing gd_win_zoom_* across menu
actions.
- Guard zoom helpers against NULL / non-GFX consoles.
- Remove leftover debug fprintf in gd_win_grab.

Dongwon Kim (3):
ui/gtk: Enable fullscreen and zoom hotkeys for detached windows ui/gtk: Register "Grab Input" shortcut to accel_group ui/gtk: Defer initial fullscreen activation until window is mapped

Quoted 6 lines
 ui/gtk.c | 188 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 146 insertions(+), 42 deletions(-)

--
2.43.0

Friendly ping on this series when you get a chance.

Thanks!
DW

#5 lore raw

Hi

Quoted 38 lines · Dongwon

Hi Marc-André,

Quoted 35 lines

-----Original Message-----
From: [email protected] <qemu- [email protected]> On Behalf Of [email protected]
Sent: Tuesday, August 11, 2026 3:24 AM
To: [email protected]
Subject: [PATCH v2 0/3] ui/gtk: Hotkey and fullscreen handling fixes

From: Dongwon Kim <[email protected]>

This series resolves several issues regarding keyboard shortcuts and fullscreen behavior in the QEMU GTK UI.

1. Detached (untabified) windows properly support fullscreen and zoom accelerators.
2. The "Grab Input" accelerator remains functional in fullscreen mode when the menubar is hidden.
3. Initial fullscreen setup is deferred until the window is properly realized to avoid display configuration race conditions.

v2:
- Return TRUE in accelerator callbacks (gd_accel_grab_input, gd_win_*) to comply with the GtkAccelGroupActivate prototype.
- Restore scale to preferred_scale and trigger gd_update_cursor() on fullscreen exit.
- Deduplicate zoom handling by sharing gd_win_zoom_* across menu
actions.
- Guard zoom helpers against NULL / non-GFX consoles.
- Remove leftover debug fprintf in gd_win_grab.

Dongwon Kim (3):
ui/gtk: Enable fullscreen and zoom hotkeys for detached windows ui/gtk: Register "Grab Input" shortcut to accel_group ui/gtk: Defer initial fullscreen activation until window is mapped

Quoted 8 lines
Quoted 6 lines
 ui/gtk.c | 188 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 146 insertions(+), 42 deletions(-)

--
2.43.0

Friendly ping on this series when you get a chance.

Sorry for the late reply, for some reason I didn't receive the series.

It would need a helper gd_is_fullscreen() because 5 functions still only check s->full_screen. Please introduce a preliminary helper for it

Second patch looks good.

thanks