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.
20 #include <X11/Xatom.h>
23 #include "gdkprivate.h"
26 gdk_atom_intern (const gchar *atom_name,
30 static GHashTable *atom_hash = NULL;
33 atom_hash = g_hash_table_new (g_str_hash, g_str_equal);
35 retval = GPOINTER_TO_UINT (g_hash_table_lookup (atom_hash, atom_name));
37 retval = XInternAtom (gdk_display, atom_name, only_if_exists);
43 gdk_atom_name (GdkAtom atom)
47 gint old_error_warnings;
49 /* If this atom doesn't exist, we'll die with an X error unless
50 we take precautions */
52 old_error_warnings = gdk_error_warnings;
53 gdk_error_warnings = 0;
55 t = XGetAtomName (gdk_display, atom);
56 gdk_error_warnings = old_error_warnings;
58 if (gdk_error_code == -1)
76 gdk_property_get (GdkWindow *window,
82 GdkAtom *actual_property_type,
83 gint *actual_format_type,
92 gulong ret_bytes_after;
98 GdkWindowPrivate *private;
100 private = (GdkWindowPrivate*) window;
101 if (private->destroyed)
104 xdisplay = private->xdisplay;
105 xwindow = private->xwindow;
109 xdisplay = gdk_display;
110 xwindow = gdk_root_window;
114 XGetWindowProperty (xdisplay, xwindow, property,
115 offset, (length + 3) / 4, pdelete,
116 type, &ret_prop_type, &ret_format,
117 &ret_nitems, &ret_bytes_after,
120 if ((ret_prop_type == None) && (ret_format == 0)) {
124 if (actual_property_type)
125 *actual_property_type = ret_prop_type;
126 if (actual_format_type)
127 *actual_format_type = ret_format;
129 if ((type != AnyPropertyType) && (ret_prop_type != type))
134 rn = gdk_atom_name(ret_prop_type);
135 pn = gdk_atom_name(type);
136 g_warning("Couldn't match property type %s to %s\n", rn, pn);
137 g_free(rn); g_free(pn);
141 /* FIXME: ignoring bytes_after could have very bad effects */
148 ret_length = ret_nitems;
151 ret_length = 2 * ret_nitems;
154 ret_length = 4 * ret_nitems;
157 g_warning ("unknown property return format: %d", ret_format);
162 *data = g_new (guchar, ret_length);
163 memcpy (*data, ret_data, ret_length);
165 *actual_length = ret_length;
174 gdk_property_change (GdkWindow *window,
187 GdkWindowPrivate *private;
189 private = (GdkWindowPrivate*) window;
190 if (private->destroyed)
193 xdisplay = private->xdisplay;
194 xwindow = private->xwindow;
198 xdisplay = gdk_display;
199 xwindow = gdk_root_window;
202 XChangeProperty (xdisplay, xwindow, property, type,
203 format, mode, data, nelements);
207 gdk_property_delete (GdkWindow *window,
215 GdkWindowPrivate *private;
217 private = (GdkWindowPrivate*) window;
218 if (private->destroyed)
221 xdisplay = private->xdisplay;
222 xwindow = private->xwindow;
226 xdisplay = gdk_display;
227 xwindow = gdk_root_window;
230 XDeleteProperty (xdisplay, xwindow, property);