guint _gdk_wayland_cursor_get_next_image_index (GdkCursor *cursor, guint current_image_index, guint *next_image_delay) { struct wl_cursor *wl_cursor = GDK_WAYLAND_CURSOR (cursor)->wl_cursor; if (wl_cursor && wl_cursor->image_count > 1) { if (current_image_index >= wl_cursor->image_count) { g_warning (G_STRLOC " out of bounds cursor image [%d / %d]", current_image_index, wl_cursor->image_count - 1); current_image_index = 0; } /* Return the time to next image */ if (next_image_delay) *next_image_delay = wl_cursor->images[current_image_index]->delay; return (current_image_index + 1) % wl_cursor->image_count; } else return current_image_index; }
static void gdk_wayland_cursor_finalize (GObject *object) { GdkWaylandCursor *cursor = GDK_WAYLAND_CURSOR (object); g_free (cursor->name); if (cursor->surface.cairo_surface) cairo_surface_destroy (cursor->surface.cairo_surface); G_OBJECT_CLASS (_gdk_wayland_cursor_parent_class)->finalize (object); }
struct wl_buffer * _gdk_wayland_cursor_get_buffer (GdkCursor *cursor, guint image_index, int *hotspot_x, int *hotspot_y, int *w, int *h, int *scale) { GdkWaylandCursor *wayland_cursor = GDK_WAYLAND_CURSOR (cursor); if (wayland_cursor->wl_cursor) { struct wl_cursor_image *image; if (image_index >= wayland_cursor->wl_cursor->image_count) { g_warning (G_STRLOC " out of bounds cursor image [%d / %d]", image_index, wayland_cursor->wl_cursor->image_count - 1); image_index = 0; } image = wayland_cursor->wl_cursor->images[image_index]; *hotspot_x = image->hotspot_x / wayland_cursor->scale; *hotspot_y = image->hotspot_y / wayland_cursor->scale; *w = image->width / wayland_cursor->scale; *h = image->height / wayland_cursor->scale; *scale = wayland_cursor->scale; return wl_cursor_image_get_buffer (image); } else if (wayland_cursor->name == NULL) /* From surface */ { *hotspot_x = wayland_cursor->surface.hotspot_x / wayland_cursor->surface.scale; *hotspot_y = wayland_cursor->surface.hotspot_y / wayland_cursor->surface.scale; *w = wayland_cursor->surface.width / wayland_cursor->surface.scale; *h = wayland_cursor->surface.height / wayland_cursor->surface.scale; *scale = wayland_cursor->surface.scale; cairo_surface_reference (wayland_cursor->surface.cairo_surface); if (wayland_cursor->surface.cairo_surface) return _gdk_wayland_shm_surface_get_wl_buffer (wayland_cursor->surface.cairo_surface); } return NULL; }
void _gdk_wayland_cursor_set_scale (GdkCursor *cursor, guint scale) { GdkWaylandDisplay *wayland_display = GDK_WAYLAND_DISPLAY (gdk_cursor_get_display (cursor)); GdkWaylandCursor *wayland_cursor = GDK_WAYLAND_CURSOR (cursor); if (scale > GDK_WAYLAND_MAX_THEME_SCALE) { g_warning (G_STRLOC ": cursor theme size %u too large", scale); scale = GDK_WAYLAND_MAX_THEME_SCALE; } if (wayland_cursor->scale == scale) return; wayland_cursor->scale = scale; _gdk_wayland_cursor_update (wayland_display, wayland_cursor); }