Remove XSMP_ENABLED constructs
[wmaker-crm.git] / src / properties.c
blob82a3cb4b38dde7b5d1a1d841dc8b325b46166016
1 /*
2 * Window Maker window manager
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
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"
34 /* atoms */
35 extern Atom _XA_WM_STATE;
36 extern Atom _XA_WM_CHANGE_STATE;
37 extern Atom _XA_WM_PROTOCOLS;
38 extern Atom _XA_WM_CLIENT_LEADER;
39 extern Atom _XA_WM_TAKE_FOCUS;
40 extern Atom _XA_WM_DELETE_WINDOW;
41 extern Atom _XA_WM_SAVE_YOURSELF;
43 extern Atom _XA_GNUSTEP_WM_ATTR;
44 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
46 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
47 extern Atom _XA_WINDOWMAKER_MENU;
48 extern Atom _XA_WINDOWMAKER_WM_PROTOCOLS;
49 extern Atom _XA_WINDOWMAKER_NOTICEBOARD;
50 extern Atom _XA_WINDOWMAKER_ICON_TILE;
51 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
53 int PropGetNormalHints(Window window, XSizeHints * size_hints, int *pre_iccm)
55 long supplied_hints;
57 if (!XGetWMNormalHints(dpy, window, size_hints, &supplied_hints)) {
58 return False;
60 if (supplied_hints == (USPosition | USSize | PPosition | PSize | PMinSize | PMaxSize
61 | PResizeInc | PAspect)) {
62 *pre_iccm = 1;
63 } else {
64 *pre_iccm = 0;
66 return True;
69 int PropGetWMClass(Window window, char **wm_class, char **wm_instance)
71 XClassHint *class_hint;
73 class_hint = XAllocClassHint();
74 if (XGetClassHint(dpy, window, class_hint) == 0) {
75 *wm_class = NULL;
76 *wm_instance = NULL;
77 XFree(class_hint);
78 return False;
80 *wm_instance = class_hint->res_name;
81 *wm_class = class_hint->res_class;
83 XFree(class_hint);
84 return True;
87 void PropGetProtocols(Window window, WProtocols * prots)
89 Atom *protocols;
90 int count, i;
92 memset(prots, 0, sizeof(WProtocols));
93 if (!XGetWMProtocols(dpy, window, &protocols, &count)) {
94 return;
96 for (i = 0; i < count; i++) {
97 if (protocols[i] == _XA_WM_TAKE_FOCUS)
98 prots->TAKE_FOCUS = 1;
99 else if (protocols[i] == _XA_WM_DELETE_WINDOW)
100 prots->DELETE_WINDOW = 1;
101 else if (protocols[i] == _XA_WM_SAVE_YOURSELF)
102 prots->SAVE_YOURSELF = 1;
103 else if (protocols[i] == _XA_GNUSTEP_WM_MINIATURIZE_WINDOW)
104 prots->MINIATURIZE_WINDOW = 1;
106 XFree(protocols);
109 unsigned char *PropGetCheckProperty(Window window, Atom hint, Atom type, int format, int count, int *retCount)
111 Atom type_ret;
112 int fmt_ret;
113 unsigned long nitems_ret;
114 unsigned long bytes_after_ret;
115 unsigned char *data;
116 int tmp;
118 if (count <= 0)
119 tmp = 0xffffff;
120 else
121 tmp = count;
123 if (XGetWindowProperty(dpy, window, hint, 0, tmp, False, type,
124 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
125 (unsigned char **)&data) != Success || !data)
126 return NULL;
128 if ((type != AnyPropertyType && type != type_ret)
129 || (count > 0 && nitems_ret != count)
130 || (format != 0 && format != fmt_ret)) {
131 XFree(data);
132 return NULL;
135 if (retCount)
136 *retCount = nitems_ret;
138 return data;
141 int PropGetGNUstepWMAttr(Window window, GNUstepWMAttributes ** attr)
143 unsigned long *data;
145 data = (unsigned long *)PropGetCheckProperty(window, _XA_GNUSTEP_WM_ATTR,
146 _XA_GNUSTEP_WM_ATTR, 32, 9, NULL);
148 if (!data)
149 return False;
151 *attr = malloc(sizeof(GNUstepWMAttributes));
152 if (!*attr) {
153 XFree(data);
154 return False;
156 (*attr)->flags = data[0];
157 (*attr)->window_style = data[1];
158 (*attr)->window_level = data[2];
159 (*attr)->reserved = data[3];
160 (*attr)->miniaturize_pixmap = data[4];
161 (*attr)->close_pixmap = data[5];
162 (*attr)->miniaturize_mask = data[6];
163 (*attr)->close_mask = data[7];
164 (*attr)->extra_flags = data[8];
166 XFree(data);
168 return True;
171 void PropSetWMakerProtocols(Window root)
173 Atom protocols[3];
174 int count = 0;
176 protocols[count++] = _XA_WINDOWMAKER_MENU;
177 protocols[count++] = _XA_WINDOWMAKER_WM_FUNCTION;
178 protocols[count++] = _XA_WINDOWMAKER_NOTICEBOARD;
180 XChangeProperty(dpy, root, _XA_WINDOWMAKER_WM_PROTOCOLS, XA_ATOM,
181 32, PropModeReplace, (unsigned char *)protocols, count);
184 void PropSetIconTileHint(WScreen * scr, RImage * image)
186 static Atom imageAtom = 0;
187 unsigned char *tmp;
188 int x, y;
190 if (scr->info_window == None)
191 return;
193 if (!imageAtom) {
195 * WIDTH, HEIGHT (16 bits, MSB First)
196 * array of R,G,B,A bytes
198 imageAtom = XInternAtom(dpy, "_RGBA_IMAGE", False);
201 tmp = malloc(image->width * image->height * 4 + 4);
202 if (!tmp) {
203 wwarning("could not allocate memory to set _WINDOWMAKER_ICON_TILE hint");
204 return;
207 tmp[0] = image->width >> 8;
208 tmp[1] = image->width & 0xff;
209 tmp[2] = image->height >> 8;
210 tmp[3] = image->height & 0xff;
212 if (image->format == RRGBAFormat) {
213 memcpy(&tmp[4], image->data, image->width * image->height * 4);
214 } else {
215 char *ptr = (char *)(tmp + 4);
216 char *src = (char *)image->data;
218 for (y = 0; y < image->height; y++) {
219 for (x = 0; x < image->width; x++) {
220 *ptr++ = *src++;
221 *ptr++ = *src++;
222 *ptr++ = *src++;
223 *ptr++ = 255;
228 XChangeProperty(dpy, scr->info_window, _XA_WINDOWMAKER_ICON_TILE,
229 imageAtom, 8, PropModeReplace, tmp, image->width * image->height * 4 + 4);
230 wfree(tmp);
234 Window PropGetClientLeader(Window window)
236 Window *win;
237 Window leader;
239 win = (Window *) PropGetCheckProperty(window, _XA_WM_CLIENT_LEADER, XA_WINDOW, 32, 1, NULL);
241 if (!win)
242 return None;
244 leader = (Window) * win;
245 XFree(win);
247 return leader;
250 void PropWriteGNUstepWMAttr(Window window, GNUstepWMAttributes * attr)
252 unsigned long data[9];
254 data[0] = attr->flags;
255 data[1] = attr->window_style;
256 data[2] = attr->window_level;
257 data[3] = 0; /* reserved */
258 /* The X protocol says XIDs are 32bit */
259 data[4] = attr->miniaturize_pixmap;
260 data[5] = attr->close_pixmap;
261 data[6] = attr->miniaturize_mask;
262 data[7] = attr->close_mask;
263 data[8] = attr->extra_flags;
264 XChangeProperty(dpy, window, _XA_GNUSTEP_WM_ATTR, _XA_GNUSTEP_WM_ATTR,
265 32, PropModeReplace, (unsigned char *)data, 9);
268 int PropGetWindowState(Window window)
270 long *data;
271 long state;
273 data = (long *)PropGetCheckProperty(window, _XA_WM_STATE, _XA_WM_STATE, 32, 1, NULL);
275 if (!data)
276 return -1;
278 state = *data;
279 XFree(data);
281 return state;
284 void PropCleanUp(Window root)
286 XDeleteProperty(dpy, root, _XA_WINDOWMAKER_WM_PROTOCOLS);
287 XDeleteProperty(dpy, root, _XA_WINDOWMAKER_NOTICEBOARD);
288 XDeleteProperty(dpy, root, XA_WM_ICON_SIZE);