Skip to contentSkip to conversation

ui/gtk: Hotkey and fullscreen handling fixes

PATCH In review Dongwon Kim 1 participant 6 messages Oct 26 – Dec 2

lore
Share & tools
lore
#0 lore raw

v4 cover ui/gtk: Hotkey and fullscreen handling fixes

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.

v3:
- Add gd_is_full_screen() to query GdkWindowState directly and replace s->full_screen checks across attached and detached consoles
- Keep zoom_fit_item deactivation in gd_menu_zoom_* while keeping gd_win_zoom_* focused on per-VC scaling
- Restrict global free_scale handling to attached consoles so detached window geometry is not overridden
- Use gd_is_full_screen for full_screen check in gd_window_map_event

v4: Resend full series with consistent patch versioning tags

---
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

 include/ui/gtk.h |   2 -
 ui/gtk.c         | 223 ++++++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 170 insertions(+), 55 deletions(-)

---
base-commit: d73149283205645625bfa9fe029cfb68e4c4a9ae
change-id: 20261025-gtk-ui-v4-0fc328996f18

Best regards,

Signature · 1 line
Dongwon Kim <[email protected]>
#1 lore raw

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

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

v3:
- Add gd_is_full_screen() to query GdkWindowState directly and replace s->full_screen checks across attached and detached consoles
- Keep zoom_fit_item deactivation in gd_menu_zoom_* while keeping gd_win_zoom_* focused on per-VC scaling
- Restrict global free_scale handling to attached consoles so detached window geometry is not overridden

Cc Marc-André Lureau <[email protected]>
---
 include/ui/gtk.h |   2 -
 ui/gtk.c         | 183 ++++++++++++++++++++++++++++++++++++++++---------------
 2 files changed, 135 insertions(+), 50 deletions(-)
include/ui/gtk.h +0 -2
index 6b62e97588..d2ccbd2c0d 100644
@@ -138,8 +138,6 @@ struct GtkDisplayState {
     VirtualConsole *kbd_owner;
     VirtualConsole *ptr_owner;
 
-    gboolean full_screen;
-
     GdkCursor *null_cursor;
     Notifier mouse_mode_notifier;
     VMChangeStateEntry *vmse;
ui/gtk.c +135 -48

287 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

PATCH v4 2/3 ui/gtk: Register "Grab Input" shortcut to accel_group

In reply to Dongwon Kim

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 724ede5633..10db77414a 100644
@@ -1971,6 +1971,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)
 {
@@ -2684,6 +2692,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;
@@ -2742,12 +2751,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.34.1
#3 lore raw

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

In reply to Dongwon Kim

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.

v2: Use gd_is_full_screen for full_screen check in gd_window_map_event

Cc Marc-André Lureau <[email protected]>
---
 ui/gtk.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
ui/gtk.c +18 -1
index 10db77414a..ff9d17015c 100644
@@ -2902,6 +2902,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 (!gd_is_full_screen(widget)) {
+            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;
@@ -3001,7 +3017,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.34.1
#4 lore raw
In reply to Dongwon Kim

Hi Marc-André,

Just a friendly ping on this series whenever you get a chance to take a look.

Thanks!
DW

Quoted 61 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Dongwon Kim
Sent: Sunday, October 25, 2026 9:05 PM
To: [email protected]
Cc: Marc-André Lureau <[email protected]>; Dongwon Kim <[email protected]>
Subject: [PATCH v4 0/3] ui/gtk: Hotkey and fullscreen handling fixes

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.

v3:
- Add gd_is_full_screen() to query GdkWindowState directly and replace s->full_screen checks across attached and detached consoles
- Keep zoom_fit_item deactivation in gd_menu_zoom_* while keeping gd_win_zoom_* focused on per-VC scaling
- Restrict global free_scale handling to attached consoles so detached window geometry is not overridden
- Use gd_is_full_screen for full_screen check in gd_window_map_event

v4: Resend full series with consistent patch versioning tags

---
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

 include/ui/gtk.h |   2 -
 ui/gtk.c         | 223 ++++++++++++++++++++++++++++++++++++++++++----------
---
 2 files changed, 170 insertions(+), 55 deletions(-)

---
base-commit: d73149283205645625bfa9fe029cfb68e4c4a9ae
change-id: 20261025-gtk-ui-v4-0fc328996f18

Best regards,
--
Dongwon Kim <[email protected]>