Skip to contentSkip to conversation

gtk cursor patches

Qemu-devel New Dave Airlie 2 participants 4 messages Dec 10, 2013

lore
Share & tools
lore
#0 lore raw

These were just fallout fixes from exploring gtk multi-head with virtio-gpu,

hopefully they are useful to people before then, not sure if the warping/absolute interaction is defined or not.

Dave.

#1 lore raw

PATCH 1/2 gtk: don't warp point in absolute mode

From: Dave Airlie <[email protected]>

This makes gtk act the same way as the current sdl backend, which doesn't do the warp in this case.

If your guest GPU has hw pointer this leads you get endless loops where the warp causes motion causes input events, causes the guest to move the cursor causes warp.

---
 ui/gtk.c | 3 +++
 1 file changed, 3 insertions(+)
ui/gtk.c +3 -0
index 6316f5b..2abf289 100644
@@ -338,6 +338,9 @@ static void gd_mouse_set(DisplayChangeListener *dcl,
     GdkDeviceManager *mgr;
     gint x_root, y_root;
 
+    if (kbd_mouse_is_absolute())
+	return;
+
     dpy = gtk_widget_get_display(s->drawing_area);
     mgr = gdk_display_get_device_manager(dpy);
     gdk_window_get_root_coords(gtk_widget_get_window(s->drawing_area),
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/2 gtk: respect cursor visibility

In reply to Dave Airlie

From: Dave Airlie <[email protected]>

If the guest asks for no cursor, switch gtk to using the null cursor.

---
 ui/gtk.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
ui/gtk.c +17 -8
index 2abf289..f60e66f 100644
@@ -158,6 +158,8 @@ typedef struct GtkDisplayState
     bool external_pause_update;
 
     bool modifier_pressed[ARRAY_SIZE(modifier_keycode)];
+
+    GdkCursor *current_cursor;
 } GtkDisplayState;
 
 static GtkDisplayState *global_state;
@@ -338,6 +340,11 @@ static void gd_mouse_set(DisplayChangeListener *dcl,
     GdkDeviceManager *mgr;
     gint x_root, y_root;
 
+    if (!visible)
+	gdk_window_set_cursor(gtk_widget_get_window(s->drawing_area), s->null_cursor);
+    else
+	gdk_window_set_cursor(gtk_widget_get_window(s->drawing_area), s->current_cursor);
+
     if (kbd_mouse_is_absolute())
 	return;
 
@@ -369,21 +376,23 @@ static void gd_cursor_define(DisplayChangeListener *dcl,
 {
     GtkDisplayState *s = container_of(dcl, GtkDisplayState, dcl);
     GdkPixbuf *pixbuf;
-    GdkCursor *cursor;
+
+    if (s->current_cursor) {
+#if !GTK_CHECK_VERSION(3, 0, 0)
+        gdk_cursor_unref(s->current_cursor);
+#else
+        g_object_unref(s->current_cursor);
+#endif
+        s->current_cursor = NULL;
+    }
 
     pixbuf = gdk_pixbuf_new_from_data((guchar *)(c->data),
                                       GDK_COLORSPACE_RGB, true, 8,
                                       c->width, c->height, c->width * 4,
                                       NULL, NULL);
-    cursor = gdk_cursor_new_from_pixbuf(gtk_widget_get_display(s->drawing_area),
+    s->current_cursor = gdk_cursor_new_from_pixbuf(gtk_widget_get_display(s->drawing_area),
                                         pixbuf, c->hot_x, c->hot_y);
-    gdk_window_set_cursor(gtk_widget_get_window(s->drawing_area), cursor);
     g_object_unref(pixbuf);
-#if !GTK_CHECK_VERSION(3, 0, 0)
-    gdk_cursor_unref(cursor);
-#else
-    g_object_unref(cursor);
-#endif
 }
 
 static void gd_switch(DisplayChangeListener *dcl,
Signature · 1 line
1.8.3.1
#3 lore raw
In reply to Dave Airlie

Am 10.12.2013 02:04, schrieb Dave Airlie:

Quoted 5 lines

These were just fallout fixes from exploring gtk multi-head with virtio-gpu,

hopefully they are useful to people before then, not sure if the warping/absolute interaction is defined or not.

Dave.

Please check both patches using scripts/checkpatch.pl.

Stefan