1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include <X11/Xatom.h>
32 #include "gdkproperty.h"
33 #include "gdkprivate.h"
36 gdk_atom_intern (const gchar *atom_name,
37 gboolean only_if_exists)
40 static GHashTable *atom_hash = NULL;
42 g_return_val_if_fail (atom_name != NULL, GDK_NONE);
45 atom_hash = g_hash_table_new (g_str_hash, g_str_equal);
47 retval = GPOINTER_TO_UINT (g_hash_table_lookup (atom_hash, atom_name));
50 retval = XInternAtom (gdk_display, atom_name, only_if_exists);
53 g_hash_table_insert (atom_hash,
55 GUINT_TO_POINTER (retval));
62 gdk_atom_name (GdkAtom atom)
66 gint old_error_warnings;
68 /* If this atom doesn't exist, we'll die with an X error unless
69 we take precautions */
71 old_error_warnings = gdk_error_warnings;
72 gdk_error_warnings = 0;
74 t = XGetAtomName (gdk_display, atom);
75 gdk_error_warnings = old_error_warnings;
95 gdk_property_get (GdkWindow *window,
101 GdkAtom *actual_property_type,
102 gint *actual_format_type,
111 gulong ret_bytes_after;
115 g_return_val_if_fail (!window || GDK_IS_WINDOW (window), FALSE);
119 if (GDK_WINDOW_DESTROYED (window))
122 xdisplay = GDK_WINDOW_XDISPLAY (window);
123 xwindow = GDK_WINDOW_XID (window);
127 xdisplay = gdk_display;
128 xwindow = gdk_root_window;
132 XGetWindowProperty (xdisplay, xwindow, property,
133 offset, (length + 3) / 4, pdelete,
134 type, &ret_prop_type, &ret_format,
135 &ret_nitems, &ret_bytes_after,
138 if ((ret_prop_type == None) && (ret_format == 0)) {
142 if (actual_property_type)
143 *actual_property_type = ret_prop_type;
144 if (actual_format_type)
145 *actual_format_type = ret_format;
147 if ((type != AnyPropertyType) && (ret_prop_type != type))
152 rn = gdk_atom_name(ret_prop_type);
153 pn = gdk_atom_name(type);
154 g_warning("Couldn't match property type %s to %s\n", rn, pn);
155 g_free(rn); g_free(pn);
159 /* FIXME: ignoring bytes_after could have very bad effects */
166 ret_length = ret_nitems;
169 ret_length = sizeof(short) * ret_nitems;
172 ret_length = sizeof(long) * ret_nitems;
175 g_warning ("unknown property return format: %d", ret_format);
180 *data = g_new (guchar, ret_length);
181 memcpy (*data, ret_data, ret_length);
183 *actual_length = ret_length;
192 gdk_property_change (GdkWindow *window,
203 g_return_if_fail (!window || GDK_IS_WINDOW (window));
207 if (GDK_WINDOW_DESTROYED (window))
210 xdisplay = GDK_WINDOW_XDISPLAY (window);
211 xwindow = GDK_WINDOW_XID (window);
215 xdisplay = gdk_display;
216 xwindow = gdk_root_window;
219 XChangeProperty (xdisplay, xwindow, property, type,
220 format, mode, (guchar *)data, nelements);
224 gdk_property_delete (GdkWindow *window,
230 g_return_if_fail (!window || GDK_IS_WINDOW (window));
234 if (GDK_WINDOW_DESTROYED (window))
237 xdisplay = GDK_WINDOW_XDISPLAY (window);
238 xwindow = GDK_WINDOW_XID (window);
242 xdisplay = gdk_display;
243 xwindow = gdk_root_window;
246 XDeleteProperty (xdisplay, xwindow, property);