diff mbox series

UI/GTK: full-screen after wait for hiding of tabs and menu_bar

Message ID a3f5c533b761756e90e80cc616e2e9dff3aefa4a.camel@proton.me (mailing list archive)
State New
Headers show
Series UI/GTK: full-screen after wait for hiding of tabs and menu_bar | expand

Commit Message

Edmund Raile Nov. 2, 2024, 4:04 a.m. UTC
Wait for hiding of GTK notebook tabs and GTK menu_bar before entering
full-screen due to asynchronous nature of GTK.

prevent:
 * full-screen window overlap onto monitor below
 * black bar on top of full-screen guest display
 * misallignment of host-drawn guest cursor and invisible guest cursor

Signed-off-by: Edmund Raile <edmund.raile@proton.me>
---
I'd like to report an issue with GTK UI and suggest a solution for it.
When entering full-screen, the tabs and menu_bar need to be hidden.

Currently, gd_menu_full_screen() does all of this in-line but since
GTK operates asynchronously, this results in:
 * a full-screen window that overlaps onto the monitor below
 * a full-screen guest display that has a black bar above it
 * a guest cursor that is misalligned to the
   host cursor the GTK UI draws in-style of the guest cursor (QXL vga)

My solution is to wait for GTK to hide tabs and menu_bar,
and only then enter full screen.
I've implemented this with a callback on a simple 10ms timer.

It has been tested to work reliably under heavy CPU load, when
GTK may take longer to respond to requests.

Since gtk.c currently has no maintainer, I am uncertain who to submit
this patch to.

Kind regards,
Edmund Raile.
 ui/gtk.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

         gd_menu_show_tabs(GTK_MENU_ITEM(s->show_tabs_item), s);

Comments

Marc-André Lureau Nov. 4, 2024, 7:44 a.m. UTC | #1
Hi

On Sat, Nov 2, 2024 at 8:05 AM Edmund Raile via <qemu-devel@nongnu.org>
wrote:

> Wait for hiding of GTK notebook tabs and GTK menu_bar before entering
> full-screen due to asynchronous nature of GTK.
>
> prevent:
>  * full-screen window overlap onto monitor below
>  * black bar on top of full-screen guest display
>  * misallignment of host-drawn guest cursor and invisible guest cursor
>
> Signed-off-by: Edmund Raile <edmund.raile@proton.me>
> ---
> I'd like to report an issue with GTK UI and suggest a solution for it.
> When entering full-screen, the tabs and menu_bar need to be hidden.
>
> Currently, gd_menu_full_screen() does all of this in-line but since
> GTK operates asynchronously, this results in:
>  * a full-screen window that overlaps onto the monitor below
>  * a full-screen guest display that has a black bar above it
>  * a guest cursor that is misalligned to the
>    host cursor the GTK UI draws in-style of the guest cursor (QXL vga)
>
> My solution is to wait for GTK to hide tabs and menu_bar,
> and only then enter full screen.
> I've implemented this with a callback on a simple 10ms timer.
>
> It has been tested to work reliably under heavy CPU load, when
> GTK may take longer to respond to requests.
>
> Since gtk.c currently has no maintainer, I am uncertain who to submit
> this patch to.
>
> Kind regards,
> Edmund Raile.
>  ui/gtk.c | 33 +++++++++++++++++++++++++++++++--
>  1 file changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/ui/gtk.c b/ui/gtk.c
> index bf9d3dd679..2f6aac6386 100644
> --- a/ui/gtk.c
> +++ b/ui/gtk.c
> @@ -1463,6 +1463,32 @@ static void gd_accel_show_menubar(void *opaque)
>      gtk_menu_item_activate(GTK_MENU_ITEM(s->show_menubar_item));
>  }
>
> +static gboolean full_screen_enter_callback(gpointer user_data)
> +{
> +    GtkDisplayState *s = user_data;
> +    VirtualConsole *vc = gd_vc_find_current(s);
> +
> +    gboolean tabs_visible = gtk_notebook_get_show_tabs(
> +                                GTK_NOTEBOOK(s->notebook));
> +    gboolean menu_bar_visible = gtk_widget_get_visible(s->menu_bar);
> +
> +    if (!tabs_visible && !menu_bar_visible) {
> +        gtk_window_fullscreen(GTK_WINDOW(s->window));
> +        s->full_screen = TRUE;
> +
> +        gd_update_windowsize(vc);
> +
> +        /** deactivate callback **/
> +        return FALSE;
> +    } else {
> +        /*
> +         * re-schedule callback if GTK _still_
> +         * did not manage to hide tabs and menu_bar
> +         */
> +        return TRUE;
> +    }
> +}
> +
>  static void gd_menu_full_screen(GtkMenuItem *item, void *opaque)
>  {
>      GtkDisplayState *s = opaque;
> @@ -1474,8 +1500,11 @@ static void gd_menu_full_screen(GtkMenuItem
> *item, void *opaque)
>          if (vc->type == GD_VC_GFX) {
>              gtk_widget_set_size_request(vc->gfx.drawing_area, -1, -1);
>          }
> -        gtk_window_fullscreen(GTK_WINDOW(s->window));
> -        s->full_screen = TRUE;
> +
> +        gd_update_windowsize(vc);
> +
> +        /** give GTK 10ms to perform the resize **/
> +        g_timeout_add(10, full_screen_enter_callback, s);
>

This is odd. Is there a related Gtk3 issue reported upstream?


>      } else {
>          gtk_window_unfullscreen(GTK_WINDOW(s->window));
>          gd_menu_show_tabs(GTK_MENU_ITEM(s->show_tabs_item), s);
> --
> 2.47.0
>
>
>
>
>
diff mbox series

Patch

diff --git a/ui/gtk.c b/ui/gtk.c
index bf9d3dd679..2f6aac6386 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1463,6 +1463,32 @@  static void gd_accel_show_menubar(void *opaque)
     gtk_menu_item_activate(GTK_MENU_ITEM(s->show_menubar_item));
 }
 
+static gboolean full_screen_enter_callback(gpointer user_data)
+{
+    GtkDisplayState *s = user_data;
+    VirtualConsole *vc = gd_vc_find_current(s);
+
+    gboolean tabs_visible = gtk_notebook_get_show_tabs(
+                                GTK_NOTEBOOK(s->notebook));
+    gboolean menu_bar_visible = gtk_widget_get_visible(s->menu_bar);
+
+    if (!tabs_visible && !menu_bar_visible) {
+        gtk_window_fullscreen(GTK_WINDOW(s->window));
+        s->full_screen = TRUE;
+
+        gd_update_windowsize(vc);
+
+        /** deactivate callback **/
+        return FALSE;
+    } else {
+        /*
+         * re-schedule callback if GTK _still_
+         * did not manage to hide tabs and menu_bar
+         */
+        return TRUE;
+    }
+}
+
 static void gd_menu_full_screen(GtkMenuItem *item, void *opaque)
 {
     GtkDisplayState *s = opaque;
@@ -1474,8 +1500,11 @@  static void gd_menu_full_screen(GtkMenuItem
*item, void *opaque)
         if (vc->type == GD_VC_GFX) {
             gtk_widget_set_size_request(vc->gfx.drawing_area, -1, -1);
         }
-        gtk_window_fullscreen(GTK_WINDOW(s->window));
-        s->full_screen = TRUE;
+
+        gd_update_windowsize(vc);
+
+        /** give GTK 10ms to perform the resize **/
+        g_timeout_add(10, full_screen_enter_callback, s);
     } else {
         gtk_window_unfullscreen(GTK_WINDOW(s->window));