[Spice-devel] [PATCH spice-gtk v2 1/5] gtk: Use gdk_cursor_new_for_display

Christophe Fergeau cfergeau at redhat.com
Wed Dec 21 10:40:04 UTC 2016


On Mon, Dec 19, 2016 at 05:26:32PM +0100, Pavel Grunt wrote:
> Create the cursor when the widget is realized
> ---
>  src/spice-widget.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/src/spice-widget.c b/src/spice-widget.c
> index 72fbbc8..a27f5a2 100644
> --- a/src/spice-widget.c
> +++ b/src/spice-widget.c
> @@ -460,12 +460,12 @@ static void spice_display_finalize(GObject *obj)
>      G_OBJECT_CLASS(spice_display_parent_class)->finalize(obj);
>  }
>  
> -static GdkCursor* get_blank_cursor(void)
> +static GdkCursor* spice_display_get_blank_cursor(SpiceDisplay *display)
>  {
> -    if (g_getenv("SPICE_DEBUG_CURSOR"))
> -        return gdk_cursor_new(GDK_DOT);
> +    GdkDisplay *gdk_display = gdk_window_get_display(GDK_WINDOW(gtk_widget_get_window(GTK_WIDGET(display))));
> +    GdkCursorType cursor_type = g_getenv("SPICE_DEBUG_CURSOR") ? GDK_DOT : GDK_BLANK_CURSOR;
>  
> -    return gdk_cursor_new(GDK_BLANK_CURSOR);
> +    return gdk_cursor_new_for_display(gdk_display, cursor_type);
>  }

As noted in GdkCursorType documentation, « Note that these IDs are directly
taken from the X cursor font, and many of these cursors are either not useful,
or are not available on other platforms », and on Wayland, GDK_DOT is indeed
not available. When we try to use this, we get the regular mouse pointer
instead, which imo is good enough.
If we want a different cursor to be shown when using SPICE_DEBUG_CURSOR (which
also makes sense!), then I'd use the patch below:

diff --git a/src/spice-widget.c b/src/spice-widget.c
index cf18fa6..2ea2ce5 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -467,9 +467,9 @@ static void spice_display_finalize(GObject *obj)
 static GdkCursor* spice_display_get_blank_cursor(SpiceDisplay *display)
 {
     GdkDisplay *gdk_display = gdk_window_get_display(GDK_WINDOW(gtk_widget_get_window(GTK_WIDGET(display))));
-    GdkCursorType cursor_type = g_getenv("SPICE_DEBUG_CURSOR") ? GDK_DOT : GDK_BLANK_CURSOR;
+    const char *cursor_name = g_getenv("SPICE_DEBUG_CURSOR") ? "crosshair" : "none";

-    return gdk_cursor_new_for_display(gdk_display, cursor_type);
+    return gdk_cursor_new_from_name(gdk_display, cursor_name);
 }

 static gboolean grab_broken(SpiceDisplay *self, GdkEventGrabBroken *event,


Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20161221/a268fc82/attachment.sig>


More information about the Spice-devel mailing list