[gtk+/gdk-backend: 75/91] Add vfuncs for atoms
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gdk-backend: 75/91] Add vfuncs for atoms
- Date: Sat, 18 Dec 2010 01:12:08 +0000 (UTC)
commit 36efc836d6e71ba61a8d746f8d8efd0f6b4e033d
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Dec 16 00:37:39 2010 -0500
Add vfuncs for atoms
gdk/gdkdisplaymanager.c | 66 +++++++++++++++++++++++++++
gdk/gdkdisplaymanagerprivate.h | 5 ++
gdk/x11/gdkdisplaymanager-x11.c | 2 +
gdk/x11/gdkprivate-x11.h | 14 ++++--
gdk/x11/gdkproperty-x11.c | 93 +++++++++------------------------------
5 files changed, 104 insertions(+), 76 deletions(-)
---
diff --git a/gdk/gdkdisplaymanager.c b/gdk/gdkdisplaymanager.c
index 7cb067e..60f5302 100644
--- a/gdk/gdkdisplaymanager.c
+++ b/gdk/gdkdisplaymanager.c
@@ -286,3 +286,69 @@ gdk_display_manager_open_display (GdkDisplayManager *manager,
{
return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->open_display (manager, name);
}
+
+/**
+ * gdk_atom_intern:
+ * @atom_name: a string.
+ * @only_if_exists: if %TRUE, GDK is allowed to not create a new atom, but
+ * just return %GDK_NONE if the requested atom doesn't already
+ * exists. Currently, the flag is ignored, since checking the
+ * existance of an atom is as expensive as creating it.
+ *
+ * Finds or creates an atom corresponding to a given string.
+ *
+ * Returns: the atom corresponding to @atom_name.
+ */
+GdkAtom
+gdk_atom_intern (const gchar *atom_name,
+ gboolean only_if_exists)
+{
+ GdkDisplayManager *manager = gdk_display_manager_get ();
+
+ return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->atom_intern (manager, atom_name, TRUE);
+}
+
+/**
+ * gdk_atom_intern_static_string:
+ * @atom_name: a static string
+ *
+ * Finds or creates an atom corresponding to a given string.
+ *
+ * Note that this function is identical to gdk_atom_intern() except
+ * that if a new #GdkAtom is created the string itself is used rather
+ * than a copy. This saves memory, but can only be used if the string
+ * will <emphasis>always</emphasis> exist. It can be used with statically
+ * allocated strings in the main program, but not with statically
+ * allocated memory in dynamically loaded modules, if you expect to
+ * ever unload the module again (e.g. do not use this function in
+ * GTK+ theme engines).
+ *
+ * Returns: the atom corresponding to @atom_name
+ *
+ * Since: 2.10
+ */
+GdkAtom
+gdk_atom_intern_static_string (const gchar *atom_name)
+{
+ GdkDisplayManager *manager = gdk_display_manager_get ();
+
+ return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->atom_intern (manager, atom_name, FALSE);
+}
+
+/**
+ * gdk_atom_name:
+ * @atom: a #GdkAtom.
+ *
+ * Determines the string corresponding to an atom.
+ *
+ * Returns: a newly-allocated string containing the string
+ * corresponding to @atom. When you are done with the
+ * return value, you should free it using g_free().
+ */
+gchar *
+gdk_atom_name (GdkAtom atom)
+{
+ GdkDisplayManager *manager = gdk_display_manager_get ();
+
+ return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->get_atom_name (manager, atom);
+}
diff --git a/gdk/gdkdisplaymanagerprivate.h b/gdk/gdkdisplaymanagerprivate.h
index f10d00a..70afd7d 100644
--- a/gdk/gdkdisplaymanagerprivate.h
+++ b/gdk/gdkdisplaymanagerprivate.h
@@ -39,6 +39,11 @@ struct _GdkDisplayManagerClass
GdkDisplay *display);
GdkDisplay * (*open_display) (GdkDisplayManager *manager,
const gchar *name);
+ GdkAtom (*atom_intern) (GdkDisplayManager *manager,
+ const gchar *atom_name,
+ gboolean copy_name);
+ gchar * (*get_atom_name) (GdkDisplayManager *manager,
+ GdkAtom atom);
/* signals */
void (*display_opened) (GdkDisplayManager *manager,
diff --git a/gdk/x11/gdkdisplaymanager-x11.c b/gdk/x11/gdkdisplaymanager-x11.c
index ddb9e4f..aef1a6d 100644
--- a/gdk/x11/gdkdisplaymanager-x11.c
+++ b/gdk/x11/gdkdisplaymanager-x11.c
@@ -102,6 +102,8 @@ gdk_display_manager_x11_class_init (GdkDisplayManagerX11Class *class)
manager_class->list_displays = gdk_display_manager_x11_list_displays;
manager_class->set_default_display = gdk_display_manager_x11_set_default_display;
manager_class->get_default_display = gdk_display_manager_x11_get_default_display;
+ manager_class->atom_intern = _gdk_x11_display_manager_atom_intern;
+ manager_class->get_atom_name = _gdk_x11_display_manager_get_atom_name;
}
void
diff --git a/gdk/x11/gdkprivate-x11.h b/gdk/x11/gdkprivate-x11.h
index 2d5ba3e..ed95139 100644
--- a/gdk/x11/gdkprivate-x11.h
+++ b/gdk/x11/gdkprivate-x11.h
@@ -159,10 +159,16 @@ void _gdk_x11_device_check_extension_events (GdkDevice *device);
GdkDeviceManager *_gdk_x11_device_manager_new (GdkDisplay *display);
-void _gdk_x11_display_manager_add_display (GdkDisplayManager *manager,
- GdkDisplay *display);
-void _gdk_x11_display_manager_remove_display (GdkDisplayManager *manager,
- GdkDisplay *display);
+void _gdk_x11_display_manager_add_display (GdkDisplayManager *manager,
+ GdkDisplay *display);
+void _gdk_x11_display_manager_remove_display (GdkDisplayManager *manager,
+ GdkDisplay *display);
+
+GdkAtom _gdk_x11_display_manager_atom_intern (GdkDisplayManager *manager,
+ const gchar *atom_name,
+ gboolean copy_name);
+gchar * _gdk_x11_display_manager_get_atom_name (GdkDisplayManager *manager,
+ GdkAtom atom);
GdkCursor *_gdk_x11_display_get_cursor_for_type (GdkDisplay *display,
GdkCursorType type);
diff --git a/gdk/x11/gdkproperty-x11.c b/gdk/x11/gdkproperty-x11.c
index fdc32a4..d0ec2d7 100644
--- a/gdk/x11/gdkproperty-x11.c
+++ b/gdk/x11/gdkproperty-x11.c
@@ -393,87 +393,44 @@ virtual_atom_check_init (void)
if (!virtual_atom_hash)
{
gint i;
-
+
virtual_atom_hash = g_hash_table_new (g_str_hash, g_str_equal);
virtual_atom_array = g_ptr_array_new ();
-
+
for (i = 0; i < G_N_ELEMENTS (xatoms_offset); i++)
- {
- g_ptr_array_add (virtual_atom_array, (gchar *)(xatoms_string + xatoms_offset[i]));
- g_hash_table_insert (virtual_atom_hash, (gchar *)(xatoms_string + xatoms_offset[i]),
- GUINT_TO_POINTER (i));
- }
+ {
+ g_ptr_array_add (virtual_atom_array, (gchar *)(xatoms_string + xatoms_offset[i]));
+ g_hash_table_insert (virtual_atom_hash, (gchar *)(xatoms_string + xatoms_offset[i]),
+ GUINT_TO_POINTER (i));
+ }
}
}
-static GdkAtom
-intern_atom (const gchar *atom_name,
- gboolean dup)
+GdkAtom
+_gdk_x11_display_manager_atom_intern (GdkDisplayManager *manager,
+ const gchar *atom_name,
+ gboolean dup)
{
GdkAtom result;
virtual_atom_check_init ();
-
+
result = GDK_POINTER_TO_ATOM (g_hash_table_lookup (virtual_atom_hash, atom_name));
if (!result)
{
result = INDEX_TO_ATOM (virtual_atom_array->len);
-
+
g_ptr_array_add (virtual_atom_array, dup ? g_strdup (atom_name) : (gchar *)atom_name);
- g_hash_table_insert (virtual_atom_hash,
- g_ptr_array_index (virtual_atom_array,
- ATOM_TO_INDEX (result)),
- GDK_ATOM_TO_POINTER (result));
+ g_hash_table_insert (virtual_atom_hash,
+ g_ptr_array_index (virtual_atom_array,
+ ATOM_TO_INDEX (result)),
+ GDK_ATOM_TO_POINTER (result));
}
return result;
}
-/**
- * gdk_atom_intern:
- * @atom_name: a string.
- * @only_if_exists: if %TRUE, GDK is allowed to not create a new atom, but
- * just return %GDK_NONE if the requested atom doesn't already
- * exists. Currently, the flag is ignored, since checking the
- * existance of an atom is as expensive as creating it.
- *
- * Finds or creates an atom corresponding to a given string.
- *
- * Returns: the atom corresponding to @atom_name.
- */
-GdkAtom
-gdk_atom_intern (const gchar *atom_name,
- gboolean only_if_exists)
-{
- return intern_atom (atom_name, TRUE);
-}
-
-/**
- * gdk_atom_intern_static_string:
- * @atom_name: a static string
- *
- * Finds or creates an atom corresponding to a given string.
- *
- * Note that this function is identical to gdk_atom_intern() except
- * that if a new #GdkAtom is created the string itself is used rather
- * than a copy. This saves memory, but can only be used if the string
- * will <emphasis>always</emphasis> exist. It can be used with statically
- * allocated strings in the main program, but not with statically
- * allocated memory in dynamically loaded modules, if you expect to
- * ever unload the module again (e.g. do not use this function in
- * GTK+ theme engines).
- *
- * Returns: the atom corresponding to @atom_name
- *
- * Since: 2.10
- */
-GdkAtom
-gdk_atom_intern_static_string (const gchar *atom_name)
-{
- return intern_atom (atom_name, FALSE);
-}
-
-static G_CONST_RETURN char *
+static const gchar *
get_atom_name (GdkAtom atom)
{
virtual_atom_check_init ();
@@ -484,18 +441,10 @@ get_atom_name (GdkAtom atom)
return NULL;
}
-/**
- * gdk_atom_name:
- * @atom: a #GdkAtom.
- *
- * Determines the string corresponding to an atom.
- *
- * Returns: a newly-allocated string containing the string
- * corresponding to @atom. When you are done with the
- * return value, you should free it using g_free().
- */
+
gchar *
-gdk_atom_name (GdkAtom atom)
+_gdk_x11_display_manager_get_atom_name (GdkDisplayManager *manager,
+ GdkAtom atom)
{
return g_strdup (get_atom_name (atom));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]