* [PATCH v2] ui/gtk: fix cursor moved to left corner
@ 2023-03-20 13:26 marcandre.lureau
2023-03-20 13:32 ` Daniel P. Berrangé
2023-03-20 22:39 ` Bernhard Beschow
0 siblings, 2 replies; 3+ messages in thread
From: marcandre.lureau @ 2023-03-20 13:26 UTC (permalink / raw)
To: qemu-devel; +Cc: berrange, shentey, Marc-André Lureau, Gerd Hoffmann
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Do not attempt to move the pointer if the widget is not yet realized.
The mouse cursor is placed to the corner of the screen, on X11 at least,
as x_root and y_root are then miscalculated. (this is not reproducible
on Wayland, because Gtk doesn't implement device warping there)
This also fixes the following warning at start:
qemu: Gdk: gdk_window_get_root_coords: assertion 'GDK_IS_WINDOW (window)' failed
Fixes: 6effaa16ac98 ("ui: set cursor position upon listener
registration")
Reported-by: Bernhard Beschow <shentey@gmail.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
ui/gtk.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/ui/gtk.c b/ui/gtk.c
index fd82e9b1ca..e9564f2baa 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -450,7 +450,8 @@ static void gd_mouse_set(DisplayChangeListener *dcl,
GdkDisplay *dpy;
gint x_root, y_root;
- if (qemu_input_is_absolute()) {
+ if (!gtk_widget_get_realized(vc->gfx.drawing_area) ||
+ qemu_input_is_absolute()) {
return;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] ui/gtk: fix cursor moved to left corner
2023-03-20 13:26 [PATCH v2] ui/gtk: fix cursor moved to left corner marcandre.lureau
@ 2023-03-20 13:32 ` Daniel P. Berrangé
2023-03-20 22:39 ` Bernhard Beschow
1 sibling, 0 replies; 3+ messages in thread
From: Daniel P. Berrangé @ 2023-03-20 13:32 UTC (permalink / raw)
To: marcandre.lureau; +Cc: qemu-devel, shentey, Gerd Hoffmann
On Mon, Mar 20, 2023 at 05:26:24PM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> Do not attempt to move the pointer if the widget is not yet realized.
> The mouse cursor is placed to the corner of the screen, on X11 at least,
> as x_root and y_root are then miscalculated. (this is not reproducible
> on Wayland, because Gtk doesn't implement device warping there)
>
> This also fixes the following warning at start:
> qemu: Gdk: gdk_window_get_root_coords: assertion 'GDK_IS_WINDOW (window)' failed
Ah, this assertion means that gdk_window_get_root_coords returns
control without setting x_root and y_root. So they contain
whatever garbage is on the stack. They could end up pointing anywhere,
and because max value of an 'int' is way larger than the screen size
they'll usually get capped at the sceen size and thus end up bottom
right corner.
>
> Fixes: 6effaa16ac98 ("ui: set cursor position upon listener
> registration")
> Reported-by: Bernhard Beschow <shentey@gmail.com>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> ui/gtk.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
>
> diff --git a/ui/gtk.c b/ui/gtk.c
> index fd82e9b1ca..e9564f2baa 100644
> --- a/ui/gtk.c
> +++ b/ui/gtk.c
> @@ -450,7 +450,8 @@ static void gd_mouse_set(DisplayChangeListener *dcl,
> GdkDisplay *dpy;
> gint x_root, y_root;
>
> - if (qemu_input_is_absolute()) {
> + if (!gtk_widget_get_realized(vc->gfx.drawing_area) ||
> + qemu_input_is_absolute()) {
> return;
> }
>
> --
> 2.39.2
>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] ui/gtk: fix cursor moved to left corner
2023-03-20 13:26 [PATCH v2] ui/gtk: fix cursor moved to left corner marcandre.lureau
2023-03-20 13:32 ` Daniel P. Berrangé
@ 2023-03-20 22:39 ` Bernhard Beschow
1 sibling, 0 replies; 3+ messages in thread
From: Bernhard Beschow @ 2023-03-20 22:39 UTC (permalink / raw)
To: marcandre.lureau, qemu-devel
Cc: berrange, Marc-André Lureau, Gerd Hoffmann
Am 20. März 2023 13:26:24 UTC schrieb marcandre.lureau@redhat.com:
>From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
>Do not attempt to move the pointer if the widget is not yet realized.
>The mouse cursor is placed to the corner of the screen, on X11 at least,
>as x_root and y_root are then miscalculated. (this is not reproducible
>on Wayland, because Gtk doesn't implement device warping there)
>
>This also fixes the following warning at start:
>qemu: Gdk: gdk_window_get_root_coords: assertion 'GDK_IS_WINDOW (window)' failed
>
>Fixes: 6effaa16ac98 ("ui: set cursor position upon listener
>registration")
This particular issue gets fixed, so:
Tested-by: Bernhard Beschow <shentey@gmail.com>
However, when I perform a test like in https://gitlab.com/qemu-project/qemu/-/issues/1550 , the cursor gets placed into the QEMU window once the graphical environment is entered *in the guest*, regardless of whether QEMU has the focus or not. This seems quite strange because an application shouldn't "steal" the mouse from the active application. So perhaps this fix is just scratching the surface of a deeper underlying bug...
Best regards,
Bernhard
>Reported-by: Bernhard Beschow <shentey@gmail.com>
>Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>---
> ui/gtk.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
>diff --git a/ui/gtk.c b/ui/gtk.c
>index fd82e9b1ca..e9564f2baa 100644
>--- a/ui/gtk.c
>+++ b/ui/gtk.c
>@@ -450,7 +450,8 @@ static void gd_mouse_set(DisplayChangeListener *dcl,
> GdkDisplay *dpy;
> gint x_root, y_root;
>
>- if (qemu_input_is_absolute()) {
>+ if (!gtk_widget_get_realized(vc->gfx.drawing_area) ||
>+ qemu_input_is_absolute()) {
> return;
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-03-20 22:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-20 13:26 [PATCH v2] ui/gtk: fix cursor moved to left corner marcandre.lureau
2023-03-20 13:32 ` Daniel P. Berrangé
2023-03-20 22:39 ` Bernhard Beschow
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).