/** * gdk_cursor_get_image: * @cursor: a #GdkCursor * * Returns a #GdkPixbuf with the image used to display the cursor. * * Note that depending on the capabilities of the windowing system and * on the cursor, GDK may not be able to obtain the image data. In this * case, %NULL is returned. * * Returns: (transfer full): a #GdkPixbuf representing @cursor, or %NULL * * Since: 2.8 */ GdkPixbuf* gdk_cursor_get_image (GdkCursor *cursor) { int w, h; cairo_surface_t *surface; GdkPixbuf *pixbuf; gchar buf[32]; double x_hot, y_hot; double x_scale, y_scale; g_return_val_if_fail (GDK_IS_CURSOR (cursor), NULL); surface = gdk_cursor_get_surface (cursor, &x_hot, &y_hot); if (surface == NULL) return NULL; w = cairo_image_surface_get_width (surface); h = cairo_image_surface_get_height (surface); x_scale = y_scale = 1; #ifdef HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE cairo_surface_get_device_scale (surface, &x_scale, &y_scale); #endif pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, w, h); cairo_surface_destroy (surface); if (x_scale != 1) { GdkPixbuf *old; old = pixbuf; pixbuf = gdk_pixbuf_scale_simple (old, w / x_scale, h / y_scale, GDK_INTERP_HYPER); g_object_unref (old); } g_snprintf (buf, 32, "%d", (int)x_hot); gdk_pixbuf_set_option (pixbuf, "x_hot", buf); g_snprintf (buf, 32, "%d", (int)y_hot); gdk_pixbuf_set_option (pixbuf, "y_hot", buf); return pixbuf; }
cairo_surface_t * gitg_platform_support_create_cursor_surface (GdkDisplay *display, GdkCursorType cursor_type, gdouble *hot_x, gdouble *hot_y, gdouble *width, gdouble *height) { GdkCursor *cursor; cairo_surface_t *surface; gdouble w = 0, h = 0; cursor = gdk_cursor_new_for_display (display, cursor_type); surface = gdk_cursor_get_surface (cursor, hot_x, hot_y); if (surface == NULL) { return NULL; } switch (cairo_surface_get_type (surface)) { case CAIRO_SURFACE_TYPE_XLIB: w = cairo_xlib_surface_get_width (surface); h = cairo_xlib_surface_get_height (surface); break; case CAIRO_SURFACE_TYPE_IMAGE: w = cairo_image_surface_get_width (surface); h = cairo_image_surface_get_height (surface); break; } if (width) { *width = w; } if (height) { *height = h; } return surface; }