summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2017-11-02 20:38:07 +0100
committerBenjamin Otte <otte@redhat.com>2017-11-04 00:07:13 +0100
commit8ba9ae601283be265e59c6092d61c099f8a17d65 (patch)
treeb6d93db04fbf5280d13f7c8a59de219befdd682c
parenta1759a0a52d4b6b988fcafbf30f9fd0b61c06030 (diff)
downloadgtk+-8ba9ae601283be265e59c6092d61c099f8a17d65.tar.gz
gdk: Add gdk_cursor_get_name()
Also add the GdkCursor::name property.
-rw-r--r--docs/reference/gdk/gdk4-sections.txt1
-rw-r--r--gdk/broadway/gdkcursor-broadway.c1
-rw-r--r--gdk/gdkcursor.c50
-rw-r--r--gdk/gdkcursor.h2
-rw-r--r--gdk/gdkcursorprivate.h1
-rw-r--r--gdk/wayland/gdkcursor-wayland.c27
-rw-r--r--gdk/x11/gdkcursor-x11.c25
7 files changed, 77 insertions, 30 deletions
diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt
index 99e81492d9..6723bbbbc0 100644
--- a/docs/reference/gdk/gdk4-sections.txt
+++ b/docs/reference/gdk/gdk4-sections.txt
@@ -813,6 +813,7 @@ gdk_cursor_new_from_pixbuf
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
diff --git a/gdk/broadway/gdkcursor-broadway.c b/gdk/broadway/gdkcursor-broadway.c
index 02e8782897..b6edb95041 100644
--- a/gdk/broadway/gdkcursor-broadway.c
+++ b/gdk/broadway/gdkcursor-broadway.c
@@ -126,6 +126,7 @@ _gdk_broadway_display_get_cursor_for_name (GdkDisplay *display,
private = g_object_new (GDK_TYPE_BROADWAY_CURSOR,
"display", display,
+ "name", name,
NULL);
return GDK_CURSOR (private);
diff --git a/gdk/gdkcursor.c b/gdk/gdkcursor.c
index 4c85588229..63a5075f32 100644
--- a/gdk/gdkcursor.c
+++ b/gdk/gdkcursor.c
@@ -65,7 +65,8 @@
enum {
PROP_0,
- PROP_DISPLAY
+ PROP_DISPLAY,
+ PROP_NAME
};
G_DEFINE_ABSTRACT_TYPE (GdkCursor, gdk_cursor, G_TYPE_OBJECT)
@@ -83,6 +84,9 @@ gdk_cursor_get_property (GObject *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;
@@ -104,6 +108,9 @@ gdk_cursor_set_property (GObject *object,
/* 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;
@@ -111,12 +118,23 @@ gdk_cursor_set_property (GObject *object,
}
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)
{
GObjectClass *object_class = G_OBJECT_CLASS (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,
@@ -125,6 +143,13 @@ gdk_cursor_class_init (GdkCursorClass *cursor_class)
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
@@ -189,6 +214,7 @@ gdk_cursor_new_from_name (GdkDisplay *display,
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);
}
@@ -309,6 +335,7 @@ gdk_cursor_new_from_surface (GdkDisplay *display,
return GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_surface (display,
surface, x, y);
}
+
/**
* gdk_cursor_get_display:
* @cursor: a #GdkCursor.
@@ -319,7 +346,6 @@ gdk_cursor_new_from_surface (GdkDisplay *display,
*
* Since: 2.2
*/
-
GdkDisplay *
gdk_cursor_get_display (GdkCursor *cursor)
{
@@ -329,6 +355,26 @@ gdk_cursor_get_display (GdkCursor *cursor)
}
/**
+ * 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
*
diff --git a/gdk/gdkcursor.h b/gdk/gdkcursor.h
index 94c09bf864..44f446fe2a 100644
--- a/gdk/gdkcursor.h
+++ b/gdk/gdkcursor.h
@@ -60,6 +60,8 @@ GdkCursor* gdk_cursor_new_from_name (GdkDisplay *display,
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
diff --git a/gdk/gdkcursorprivate.h b/gdk/gdkcursorprivate.h
index 85498a6f8f..36601c825f 100644
--- a/gdk/gdkcursorprivate.h
+++ b/gdk/gdkcursorprivate.h
@@ -40,6 +40,7 @@ struct _GdkCursor
GObject parent_instance;
GdkDisplay *display;
+ char *name;
};
struct _GdkCursorClass
diff --git a/gdk/wayland/gdkcursor-wayland.c b/gdk/wayland/gdkcursor-wayland.c
index 060b54a43e..7a2260371b 100644
--- a/gdk/wayland/gdkcursor-wayland.c
+++ b/gdk/wayland/gdkcursor-wayland.c
@@ -49,7 +49,6 @@ typedef struct _GdkWaylandCursorClass GdkWaylandCursorClass;
struct _GdkWaylandCursor
{
GdkCursor cursor;
- gchar *name;
struct
{
@@ -144,22 +143,25 @@ _gdk_wayland_cursor_update (GdkWaylandDisplay *display_wayland,
{
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");
}
@@ -167,7 +169,7 @@ _gdk_wayland_cursor_update (GdkWaylandDisplay *display_wayland,
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;
}
@@ -194,7 +196,6 @@ 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);
@@ -243,7 +244,7 @@ _gdk_wayland_cursor_get_buffer (GdkCursor *cursor,
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;
@@ -309,7 +310,7 @@ _gdk_wayland_cursor_set_scale (GdkCursor *cursor,
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);
@@ -347,18 +348,17 @@ _gdk_wayland_display_get_cursor_for_name_with_scale (GdkDisplay *display,
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))
@@ -369,7 +369,7 @@ _gdk_wayland_display_get_cursor_for_name_with_scale (GdkDisplay *display,
/* 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);
}
@@ -408,7 +408,6 @@ _gdk_wayland_display_get_cursor_for_surface (GdkDisplay *display,
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;
diff --git a/gdk/x11/gdkcursor-x11.c b/gdk/x11/gdkcursor-x11.c
index 7fc1c5d405..cd5064ddba 100644
--- a/gdk/x11/gdkcursor-x11.c
+++ b/gdk/x11/gdkcursor-x11.c
@@ -50,7 +50,6 @@ struct _GdkX11Cursor
GdkCursor cursor;
Cursor xcursor;
- gchar *name;
guint serial;
};
@@ -103,7 +102,7 @@ cache_compare_func (gconstpointer listelem,
/* 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
@@ -175,8 +174,6 @@ gdk_x11_cursor_finalize (GObject *object)
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);
}
@@ -269,24 +266,23 @@ gdk_x11_cursor_get_surface (GdkCursor *cursor,
{
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;
@@ -343,8 +339,11 @@ _gdk_x11_cursor_update_theme (GdkCursor *cursor)
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)
{
@@ -532,7 +531,6 @@ _gdk_x11_display_get_cursor_for_surface (GdkDisplay *display,
"display", display,
NULL);
private->xcursor = xcursor;
- private->name = NULL;
private->serial = theme_serial;
return GDK_CURSOR (private);
@@ -644,9 +642,9 @@ _gdk_x11_display_get_cursor_for_name (GdkDisplay *display,
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);
@@ -709,7 +707,6 @@ gdk_cursor_new_from_pixmap (GdkDisplay *display,
"display", display,
NULL);
private->xcursor = xcursor;
- private->name = NULL;
private->serial = theme_serial;
return GDK_CURSOR (private);