Also add the GdkCursor::name property.
gdk_cursor_new_from_surface
gdk_cursor_new_from_name
gdk_cursor_get_display
+gdk_cursor_get_name
gdk_cursor_get_image
gdk_cursor_get_surface
private = g_object_new (GDK_TYPE_BROADWAY_CURSOR,
"display", display,
+ "name", name,
NULL);
return GDK_CURSOR (private);
enum {
PROP_0,
- PROP_DISPLAY
+ PROP_DISPLAY,
+ PROP_NAME
};
G_DEFINE_ABSTRACT_TYPE (GdkCursor, gdk_cursor, G_TYPE_OBJECT)
case PROP_DISPLAY:
g_value_set_object (value, cursor->display);
break;
+ case PROP_NAME:
+ g_value_set_string (value, cursor->name);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
/* check that implementations actually provide the display when constructing */
g_assert (cursor->display != NULL);
break;
+ case PROP_NAME:
+ cursor->name = g_value_dup_string (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
+static void
+gdk_cursor_finalize (GObject *object)
+{
+ GdkCursor *cursor = GDK_CURSOR (object);
+
+ g_free (cursor->name);
+
+ G_OBJECT_CLASS (gdk_cursor_parent_class)->finalize (object);
+}
+
static void
gdk_cursor_class_init (GdkCursorClass *cursor_class)
{
object_class->get_property = gdk_cursor_get_property;
object_class->set_property = gdk_cursor_set_property;
+ object_class->finalize = gdk_cursor_finalize;
g_object_class_install_property (object_class,
PROP_DISPLAY,
P_("Display of this cursor"),
GDK_TYPE_DISPLAY,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class,
+ PROP_NAME,
+ g_param_spec_string ("name",
+ P_("Name"),
+ P_("Name of this cursor"),
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
static void
const gchar *name)
{
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
+ g_return_val_if_fail (name != NULL, NULL);
return GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_name (display, name);
}
return GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_surface (display,
surface, x, y);
}
+
/**
* gdk_cursor_get_display:
* @cursor: a #GdkCursor.
*
* Since: 2.2
*/
-
GdkDisplay *
gdk_cursor_get_display (GdkCursor *cursor)
{
return cursor->display;
}
+/**
+ * gdk_cursor_get_name:
+ * @cursor: a #GdkCursor.
+ *
+ * Returns the name of the cursor. If the cursor is not a named cursor, %NULL
+ * will be returned and the surface property will be set.
+ *
+ * Returns: (transfer none): the name of the cursor or %NULL if it is not
+ * a named cursor
+ *
+ * Since: 3.94
+ */
+const char *
+gdk_cursor_get_name (GdkCursor *cursor)
+{
+ g_return_val_if_fail (GDK_IS_CURSOR (cursor), NULL);
+
+ return cursor->name;
+}
+
/**
* gdk_cursor_get_image:
* @cursor: a #GdkCursor
const gchar *name);
GDK_AVAILABLE_IN_ALL
GdkDisplay* gdk_cursor_get_display (GdkCursor *cursor);
+GDK_AVAILABLE_IN_3_94
+const char *gdk_cursor_get_name (GdkCursor *cursor);
GDK_AVAILABLE_IN_ALL
GdkPixbuf* gdk_cursor_get_image (GdkCursor *cursor);
GDK_AVAILABLE_IN_3_10
GObject parent_instance;
GdkDisplay *display;
+ char *name;
};
struct _GdkCursorClass
struct _GdkWaylandCursor
{
GdkCursor cursor;
- gchar *name;
struct
{
{
struct wl_cursor *c;
struct wl_cursor_theme *theme;
+ const char *name;
+
+ name = gdk_cursor_get_name (GDK_CURSOR (cursor));
/* Do nothing if this is not a wl_cursor cursor. */
- if (cursor->name == NULL)
+ if (name == NULL)
return FALSE;
theme = _gdk_wayland_display_get_scaled_cursor_theme (display_wayland,
cursor->scale);
- c = wl_cursor_theme_get_cursor (theme, cursor->name);
+ c = wl_cursor_theme_get_cursor (theme, name);
if (!c)
{
const char *fallback;
- fallback = name_fallback (cursor->name);
+ fallback = name_fallback (name);
if (fallback)
{
- c = wl_cursor_theme_get_cursor (theme, name_fallback (cursor->name));
+ c = wl_cursor_theme_get_cursor (theme, fallback);
if (!c)
c = wl_cursor_theme_get_cursor (theme, "left_ptr");
}
if (!c)
{
- g_message ("Unable to load %s from the cursor theme", cursor->name);
+ g_message ("Unable to load %s from the cursor theme", name);
return FALSE;
}
{
GdkWaylandCursor *cursor = GDK_WAYLAND_CURSOR (object);
- g_free (cursor->name);
if (cursor->surface.cairo_surface)
cairo_surface_destroy (cursor->surface.cairo_surface);
return wl_cursor_image_get_buffer (image);
}
- else if (wayland_cursor->name == NULL) /* From surface */
+ else if (gdk_cursor_get_name (cursor) == NULL) /* From surface */
{
*hotspot_x =
wayland_cursor->surface.hotspot_x / wayland_cursor->surface.scale;
wayland_cursor->scale = scale;
/* Blank cursor case */
- if (g_strcmp0 (wayland_cursor->name, "none") == 0)
+ if (g_strcmp0 (gdk_cursor_get_name (cursor), "none") == 0)
return;
_gdk_wayland_cursor_update (display_wayland, wayland_cursor);
private = g_object_new (GDK_TYPE_WAYLAND_CURSOR,
"display", display,
+ "name", name,
NULL);
/* Blank cursor case */
- if (!name || g_str_equal (name, "none") || g_str_equal (name, "blank_cursor"))
+ if (g_str_equal (name, "none") || g_str_equal (name, "blank_cursor"))
{
- private->name = g_strdup ("none");
private->scale = scale;
return GDK_CURSOR (private);
}
- private->name = g_strdup (name);
private->scale = scale;
if (!_gdk_wayland_cursor_update (display_wayland, private))
/* Insert into cache. */
g_hash_table_insert (display_wayland->cursor_cache,
- private->name,
+ (gpointer) gdk_cursor_get_name (GDK_CURSOR (private)),
g_object_ref (private));
return GDK_CURSOR (private);
}
cursor = g_object_new (GDK_TYPE_WAYLAND_CURSOR,
"display", display_wayland,
NULL);
- cursor->name = NULL;
cursor->surface.hotspot_x = x;
cursor->surface.hotspot_y = y;
GdkCursor cursor;
Cursor xcursor;
- gchar *name;
guint serial;
};
/* Elements marked as pixmap must be named cursors
* (since we don't store normal pixmap cursors
*/
- return strcmp (key->name, cursor->name);
+ return strcmp (key->name, gdk_cursor_get_name (GDK_CURSOR (cursor)));
}
/* Returns the cursor if there is a match, NULL if not
if (private->xcursor && !gdk_display_is_closed (display))
XFreeCursor (GDK_DISPLAY_XDISPLAY (display), private->xcursor);
- g_free (private->name);
-
G_OBJECT_CLASS (gdk_x11_cursor_parent_class)->finalize (object);
}
{
GdkDisplay *display;
Display *xdisplay;
- GdkX11Cursor *private;
XcursorImages *images;
XcursorImage *image;
gint size;
cairo_surface_t *surface;
gint scale;
gchar *theme;
+ const char *name;
- private = GDK_X11_CURSOR (cursor);
-
display = gdk_cursor_get_display (cursor);
xdisplay = GDK_DISPLAY_XDISPLAY (display);
size = XcursorGetDefaultSize (xdisplay);
theme = XcursorGetTheme (xdisplay);
- if (private->name)
- images = XcursorLibraryLoadImages (private->name, theme, size);
+ name = gdk_cursor_get_name (cursor);
+ if (name)
+ images = XcursorLibraryLoadImages (name, theme, size);
else
images = NULL;
if (private->xcursor != None)
{
- if (private->name)
- new_cursor = XcursorLibraryLoadCursor (xdisplay, private->name);
+ const char *name;
+
+ name = gdk_cursor_get_name (cursor);
+ if (name)
+ new_cursor = XcursorLibraryLoadCursor (xdisplay, name);
if (new_cursor != None)
{
"display", display,
NULL);
private->xcursor = xcursor;
- private->name = NULL;
private->serial = theme_serial;
return GDK_CURSOR (private);
private = g_object_new (GDK_TYPE_X11_CURSOR,
"display", display,
+ "name", name,
NULL);
private->xcursor = xcursor;
- private->name = g_strdup (name);
private->serial = theme_serial;
add_to_cache (private);
"display", display,
NULL);
private->xcursor = xcursor;
- private->name = NULL;
private->serial = theme_serial;
return GDK_CURSOR (private);