[PATCH] ui/gtk: Fix event handling on macOS hosts

Charalampos Mitrodimas posted 1 patch 1 day, 20 hours ago
ui/gtk.c | 9 +++++++++
1 file changed, 9 insertions(+)
[PATCH] ui/gtk: Fix event handling on macOS hosts
Posted by Charalampos Mitrodimas 1 day, 20 hours ago
The GTK+ UI was not properly handling events on macOS due to missing
event loop polling in the Cocoa backend. Add polling of the GLib main
context during display refresh to ensure UI events are processed.

This fixes UI responsiveness issues when running QEMU with the GTK
display (--display gtk) on macOS hosts.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2676

Co-developed-by: Phil Dennis-Jordan <phil@philjordan.eu>
Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
---
 ui/gtk.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/ui/gtk.c b/ui/gtk.c
index bf9d3dd679..979210255f 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -437,6 +437,15 @@ static void gd_update(DisplayChangeListener *dcl,
 
 static void gd_refresh(DisplayChangeListener *dcl)
 {
+#ifdef GDK_WINDOWING_QUARTZ
+    GMainContext *context;
+    if (GDK_IS_QUARTZ_DISPLAY(gdk_display_get_default())) {
+        context = g_main_context_default();
+        while (g_main_context_pending(context)) {
+            g_main_context_iteration(context, FALSE);
+        }
+    }
+#endif
     graphic_hw_update(dcl->con);
 }
 
-- 
2.39.5 (Apple Git-154)
Re: [PATCH] ui/gtk: Fix event handling on macOS hosts
Posted by Phil Dennis-Jordan 1 day, 17 hours ago
Charalampos contacted me off-list with his original patch and I made a few
suggestions after testing it. So I'm not sure the 'Co-developed-by' tag is
warranted given I didn't write any code. In any case, this patch worked in
the testing I did on macOS, and it looks to be near-zero risk on other
platforms. I can't think of a simpler fix to the problem.

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
or
Reviewed-by: Phil Dennis-Jordan <phil@philjordan.eu>
Tested-by: Phil Dennis-Jordan <phil@philjordan.eu>

whichever is deemed appropriate in these circumstances.


On Thu, 21 Nov 2024 at 17:23, Charalampos Mitrodimas <charmitro@posteo.net>
wrote:

> The GTK+ UI was not properly handling events on macOS due to missing
> event loop polling in the Cocoa backend. Add polling of the GLib main
> context during display refresh to ensure UI events are processed.
>
> This fixes UI responsiveness issues when running QEMU with the GTK
> display (--display gtk) on macOS hosts.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2676
>
> Co-developed-by: Phil Dennis-Jordan <phil@philjordan.eu>
> Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
> ---
>  ui/gtk.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/ui/gtk.c b/ui/gtk.c
> index bf9d3dd679..979210255f 100644
> --- a/ui/gtk.c
> +++ b/ui/gtk.c
> @@ -437,6 +437,15 @@ static void gd_update(DisplayChangeListener *dcl,
>
>  static void gd_refresh(DisplayChangeListener *dcl)
>  {
> +#ifdef GDK_WINDOWING_QUARTZ
> +    GMainContext *context;
> +    if (GDK_IS_QUARTZ_DISPLAY(gdk_display_get_default())) {
> +        context = g_main_context_default();
> +        while (g_main_context_pending(context)) {
> +            g_main_context_iteration(context, FALSE);
> +        }
> +    }
> +#endif
>      graphic_hw_update(dcl->con);
>  }
>
> --
> 2.39.5 (Apple Git-154)
>
>
>