Code update for Window Maker version 0.50.0
[wmaker-crm.git] / src / properties.c
blobcdd073d3d4b3e063ee0e1869c41ec212f3bea7d3
1 /*
2 * Window Maker window manager
3 *
4 * Copyright (c) 1997, 1998 Alfredo K. Kojima
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 * USA.
22 #include "wconfig.h"
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26 #include <X11/Xatom.h>
27 #include <string.h>
28 #include <stdlib.h>
30 #include "WindowMaker.h"
31 #include "window.h"
32 #include "GNUstep.h"
35 /* atoms */
36 extern Atom _XA_WM_STATE;
37 extern Atom _XA_WM_CHANGE_STATE;
38 extern Atom _XA_WM_PROTOCOLS;
39 extern Atom _XA_WM_CLIENT_LEADER;
40 extern Atom _XA_WM_TAKE_FOCUS;
41 extern Atom _XA_WM_DELETE_WINDOW;
42 extern Atom _XA_WM_SAVE_YOURSELF;
43 #ifdef R6SM
44 extern Atom _XA_WM_WINDOW_ROLE;
45 extern Atom _XA_SM_CLIENT_ID;
46 #endif
49 extern Atom _XA_GNUSTEP_WM_ATTR;
50 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
52 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
53 extern Atom _XA_WINDOWMAKER_MENU;
54 extern Atom _XA_WINDOWMAKER_WM_PROTOCOLS;
57 int
58 PropGetNormalHints(Window window, XSizeHints *size_hints, int *pre_iccm)
60 long supplied_hints;
62 if (!XGetWMNormalHints(dpy, window, size_hints, &supplied_hints)) {
63 return False;
65 if (supplied_hints==(USPosition|USSize|PPosition|PSize|PMinSize|PMaxSize
66 |PResizeInc|PAspect)) {
67 *pre_iccm = 1;
68 } else {
69 *pre_iccm = 0;
71 return True;
75 int
76 PropGetWMClass(Window window, char **wm_class, char **wm_instance)
78 XClassHint *class_hint;
80 class_hint = XAllocClassHint();
81 if (XGetClassHint(dpy,window,class_hint) == 0) {
82 *wm_class = NULL;
83 *wm_instance = NULL;
84 XFree(class_hint);
85 return False;
87 *wm_instance = class_hint->res_name;
88 *wm_class = class_hint->res_class;
90 XFree(class_hint);
91 return True;
95 void
96 PropGetProtocols(Window window, WProtocols *prots)
98 Atom *protocols;
99 int count, i;
101 memset(prots, 0, sizeof(WProtocols));
102 if (!XGetWMProtocols(dpy, window, &protocols, &count)) {
103 return;
105 for (i=0; i<count; i++) {
106 if (protocols[i]==_XA_WM_TAKE_FOCUS)
107 prots->TAKE_FOCUS=1;
108 else if (protocols[i]==_XA_WM_DELETE_WINDOW)
109 prots->DELETE_WINDOW=1;
110 else if (protocols[i]==_XA_WM_SAVE_YOURSELF)
111 prots->SAVE_YOURSELF=1;
112 else if (protocols[i]==_XA_GNUSTEP_WM_MINIATURIZE_WINDOW)
113 prots->MINIATURIZE_WINDOW=1;
115 XFree(protocols);
119 unsigned char*
120 PropGetCheckProperty(Window window, Atom hint, Atom type, int format,
121 int count, int *retCount)
123 Atom type_ret;
124 int fmt_ret;
125 unsigned long nitems_ret;
126 unsigned long bytes_after_ret;
127 unsigned char *data;
128 int tmp;
130 if (count <= 0)
131 tmp = 0xffffff;
133 if (XGetWindowProperty(dpy, window, hint, 0, tmp, False, type,
134 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
135 (unsigned char **)&data)!=Success || !data)
136 return NULL;
138 if ((type!=AnyPropertyType && type!=type_ret)
139 || (count > 0 && nitems_ret != count)
140 || (format != 0 && format != fmt_ret)) {
141 XFree(data);
142 return NULL;
145 if (retCount)
146 *retCount = nitems_ret;
148 return data;
153 PropGetGNUstepWMAttr(Window window, GNUstepWMAttributes **attr)
155 unsigned long *data;
157 data = (unsigned long*)PropGetCheckProperty(window, _XA_GNUSTEP_WM_ATTR,
158 _XA_GNUSTEP_WM_ATTR, 32, 9,
159 NULL);
161 if (!data)
162 return False;
164 *attr = malloc(sizeof(GNUstepWMAttributes));
165 if (!*attr) {
166 XFree(data);
167 return False;
169 (*attr)->flags = data[0];
170 (*attr)->window_style = data[1];
171 (*attr)->window_level = data[2];
172 (*attr)->reserved = data[3];
173 (*attr)->miniaturize_pixmap = data[4];
174 (*attr)->close_pixmap = data[5];
175 (*attr)->miniaturize_mask = data[6];
176 (*attr)->close_mask = data[7];
177 (*attr)->extra_flags = data[8];
179 XFree(data);
181 return True;
186 void
187 PropSetWMakerProtocols(Window root)
189 Atom protocols[2];
190 int count=0;
192 protocols[count++] = _XA_WINDOWMAKER_MENU;
193 protocols[count++] = _XA_WINDOWMAKER_WM_FUNCTION;
195 XChangeProperty(dpy, root, _XA_WINDOWMAKER_WM_PROTOCOLS, XA_ATOM,
196 32, PropModeReplace, (unsigned char *)protocols, count);
200 Window
201 PropGetClientLeader(Window window)
203 Window *win;
204 Window leader;
206 win = (Window*)PropGetCheckProperty(window, _XA_WM_CLIENT_LEADER,
207 XA_WINDOW, 32, 1, NULL);
209 if (!win)
210 return None;
212 leader = (Window)*win;
213 XFree(win);
215 return leader;
219 #ifdef R6SM
220 char*
221 PropGetClientID(Window window)
223 XTextProperty txprop;
225 txprop.value = NULL;
227 if (XGetTextProperty(dpy, window, &txprop, _XA_SM_CLIENT_ID)!=Success) {
228 return NULL;
231 if (txprop.encoding == XA_STRING && txprop.format == 8
232 && txprop.nitems > 0) {
234 return (char*)txprop.value;
235 } else {
237 if (txprop.value)
238 XFree(txprop.value);
240 return NULL;
245 char*
246 PropGetWindowRole(Window window)
248 XTextProperty txprop;
250 txprop.value = NULL;
252 if (XGetTextProperty(dpy, window, &txprop, _XA_WM_WINDOW_ROLE)!=Success) {
253 return NULL;
256 if (txprop.encoding == XA_STRING && txprop.format == 8
257 && txprop.nitems > 0) {
259 return (char*)txprop.value;
260 } else {
262 if (txprop.value)
263 XFree(txprop.value);
265 return NULL;
268 #endif /* R6SM */
271 void
272 PropWriteGNUstepWMAttr(Window window, GNUstepWMAttributes *attr)
274 unsigned long data[9];
276 data[0] = attr->flags;
277 data[1] = attr->window_style;
278 data[2] = attr->window_level;
279 data[3] = 0; /* reserved */
280 /* The X protocol says XIDs are 32bit */
281 data[4] = attr->miniaturize_pixmap;
282 data[5] = attr->close_pixmap;
283 data[6] = attr->miniaturize_mask;
284 data[7] = attr->close_mask;
285 data[8] = attr->extra_flags;
286 XChangeProperty(dpy, window, _XA_GNUSTEP_WM_ATTR, _XA_GNUSTEP_WM_ATTR,
287 32, PropModeReplace, (unsigned char *)data, 9);
291 void
292 PropCleanUp(Window root)
294 XDeleteProperty(dpy, root, _XA_WINDOWMAKER_WM_PROTOCOLS);
296 XDeleteProperty(dpy, root, XA_WM_ICON_SIZE);
298 #ifdef KWM_HINTS
299 XDeleteProperty(dpy, root, XInternAtom(dpy, "KWM_RUNNING", False));
300 #endif