[spice-gtk,v1] widget: mouse: Fix getting coordinates

Submitted by Victor Toso on Feb. 12, 2019, 5:27 p.m.

Details

Message ID 20190212172739.10045-1-victortoso@redhat.com
State New
Headers show
Series "widget: mouse: Fix getting coordinates" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Victor Toso Feb. 12, 2019, 5:27 p.m.
From: Victor Toso <me@victortoso.com>

Documentation for gdk_display_get_primary_monitor() says that it
returns "the primary monitor, or NULL if no primary monitor is
configured by the user".

If monitor endup being NULL, we endup using unitialized GdkRectangle
geom later on as gdk_monitor_get_geometry() will fail with:

 | gdk_monitor_get_geometry: assertion 'GDK_IS_MONITOR (monitor)' failed

This patch tries gdk_display_get_monitor_at_point() and will fail if
no GdkMonitor is set.

Signed-off-by: Victor Toso <victortoso@redhat.com>
---
 src/spice-widget.c | 5 +++++
 1 file changed, 5 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/spice-widget.c b/src/spice-widget.c
index 8adcc38..e69b808 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -1129,6 +1129,11 @@  static void mouse_wrap(SpiceDisplay *display, GdkEventMotion *motion)
     GdkWindow *gdk_window = gtk_widget_get_window(GTK_WIDGET(display));
     GdkDisplay *gdk_display = gdk_window_get_display(gdk_window);
     GdkMonitor *monitor = gdk_display_get_primary_monitor(gdk_display);
+    if (monitor == NULL) {
+        /* No primary monitor set, using last mouse coordinates */
+        monitor = gdk_display_get_monitor_at_point(gdk_display, d->mouse_last_x, d->mouse_last_y);
+    }
+    g_return_if_fail(monitor != NULL);
     gdk_monitor_get_geometry(monitor, &geom);
 
     xr = geom.width / 2;