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,
25 #include <X11/Xutil.h>
26 #include <X11/Xatom.h>
30 #include "WindowMaker.h"
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
;
44 extern Atom _XA_WM_WINDOW_ROLE
;
45 extern Atom _XA_SM_CLIENT_ID
;
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
;
55 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
56 extern Atom _XA_WINDOWMAKER_ICON_TILE
;
57 extern Atom _XA_WINDOWMAKER_ICON_SIZE
;
60 PropGetNormalHints(Window window
, XSizeHints
*size_hints
, int *pre_iccm
)
64 if (!XGetWMNormalHints(dpy
, window
, size_hints
, &supplied_hints
)) {
67 if (supplied_hints
==(USPosition
|USSize
|PPosition
|PSize
|PMinSize
|PMaxSize
68 |PResizeInc
|PAspect
)) {
78 PropGetWMClass(Window window
, char **wm_class
, char **wm_instance
)
80 XClassHint
*class_hint
;
82 class_hint
= XAllocClassHint();
83 if (XGetClassHint(dpy
,window
,class_hint
) == 0) {
89 *wm_instance
= class_hint
->res_name
;
90 *wm_class
= class_hint
->res_class
;
98 PropGetProtocols(Window window
, WProtocols
*prots
)
103 memset(prots
, 0, sizeof(WProtocols
));
104 if (!XGetWMProtocols(dpy
, window
, &protocols
, &count
)) {
107 for (i
=0; i
<count
; i
++) {
108 if (protocols
[i
]==_XA_WM_TAKE_FOCUS
)
110 else if (protocols
[i
]==_XA_WM_DELETE_WINDOW
)
111 prots
->DELETE_WINDOW
=1;
112 else if (protocols
[i
]==_XA_WM_SAVE_YOURSELF
)
113 prots
->SAVE_YOURSELF
=1;
114 else if (protocols
[i
]==_XA_GNUSTEP_WM_MINIATURIZE_WINDOW
)
115 prots
->MINIATURIZE_WINDOW
=1;
122 PropGetCheckProperty(Window window
, Atom hint
, Atom type
, int format
,
123 int count
, int *retCount
)
127 unsigned long nitems_ret
;
128 unsigned long bytes_after_ret
;
137 if (XGetWindowProperty(dpy
, window
, hint
, 0, tmp
, False
, type
,
138 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
139 (unsigned char **)&data
)!=Success
|| !data
)
142 if ((type
!=AnyPropertyType
&& type
!=type_ret
)
143 || (count
> 0 && nitems_ret
!= count
)
144 || (format
!= 0 && format
!= fmt_ret
)) {
150 *retCount
= nitems_ret
;
157 PropGetGNUstepWMAttr(Window window
, GNUstepWMAttributes
**attr
)
161 data
= (unsigned long*)PropGetCheckProperty(window
, _XA_GNUSTEP_WM_ATTR
,
162 _XA_GNUSTEP_WM_ATTR
, 32, 9,
168 *attr
= malloc(sizeof(GNUstepWMAttributes
));
173 (*attr
)->flags
= data
[0];
174 (*attr
)->window_style
= data
[1];
175 (*attr
)->window_level
= data
[2];
176 (*attr
)->reserved
= data
[3];
177 (*attr
)->miniaturize_pixmap
= data
[4];
178 (*attr
)->close_pixmap
= data
[5];
179 (*attr
)->miniaturize_mask
= data
[6];
180 (*attr
)->close_mask
= data
[7];
181 (*attr
)->extra_flags
= data
[8];
191 PropSetWMakerProtocols(Window root
)
196 protocols
[count
++] = _XA_WINDOWMAKER_MENU
;
197 protocols
[count
++] = _XA_WINDOWMAKER_WM_FUNCTION
;
198 protocols
[count
++] = _XA_WINDOWMAKER_NOTICEBOARD
;
200 XChangeProperty(dpy
, root
, _XA_WINDOWMAKER_WM_PROTOCOLS
, XA_ATOM
,
201 32, PropModeReplace
, (unsigned char *)protocols
, count
);
206 PropSetIconTileHint(WScreen
*scr
, RImage
*image
)
208 static Atom imageAtom
= 0;
212 if (scr
->info_window
== None
)
217 * WIDTH, HEIGHT (16 bits, MSB First)
218 * array of R,G,B,A bytes
220 imageAtom
= XInternAtom(dpy
, "_RGBA_IMAGE", False
);
223 tmp
= malloc(image
->width
* image
->height
* 4 + 4);
225 wwarning("could not allocate memory to set _WINDOWMAKER_ICON_TILE hint");
229 tmp
[0] = image
->width
>>8;
230 tmp
[1] = image
->width
&0xff;
231 tmp
[2] = image
->height
>>8;
232 tmp
[3] = image
->height
&0xff;
234 if (image
->format
== RRGBAFormat
) {
235 memcpy(&tmp
[4], image
->data
, image
->width
*image
->height
*4);
237 char *ptr
= (char*)(tmp
+4);
238 char *src
= (char*)image
->data
;
240 for (y
= 0; y
< image
->height
; y
++) {
241 for (x
= 0; x
< image
->width
; x
++) {
250 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_ICON_TILE
,
251 imageAtom
, 8, PropModeReplace
, tmp
,
252 image
->width
* image
->height
* 4 + 4);
259 PropGetClientLeader(Window window
)
264 win
= (Window
*)PropGetCheckProperty(window
, _XA_WM_CLIENT_LEADER
,
265 XA_WINDOW
, 32, 1, NULL
);
270 leader
= (Window
)*win
;
279 PropGetClientID(Window window
)
281 XTextProperty txprop
;
285 if (XGetTextProperty(dpy
, window
, &txprop
, _XA_SM_CLIENT_ID
)!=Success
) {
289 if (txprop
.encoding
== XA_STRING
&& txprop
.format
== 8
290 && txprop
.nitems
> 0) {
292 return (char*)txprop
.value
;
304 PropGetWindowRole(Window window
)
306 XTextProperty txprop
;
310 if (XGetTextProperty(dpy
, window
, &txprop
, _XA_WM_WINDOW_ROLE
)!=Success
) {
314 if (txprop
.encoding
== XA_STRING
&& txprop
.format
== 8
315 && txprop
.nitems
> 0) {
317 return (char*)txprop
.value
;
326 #endif /* XSMP_ENABLED */
330 PropWriteGNUstepWMAttr(Window window
, GNUstepWMAttributes
*attr
)
332 unsigned long data
[9];
334 data
[0] = attr
->flags
;
335 data
[1] = attr
->window_style
;
336 data
[2] = attr
->window_level
;
337 data
[3] = 0; /* reserved */
338 /* The X protocol says XIDs are 32bit */
339 data
[4] = attr
->miniaturize_pixmap
;
340 data
[5] = attr
->close_pixmap
;
341 data
[6] = attr
->miniaturize_mask
;
342 data
[7] = attr
->close_mask
;
343 data
[8] = attr
->extra_flags
;
344 XChangeProperty(dpy
, window
, _XA_GNUSTEP_WM_ATTR
, _XA_GNUSTEP_WM_ATTR
,
345 32, PropModeReplace
, (unsigned char *)data
, 9);
350 PropGetWindowState(Window window
)
355 data
= (long*)PropGetCheckProperty(window
, _XA_WM_STATE
, _XA_WM_STATE
,
369 PropCleanUp(Window root
)
371 XDeleteProperty(dpy
, root
, _XA_WINDOWMAKER_WM_PROTOCOLS
);
373 XDeleteProperty(dpy
, root
, _XA_WINDOWMAKER_NOTICEBOARD
);
375 XDeleteProperty(dpy
, root
, XA_WM_ICON_SIZE
);