1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <string.h>
#include "gdk.h"
#include "gdkprivate.h"
GdkAtom
gdk_atom_intern (const gchar *atom_name,
gint only_if_exists)
{
return XInternAtom (gdk_display, atom_name, only_if_exists);
}
gchar *
gdk_atom_name (GdkAtom atom)
{
gchar *t;
gchar *name;
/* If this atom doesn't exist, we'll die with an X error unless
we take precautions */
gdk_error_warnings = 0;
t = XGetAtomName (gdk_display, atom);
gdk_error_warnings = 1;
if (gdk_error_code == -1)
{
return NULL;
}
else
{
name = g_strdup (t);
XFree (t);
return name;
}
}
gint
gdk_property_get (GdkWindow *window,
GdkAtom property,
GdkAtom type,
gulong offset,
gulong length,
gint pdelete,
GdkAtom *actual_property_type,
gint *actual_format_type,
gint *actual_length,
guchar **data)
{
GdkWindowPrivate *private;
Display *xdisplay;
Window xwindow;
Atom ret_prop_type;
gint ret_format;
gulong ret_nitems;
gulong ret_bytes_after;
gulong ret_length;
guchar *ret_data;
if (window)
{
private = (GdkWindowPrivate*) window;
xdisplay = private->xdisplay;
xwindow = private->xwindow;
}
else
{
xdisplay = gdk_display;
xwindow = gdk_root_window;
}
XGetWindowProperty (xdisplay, xwindow, property,
offset, (length + 3) / 4, pdelete,
type, &ret_prop_type, &ret_format,
&ret_nitems, &ret_bytes_after,
&ret_data);
if ((ret_prop_type == None) && (ret_format == 0)) {
g_warning("XGetWindowProperty failed\n");
return FALSE;
}
if (actual_property_type)
*actual_property_type = ret_prop_type;
if (actual_format_type)
*actual_format_type = ret_format;
if (ret_prop_type != type)
{
gchar *rn, *pn;
XFree (ret_data);
rn = gdk_atom_name(ret_prop_type);
pn = gdk_atom_name(type);
g_warning("Couldn't match property type %s to %s\n", rn, pn);
g_free(rn); g_free(pn);
return FALSE;
}
/* FIXME: ignoring bytes_after could have very bad effects */
if (data)
{
switch (ret_format)
{
case 8:
ret_length = ret_nitems;
break;
case 16:
ret_length = 2 * ret_nitems;
break;
case 32:
ret_length = 4 * ret_nitems;
break;
default:
g_warning ("unknown property return format: %d", ret_format);
XFree (ret_data);
return FALSE;
}
*data = g_new (guchar, ret_length);
memcpy (*data, ret_data, ret_length);
if (actual_length)
*actual_length = ret_length;
}
XFree (ret_data);
return TRUE;
}
void
gdk_property_change (GdkWindow *window,
GdkAtom property,
GdkAtom type,
gint format,
GdkPropMode mode,
guchar *data,
gint nelements)
{
GdkWindowPrivate *private;
Display *xdisplay;
Window xwindow;
if (window)
{
private = (GdkWindowPrivate*) window;
xdisplay = private->xdisplay;
xwindow = private->xwindow;
}
else
{
xdisplay = gdk_display;
xwindow = gdk_root_window;
}
XChangeProperty (xdisplay, xwindow, property, type,
format, mode, data, nelements);
}
void
gdk_property_delete (GdkWindow *window,
GdkAtom property)
{
GdkWindowPrivate *private;
Display *xdisplay;
Window xwindow;
if (window)
{
private = (GdkWindowPrivate*) window;
xdisplay = private->xdisplay;
xwindow = private->xwindow;
}
else
{
xdisplay = gdk_display;
xwindow = gdk_root_window;
}
XDeleteProperty (xdisplay, xwindow, property);
}
|