Updating to version 0.20.2
[wmaker-crm.git] / src / properties.c
blob42fa2d639b1ea9133c0a3855eb0d0ea5a092cdb8
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"
33 #ifdef MWM_HINTS
34 # include "motif.h"
35 #endif
38 /* atoms */
39 extern Atom _XA_WM_STATE;
40 extern Atom _XA_WM_CHANGE_STATE;
41 extern Atom _XA_WM_PROTOCOLS;
42 extern Atom _XA_WM_CLIENT_LEADER;
43 extern Atom _XA_WM_TAKE_FOCUS;
44 extern Atom _XA_WM_DELETE_WINDOW;
45 extern Atom _XA_WM_SAVE_YOURSELF;
47 extern Atom _XA_GNUSTEP_WM_ATTR;
48 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
50 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
51 extern Atom _XA_WINDOWMAKER_MENU;
52 extern Atom _XA_WINDOWMAKER_WM_PROTOCOLS;
55 int
56 PropGetNormalHints(Window window, XSizeHints *size_hints, int *pre_iccm)
58 long supplied_hints;
60 if (!XGetWMNormalHints(dpy, window, size_hints, &supplied_hints)) {
61 return False;
63 if (supplied_hints==(USPosition|USSize|PPosition|PSize|PMinSize|PMaxSize
64 |PResizeInc|PAspect)) {
65 *pre_iccm = 1;
66 } else {
67 *pre_iccm = 0;
69 return True;
73 int
74 PropGetWMClass(Window window, char **wm_class, char **wm_instance)
76 XClassHint *class_hint;
78 class_hint = XAllocClassHint();
79 if (XGetClassHint(dpy,window,class_hint) == 0) {
80 *wm_class = NULL;
81 *wm_instance = NULL;
82 XFree(class_hint);
83 return False;
85 *wm_instance = class_hint->res_name;
86 *wm_class = class_hint->res_class;
88 XFree(class_hint);
89 return True;
92 void
93 PropGetProtocols(Window window, WProtocols *prots)
95 Atom *protocols;
96 int count, i;
98 memset(prots, 0, sizeof(WProtocols));
99 if (!XGetWMProtocols(dpy, window, &protocols, &count)) {
100 return;
102 for (i=0; i<count; i++) {
103 if (protocols[i]==_XA_WM_TAKE_FOCUS)
104 prots->TAKE_FOCUS=1;
105 else if (protocols[i]==_XA_WM_DELETE_WINDOW)
106 prots->DELETE_WINDOW=1;
107 else if (protocols[i]==_XA_WM_SAVE_YOURSELF)
108 prots->SAVE_YOURSELF=1;
109 else if (protocols[i]==_XA_GNUSTEP_WM_MINIATURIZE_WINDOW)
110 prots->MINIATURIZE_WINDOW=1;
112 XFree(protocols);
117 PropGetGNUstepWMAttr(Window window, GNUstepWMAttributes **attr)
119 Atom type_ret;
120 int fmt_ret;
121 unsigned long nitems_ret;
122 unsigned long bytes_after_ret;
123 CARD32 *data;
125 if (XGetWindowProperty(dpy, window, _XA_GNUSTEP_WM_ATTR, 0, 9,
126 False, _XA_GNUSTEP_WM_ATTR,
127 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
128 (unsigned char **)&data)!=Success || !data)
129 return False;
130 if (type_ret!=_XA_GNUSTEP_WM_ATTR || !data || fmt_ret!=32)
131 return False;
133 *attr = malloc(sizeof(GNUstepWMAttributes));
134 if (!*attr) {
135 XFree(data);
136 return False;
138 (*attr)->flags = data[0];
139 (*attr)->window_style = data[1];
140 (*attr)->window_level = data[2];
141 (*attr)->reserved = data[3];
142 (*attr)->miniaturize_pixmap = data[4];
143 (*attr)->close_pixmap = data[5];
144 (*attr)->miniaturize_mask = data[6];
145 (*attr)->close_mask = data[7];
146 (*attr)->extra_flags = data[8];
148 XFree(data);
150 return True;
156 #ifdef MWM_HINTS
158 PropGetMotifWMHints(Window window, MWMHints **mwmhints)
160 Atom type_ret;
161 int fmt_ret;
162 unsigned long nitems_ret;
163 unsigned long bytes_after_ret;
164 CARD32 *data;
166 if (XGetWindowProperty(dpy, window, _XA_MOTIF_WM_HINTS, 0,
167 PROP_MWM_HINTS_ELEMENTS,
168 False, _XA_MOTIF_WM_HINTS,
169 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
170 (unsigned char **)&data)!=Success)
171 return 0;
173 if (type_ret!=_XA_MOTIF_WM_HINTS || fmt_ret!=32
174 || nitems_ret!=PROP_MWM_HINTS_ELEMENTS || !data)
175 return 0;
177 *mwmhints = malloc(sizeof(MWMHints));
178 if (!*mwmhints) {
179 XFree(data);
180 return 0;
183 (*mwmhints)->flags = data[0];
184 (*mwmhints)->functions = data[1];
185 (*mwmhints)->decorations = data[2];
186 (*mwmhints)->inputMode = data[3];
188 XFree(data);
190 if (type_ret==_XA_MOTIF_WM_HINTS)
191 return 1;
192 else
193 return 0;
195 #endif /* MWM_HINTS */
198 void
199 PropSetWMakerProtocols(Window root)
201 Atom protocols[2];
202 int count=0;
204 protocols[count++] = _XA_WINDOWMAKER_MENU;
205 protocols[count++] = _XA_WINDOWMAKER_WM_FUNCTION;
207 XChangeProperty(dpy, root, _XA_WINDOWMAKER_WM_PROTOCOLS, XA_ATOM,
208 32, PropModeReplace, (unsigned char *)protocols, count);
213 PropGetClientLeader(Window window, Window *leader)
215 Atom type_ret;
216 int fmt_ret;
217 unsigned long nitems_ret;
218 unsigned long bytes_after_ret;
219 Window *win;
221 if (XGetWindowProperty(dpy, window, _XA_WM_CLIENT_LEADER, 0, 4,
222 False, AnyPropertyType,
223 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
224 (unsigned char**)&win)!=Success)
225 return 0;
227 if (!win) return 0;
228 *leader = (Window)*win;
229 XFree(win);
230 return 1;
235 void
236 PropWriteGNUstepWMAttr(Window window, GNUstepWMAttributes *attr)
238 CARD32 data[9];
240 /* handle idiot compilers where array of CARD32 != struct of CARD32 */
241 data[0] = attr->flags;
242 data[1] = attr->window_style;
243 data[2] = attr->window_level;
244 data[3] = 0; /* reserved */
245 /* The X protocol says XIDs are 32bit */
246 data[4] = attr->miniaturize_pixmap;
247 data[5] = attr->close_pixmap;
248 data[6] = attr->miniaturize_mask;
249 data[7] = attr->close_mask;
250 data[8] = attr->extra_flags;
251 XChangeProperty(dpy, window, _XA_GNUSTEP_WM_ATTR, _XA_GNUSTEP_WM_ATTR,
252 32, PropModeReplace, (unsigned char *)data, 9);
256 void
257 PropCleanUp(Window root)
259 XDeleteProperty(dpy, root, _XA_WINDOWMAKER_WM_PROTOCOLS);
261 XDeleteProperty(dpy, root, XA_WM_ICON_SIZE);