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]>
Signed-off-by: Dongwon Kim <[email protected]>
---
 ui/gtk.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index f20edc5c5b..cace30114e 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -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) {
-- 
2.43.0


Reply via email to