25 |
#include <X11/Xmd.h> |
#include <X11/Xmd.h> |
26 |
#include <stdlib.h> |
#include <stdlib.h> |
27 |
#include <stdio.h> |
#include <stdio.h> |
28 |
|
#include <string.h> |
29 |
#include "hints.h" |
#include "hints.h" |
30 |
|
#include "xmalloc.h" |
31 |
|
|
32 |
Atom wm_state, wm_change_state, wm_delete_window, wm_protocols; |
Atom wm_state, wm_change_state, wm_delete_window, wm_protocols; |
33 |
Atom motif_wm_hints; |
Atom motif_wm_hints; |
35 |
win_workspace_count, win_desktop_button_proxy, win_supporting_wm_check, |
win_workspace_count, win_desktop_button_proxy, win_supporting_wm_check, |
36 |
gnome_panel_desktop_area; |
gnome_panel_desktop_area; |
37 |
Atom net_atoms[NET_ATOM_COUNT]; |
Atom net_atoms[NET_ATOM_COUNT]; |
38 |
|
Display *dpy; |
39 |
|
|
40 |
void |
void |
41 |
initICCCMHints (Display * dpy) |
initHints (Display * d) |
42 |
|
{ |
43 |
|
dpy = d; |
44 |
|
initICCCMHints (); |
45 |
|
initMotifHints (); |
46 |
|
initGnomeHints (); |
47 |
|
initNETHints (); |
48 |
|
} |
49 |
|
|
50 |
|
void |
51 |
|
initICCCMHints () |
52 |
{ |
{ |
53 |
#ifdef DEBUG |
#ifdef DEBUG |
54 |
printf ("entering initICCCMHints\n"); |
printf ("entering initICCCMHints\n"); |
61 |
} |
} |
62 |
|
|
63 |
void |
void |
64 |
initNETHints (Display * dpy) |
initNETHints () |
65 |
{ |
{ |
66 |
Window root; |
Window root; |
67 |
#ifdef DEBUG |
#ifdef DEBUG |
111 |
net_atoms[NET_WM_STATE_FULLSCREEN] = |
net_atoms[NET_WM_STATE_FULLSCREEN] = |
112 |
XInternAtom (dpy, "_NET_WM_STATE_FULLSCREEN", False); |
XInternAtom (dpy, "_NET_WM_STATE_FULLSCREEN", False); |
113 |
net_atoms[NET_WM_NAME] = XInternAtom (dpy, "_NET_WM_NAME", False); |
net_atoms[NET_WM_NAME] = XInternAtom (dpy, "_NET_WM_NAME", False); |
114 |
net_atoms[NET_NUMBER_OF_DESKTOPS] = XInternAtom (dpy, "_NET_NUMBER_OF_DESKTOPS", False); |
net_atoms[NET_NUMBER_OF_DESKTOPS] = |
115 |
net_atoms[NET_CURRENT_DESKTOP] = XInternAtom (dpy, "_NET_CURRENT_DESKTOP", False); |
XInternAtom (dpy, "_NET_NUMBER_OF_DESKTOPS", False); |
116 |
|
net_atoms[NET_CURRENT_DESKTOP] = |
117 |
|
XInternAtom (dpy, "_NET_CURRENT_DESKTOP", False); |
118 |
XChangeProperty (dpy, root, XInternAtom (dpy, "_NET_SUPPORTED", False), |
XChangeProperty (dpy, root, XInternAtom (dpy, "_NET_SUPPORTED", False), |
119 |
XA_ATOM, 32, PropModeReplace, (unsigned char *) net_atoms, |
XA_ATOM, 32, PropModeReplace, (unsigned char *) net_atoms, |
120 |
NET_ATOM_COUNT); |
NET_ATOM_COUNT); |
121 |
} |
} |
122 |
|
|
123 |
|
void |
124 |
|
initMotifHints () |
125 |
|
{ |
126 |
|
#ifdef DEBUG |
127 |
|
printf ("entering initMotifHints\n"); |
128 |
|
#endif |
129 |
|
|
130 |
|
motif_wm_hints = XInternAtom (dpy, "_MOTIF_WM_HINTS", False); |
131 |
|
} |
132 |
|
|
133 |
|
void |
134 |
|
initGnomeHints () |
135 |
|
{ |
136 |
|
Window root; |
137 |
|
|
138 |
|
#ifdef DEBUG |
139 |
|
printf ("entering initGnomeHints\n"); |
140 |
|
#endif |
141 |
|
|
142 |
|
root = XDefaultRootWindow (dpy); |
143 |
|
win_hints = XInternAtom (dpy, "_WIN_HINTS", False); |
144 |
|
win_state = XInternAtom (dpy, "_WIN_STATE", False); |
145 |
|
win_client_list = XInternAtom (dpy, "_WIN_CLIENT_LIST", False); |
146 |
|
win_layer = XInternAtom (dpy, "_WIN_LAYER", False); |
147 |
|
win_workspace = XInternAtom (dpy, "_WIN_WORKSPACE", False); |
148 |
|
win_workspace_count = XInternAtom (dpy, "_WIN_WORKSPACE_COUNT", False); |
149 |
|
win_desktop_button_proxy = |
150 |
|
XInternAtom (dpy, "_WIN_DESKTOP_BUTTON_PROXY", False); |
151 |
|
win_supporting_wm_check = |
152 |
|
XInternAtom (dpy, "_WIN_SUPPORTING_WM_CHECK", False); |
153 |
|
gnome_panel_desktop_area = |
154 |
|
XInternAtom (dpy, "GNOME_PANEL_DESKTOP_AREA", False); |
155 |
|
} |
156 |
|
|
157 |
long |
long |
158 |
getWMState (Display * dpy, Window w) |
getWMState (Window w) |
159 |
{ |
{ |
160 |
Atom real_type; |
unsigned long *data = NULL, state = WithdrawnState; |
|
int real_format; |
|
|
unsigned long items_read, items_left; |
|
|
long *data = NULL, state = WithdrawnState; |
|
161 |
|
|
162 |
#ifdef DEBUG |
#ifdef DEBUG |
163 |
printf ("entering getWmState\n"); |
printf ("entering getWmState\n"); |
164 |
#endif |
#endif |
165 |
|
|
166 |
if (XGetWindowProperty |
data = getPropData (w, wm_state, wm_state, NULL); |
167 |
(dpy, w, wm_state, 0L, 2L, False, wm_state, &real_type, &real_format, |
if (data) |
|
&items_read, &items_left, (unsigned char **) &data) == Success && |
|
|
items_read) |
|
168 |
{ |
{ |
169 |
state = *data; |
state = *data; |
170 |
XFree (data); |
XFree (data); |
173 |
} |
} |
174 |
|
|
175 |
void |
void |
176 |
setWMState (Display * dpy, Window w, long state) |
setWMState (Window w, long state) |
177 |
{ |
{ |
178 |
CARD32 data[2]; |
CARD32 data[2]; |
179 |
|
|
188 |
(unsigned char *) data, 2); |
(unsigned char *) data, 2); |
189 |
} |
} |
190 |
|
|
|
void |
|
|
initMotifHints (Display * dpy) |
|
|
{ |
|
|
#ifdef DEBUG |
|
|
printf ("entering initMotifHints\n"); |
|
|
#endif |
|
|
|
|
|
motif_wm_hints = XInternAtom (dpy, "_MOTIF_WM_HINTS", False); |
|
|
} |
|
|
|
|
191 |
PropMwmHints * |
PropMwmHints * |
192 |
getMotifHints (Display * dpy, Window w) |
getMotifHints (Window w) |
193 |
{ |
{ |
|
Atom real_type; |
|
|
int real_format; |
|
|
unsigned long items_read, items_left; |
|
|
PropMwmHints *data = NULL; |
|
|
|
|
194 |
#ifdef DEBUG |
#ifdef DEBUG |
195 |
printf ("entering getMotifHints\n"); |
printf ("entering getMotifHints\n"); |
196 |
#endif |
#endif |
197 |
|
|
198 |
if (XGetWindowProperty |
return getPropData (w, motif_wm_hints, motif_wm_hints, NULL); |
|
(dpy, w, motif_wm_hints, 0L, 20L, False, motif_wm_hints, &real_type, |
|
|
&real_format, &items_read, &items_left, |
|
|
(unsigned char **) &data) == Success && items_read) |
|
|
return data; |
|
|
else |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
void |
|
|
initGnomeHints (Display * dpy) |
|
|
{ |
|
|
Window root; |
|
|
|
|
|
#ifdef DEBUG |
|
|
printf ("entering initGnomeHints\n"); |
|
|
#endif |
|
|
|
|
|
root = XDefaultRootWindow (dpy); |
|
|
win_hints = XInternAtom (dpy, "_WIN_HINTS", False); |
|
|
win_state = XInternAtom (dpy, "_WIN_STATE", False); |
|
|
win_client_list = XInternAtom (dpy, "_WIN_CLIENT_LIST", False); |
|
|
win_layer = XInternAtom (dpy, "_WIN_LAYER", False); |
|
|
win_workspace = XInternAtom (dpy, "_WIN_WORKSPACE", False); |
|
|
win_workspace_count = XInternAtom (dpy, "_WIN_WORKSPACE_COUNT", False); |
|
|
win_desktop_button_proxy = |
|
|
XInternAtom (dpy, "_WIN_DESKTOP_BUTTON_PROXY", False); |
|
|
win_supporting_wm_check = |
|
|
XInternAtom (dpy, "_WIN_SUPPORTING_WM_CHECK", False); |
|
|
gnome_panel_desktop_area = |
|
|
XInternAtom (dpy, "GNOME_PANEL_DESKTOP_AREA", False); |
|
199 |
} |
} |
200 |
|
|
201 |
int |
int |
202 |
getGnomeHint (Display * dpy, Window w, Atom a, long *value) |
getGnomeHint (Window w, Atom a, long *value) |
203 |
{ |
{ |
204 |
Atom real_type; |
int success = False; |
|
int real_format, success = False; |
|
|
unsigned long items_read, items_left; |
|
205 |
long *data = NULL; |
long *data = NULL; |
206 |
|
|
207 |
#ifdef DEBUG |
#ifdef DEBUG |
213 |
else |
else |
214 |
*value = 0; |
*value = 0; |
215 |
|
|
216 |
if (XGetWindowProperty |
data = getPropData (w, a, XA_CARDINAL, NULL); |
217 |
(dpy, w, a, 0L, 1L, False, XA_CARDINAL, &real_type, &real_format, |
if (data) |
|
&items_read, &items_left, (unsigned char **) &data) == Success && |
|
|
items_read) |
|
218 |
{ |
{ |
219 |
*value = *data; |
*value = *data; |
220 |
success = True; |
success = True; |
224 |
} |
} |
225 |
|
|
226 |
void |
void |
227 |
setGnomeHint (Display * dpy, Window w, Atom a, long value) |
setGnomeHint (Window w, Atom a, long value) |
228 |
{ |
{ |
229 |
#ifdef DEBUG |
#ifdef DEBUG |
230 |
printf ("entering setGnomeHint\n"); |
printf ("entering setGnomeHint\n"); |
235 |
} |
} |
236 |
|
|
237 |
void |
void |
238 |
getEWMHState (Display * dpy, Window w, long *value) |
getEWMHState (Window w, long *value) |
239 |
{ |
{ |
240 |
unsigned long *data; |
unsigned long *data; |
241 |
unsigned long items = 0; |
unsigned long items = 0; |
242 |
unsigned long i; |
unsigned long i; |
243 |
|
|
244 |
data = getPropData (dpy, w, net_atoms[NET_WM_STATE], XA_ATOM, &items); |
data = getPropData (w, net_atoms[NET_WM_STATE], XA_ATOM, &items); |
245 |
if (data) |
if (data) |
246 |
{ |
{ |
247 |
for (i = 0; i < items; i++) |
for (i = 0; i < items; i++) |
251 |
XGetAtomName (dpy, net_atoms[NET_WM_STATE_STICKY]))) |
XGetAtomName (dpy, net_atoms[NET_WM_STATE_STICKY]))) |
252 |
*value |= WIN_STATE_STICKY; |
*value |= WIN_STATE_STICKY; |
253 |
} |
} |
254 |
|
XFree (data); |
255 |
} |
} |
256 |
} |
} |
257 |
|
|
258 |
void |
void |
259 |
getGnomeDesktopMargins (Display * dpy, CARD32 * margins) |
getGnomeDesktopMargins (CARD32 * margins) |
260 |
{ |
{ |
261 |
Atom real_type; |
unsigned long items_read; |
|
int real_format; |
|
|
unsigned long items_read, items_left; |
|
262 |
CARD32 *data = NULL; |
CARD32 *data = NULL; |
263 |
|
|
264 |
#ifdef DEBUG |
#ifdef DEBUG |
265 |
printf ("entering getGnomeDesktopMargins\n"); |
printf ("entering getGnomeDesktopMargins\n"); |
266 |
#endif |
#endif |
267 |
|
|
268 |
if (XGetWindowProperty |
data = |
269 |
(dpy, XDefaultRootWindow (dpy), gnome_panel_desktop_area, 0L, 4L, False, |
getPropData (XDefaultRootWindow (dpy), gnome_panel_desktop_area, |
270 |
XA_CARDINAL, &real_type, &real_format, &items_read, &items_left, |
XA_CARDINAL, &items_read); |
271 |
(unsigned char **) &data) == Success && items_read >= 4) |
if (data && items_read >= 4) |
272 |
{ |
{ |
273 |
margins[0] = data[0]; |
margins[0] = data[0]; |
274 |
margins[1] = data[1]; |
margins[1] = data[1]; |
286 |
} |
} |
287 |
|
|
288 |
int |
int |
289 |
typeDesktop (Display * dpy, Window w) |
typeDesktop (Window w) |
290 |
{ |
{ |
291 |
return typeEWMH (dpy, w, "_NET_WM_WINDOW_TYPE_DESKTOP"); |
return typeEWMH (w, "_NET_WM_WINDOW_TYPE_DESKTOP"); |
292 |
} |
} |
293 |
|
|
294 |
int |
int |
295 |
typeDock (Display * dpy, Window w) |
typeDock (Window w) |
296 |
{ |
{ |
297 |
return typeEWMH (dpy, w, "_NET_WM_WINDOW_TYPE_DOCK"); |
return typeEWMH (w, "_NET_WM_WINDOW_TYPE_DOCK"); |
298 |
} |
} |
299 |
|
|
300 |
int |
int |
301 |
typeEWMH (Display * dpy, Window w, char *type) |
typeEWMH (Window w, char *type) |
302 |
{ |
{ |
303 |
unsigned long *data; |
unsigned long *data; |
304 |
unsigned long items = 0; |
unsigned long items = 0; |
308 |
printf ("entering typeEWMH\n"); |
printf ("entering typeEWMH\n"); |
309 |
#endif |
#endif |
310 |
|
|
311 |
data = getPropData (dpy, w, net_atoms[NET_WM_WINDOW_TYPE], XA_ATOM, &items); |
data = getPropData (w, net_atoms[NET_WM_WINDOW_TYPE], XA_ATOM, &items); |
312 |
if (data) |
if (data) |
313 |
{ |
{ |
314 |
char *name; |
char *name; |
323 |
return ret; |
return ret; |
324 |
} |
} |
325 |
|
|
326 |
void |
void * |
327 |
*getPropData (Display * dpy, Window win, Atom prop, Atom type, |
getPropData (Window w, Atom prop, Atom type, unsigned long *items_ret) |
|
unsigned long *items_ret) |
|
328 |
{ |
{ |
329 |
Atom type_ret; |
Atom type_ret; |
330 |
int format_ret; |
int format_ret; |
334 |
#ifdef DEBUG |
#ifdef DEBUG |
335 |
printf ("entering getPropData\n"); |
printf ("entering getPropData\n"); |
336 |
#endif |
#endif |
337 |
|
if (items_ret == NULL) |
338 |
|
items_ret = (unsigned long *) xmalloc (sizeof (unsigned long)); |
339 |
|
|
340 |
prop_data = 0; |
prop_data = 0; |
341 |
|
|
342 |
XGetWindowProperty (dpy, win, prop, 0, 0x7fffffff, False, |
XGetWindowProperty (dpy, w, prop, 0, 0x7fffffff, False, |
343 |
type, &type_ret, &format_ret, items_ret, |
type, &type_ret, &format_ret, items_ret, |
344 |
&after_ret, &prop_data); |
&after_ret, &prop_data); |
345 |
|
|
346 |
return prop_data; |
if (prop_data && *items_ret) |
347 |
|
return prop_data; |
348 |
|
else |
349 |
|
return NULL; |
350 |
} |
} |
351 |
|
|
352 |
int |
int |