[gtk+] gdk: Turn GdkAtom into a const char *
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] gdk: Turn GdkAtom into a const char *
- Date: Wed, 15 Nov 2017 18:22:23 +0000 (UTC)
commit cb941956d3f2003f6fa3551d44e42221b1345393
Author: Benjamin Otte <otte redhat com>
Date: Wed Nov 15 16:57:33 2017 +0100
gdk: Turn GdkAtom into a const char *
Instead of an integer, it is now a char pointer. We also use
g_intern_string() instead of doing the interning ourselves.
gdk/gdkproperty.c | 46 ++---------------------------------
gdk/gdktypes.h | 8 ++----
gdk/wayland/gdkselection-wayland.c | 8 +++---
3 files changed, 10 insertions(+), 52 deletions(-)
---
diff --git a/gdk/gdkproperty.c b/gdk/gdkproperty.c
index d46b9ed..bdd6d70 100644
--- a/gdk/gdkproperty.c
+++ b/gdk/gdkproperty.c
@@ -56,41 +56,6 @@
* data commonly stored in X window properties.
*/
-static GHashTable *names_to_atoms;
-static GPtrArray *atoms_to_names;
-
-static void
-ensure_atom_tables (void)
-{
- if (names_to_atoms)
- return;
-
- names_to_atoms = g_hash_table_new (g_str_hash, g_str_equal);
- atoms_to_names = g_ptr_array_new ();
-
- g_ptr_array_add (atoms_to_names, NULL);
-}
-
-static GdkAtom
-intern_atom_internal (const gchar *atom_name,
- gboolean allocate)
-{
- gpointer result;
- gchar *name;
-
- ensure_atom_tables ();
-
- if (g_hash_table_lookup_extended (names_to_atoms, atom_name, NULL, &result))
- return result;
-
- result = GINT_TO_POINTER (atoms_to_names->len);
- name = allocate ? g_strdup (atom_name) : (gchar *)atom_name;
- g_hash_table_insert (names_to_atoms, name, result);
- g_ptr_array_add (atoms_to_names, name);
-
- return result;
-}
-
/**
* gdk_atom_intern:
* @atom_name: a string.
@@ -109,7 +74,7 @@ gdk_atom_intern (const gchar *atom_name,
{
g_return_val_if_fail (atom_name != NULL, GDK_NONE);
- return intern_atom_internal (atom_name, TRUE);
+ return g_intern_string (atom_name);
}
/**
@@ -136,7 +101,7 @@ gdk_atom_intern_static_string (const gchar *atom_name)
{
g_return_val_if_fail (atom_name != NULL, GDK_NONE);
- return intern_atom_internal (atom_name, FALSE);
+ return g_intern_static_string (atom_name);
}
/**
@@ -158,10 +123,5 @@ gdk_atom_name (GdkAtom atom)
const gchar *
_gdk_atom_name_const (GdkAtom atom)
{
- ensure_atom_tables ();
-
- if (GPOINTER_TO_INT (atom) >= atoms_to_names->len)
- return NULL;
-
- return g_ptr_array_index (atoms_to_names, GPOINTER_TO_INT (atom));
+ return atom;
}
diff --git a/gdk/gdktypes.h b/gdk/gdktypes.h
index 0fae1ca..8373b32 100644
--- a/gdk/gdktypes.h
+++ b/gdk/gdktypes.h
@@ -99,7 +99,7 @@ typedef cairo_rectangle_int_t GdkRectangle;
* An opaque type representing a string as an index into a table
* of strings on the X server.
*/
-typedef struct _GdkAtom *GdkAtom;
+typedef const char *GdkAtom;
/**
* GDK_ATOM_TO_POINTER:
@@ -107,7 +107,7 @@ typedef struct _GdkAtom *GdkAtom;
*
* Converts a #GdkAtom into a pointer type.
*/
-#define GDK_ATOM_TO_POINTER(atom) (atom)
+#define GDK_ATOM_TO_POINTER(atom) ((gpointer) (atom))
/**
* GDK_POINTER_TO_ATOM:
@@ -118,15 +118,13 @@ typedef struct _GdkAtom *GdkAtom;
*/
#define GDK_POINTER_TO_ATOM(ptr) ((GdkAtom)(ptr))
-#define _GDK_MAKE_ATOM(val) ((GdkAtom)GUINT_TO_POINTER(val))
-
/**
* GDK_NONE:
*
* A null value for #GdkAtom, used in a similar way as
* `None` in the Xlib API.
*/
-#define GDK_NONE ((GdkAtom) 0)
+#define GDK_NONE NULL
/* Forward declarations of commonly used types */
typedef struct _GdkRGBA GdkRGBA;
diff --git a/gdk/wayland/gdkselection-wayland.c b/gdk/wayland/gdkselection-wayland.c
index b60a99a..6110dc0 100644
--- a/gdk/wayland/gdkselection-wayland.c
+++ b/gdk/wayland/gdkselection-wayland.c
@@ -378,13 +378,13 @@ data_offer_offer (void *data,
info = g_hash_table_lookup (selection->offers, wl_data_offer);
- if (!info || g_list_find (info->targets, atom))
+ if (!info || g_list_find (info->targets, GDK_ATOM_TO_POINTER (atom)))
return;
GDK_NOTE (EVENTS,
g_message ("data offer offer, offer %p, type = %s", wl_data_offer, type));
- info->targets = g_list_prepend (info->targets, atom);
+ info->targets = g_list_prepend (info->targets, GDK_ATOM_TO_POINTER (atom));
}
static inline GdkDragAction
@@ -466,13 +466,13 @@ primary_offer_offer (void *data,
info = g_hash_table_lookup (selection->offers, gtk_offer);
- if (!info || g_list_find (info->targets, atom))
+ if (!info || g_list_find (info->targets, GDK_ATOM_TO_POINTER (atom)))
return;
GDK_NOTE (EVENTS,
g_message ("primary offer offer, offer %p, type = %s", gtk_offer, type));
- info->targets = g_list_prepend (info->targets, atom);
+ info->targets = g_list_prepend (info->targets, GDK_ATOM_TO_POINTER (atom));
}
static const struct gtk_primary_selection_offer_listener primary_offer_listener = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]