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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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-1999. 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>
31 #include "gdkprivate.h"
34 gdk_atom_intern (const gchar *atom_name,
38 static GHashTable *atom_hash = NULL;
41 atom_hash = g_hash_table_new (g_str_hash, g_str_equal);
43 retval = GPOINTER_TO_UINT (g_hash_table_lookup (atom_hash, atom_name));
46 retval = XInternAtom (gdk_display, atom_name, only_if_exists);
48 g_hash_table_insert (atom_hash,
50 GUINT_TO_POINTER (retval));
57 gdk_atom_name (GdkAtom atom)
61 gint old_error_warnings;
63 /* If this atom doesn't exist, we'll die with an X error unless
64 we take precautions */
66 old_error_warnings = gdk_error_warnings;
67 gdk_error_warnings = 0;
69 t = XGetAtomName (gdk_display, atom);
70 gdk_error_warnings = old_error_warnings;
72 if (gdk_error_code == -1)
90 gdk_property_get (GdkWindow *window,
96 GdkAtom *actual_property_type,
97 gint *actual_format_type,
106 gulong ret_bytes_after;
112 GdkWindowPrivate *private;
114 private = (GdkWindowPrivate*) window;
115 if (private->destroyed)
118 xdisplay = private->xdisplay;
119 xwindow = private->xwindow;
123 xdisplay = gdk_display;
124 xwindow = gdk_root_window;
128 XGetWindowProperty (xdisplay, xwindow, property,
129 offset, (length + 3) / 4, pdelete,
130 type, &ret_prop_type, &ret_format,
131 &ret_nitems, &ret_bytes_after,
134 if ((ret_prop_type == None) && (ret_format == 0)) {
138 if (actual_property_type)
139 *actual_property_type = ret_prop_type;
140 if (actual_format_type)
141 *actual_format_type = ret_format;
143 if ((type != AnyPropertyType) && (ret_prop_type != type))
148 rn = gdk_atom_name(ret_prop_type);
149 pn = gdk_atom_name(type);
150 g_warning("Couldn't match property type %s to %s\n", rn, pn);
151 g_free(rn); g_free(pn);
155 /* FIXME: ignoring bytes_after could have very bad effects */
162 ret_length = ret_nitems;
165 ret_length = 2 * ret_nitems;
168 ret_length = 4 * ret_nitems;
171 g_warning ("unknown property return format: %d", ret_format);
176 *data = g_new (guchar, ret_length);
177 memcpy (*data, ret_data, ret_length);
179 *actual_length = ret_length;
188 gdk_property_change (GdkWindow *window,
201 GdkWindowPrivate *private;
203 private = (GdkWindowPrivate*) window;
204 if (private->destroyed)
207 xdisplay = private->xdisplay;
208 xwindow = private->xwindow;
212 xdisplay = gdk_display;
213 xwindow = gdk_root_window;
216 XChangeProperty (xdisplay, xwindow, property, type,
217 format, mode, data, nelements);
221 gdk_property_delete (GdkWindow *window,
229 GdkWindowPrivate *private;
231 private = (GdkWindowPrivate*) window;
232 if (private->destroyed)
235 xdisplay = private->xdisplay;
236 xwindow = private->xwindow;
240 xdisplay = gdk_display;
241 xwindow = gdk_root_window;
244 XDeleteProperty (xdisplay, xwindow, property);