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"
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_WM_WINDOW_ROLE
;
44 extern Atom _XA_SM_CLIENT_ID
;
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
;
53 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
54 extern Atom _XA_WINDOWMAKER_ICON_TILE
;
55 extern Atom _XA_WINDOWMAKER_ICON_SIZE
;
57 int PropGetNormalHints(Window window
, XSizeHints
* size_hints
, int *pre_iccm
)
61 if (!XGetWMNormalHints(dpy
, window
, size_hints
, &supplied_hints
)) {
64 if (supplied_hints
== (USPosition
| USSize
| PPosition
| PSize
| PMinSize
| PMaxSize
65 | PResizeInc
| PAspect
)) {
73 int PropGetWMClass(Window window
, char **wm_class
, char **wm_instance
)
75 XClassHint
*class_hint
;
77 class_hint
= XAllocClassHint();
78 if (XGetClassHint(dpy
, window
, class_hint
) == 0) {
84 *wm_instance
= class_hint
->res_name
;
85 *wm_class
= class_hint
->res_class
;
91 void PropGetProtocols(Window window
, WProtocols
* prots
)
96 memset(prots
, 0, sizeof(WProtocols
));
97 if (!XGetWMProtocols(dpy
, window
, &protocols
, &count
)) {
100 for (i
= 0; i
< count
; i
++) {
101 if (protocols
[i
] == _XA_WM_TAKE_FOCUS
)
102 prots
->TAKE_FOCUS
= 1;
103 else if (protocols
[i
] == _XA_WM_DELETE_WINDOW
)
104 prots
->DELETE_WINDOW
= 1;
105 else if (protocols
[i
] == _XA_WM_SAVE_YOURSELF
)
106 prots
->SAVE_YOURSELF
= 1;
107 else if (protocols
[i
] == _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
)
108 prots
->MINIATURIZE_WINDOW
= 1;
113 unsigned char *PropGetCheckProperty(Window window
, Atom hint
, Atom type
, int format
, int count
, int *retCount
)
117 unsigned long nitems_ret
;
118 unsigned long bytes_after_ret
;
127 if (XGetWindowProperty(dpy
, window
, hint
, 0, tmp
, False
, type
,
128 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
129 (unsigned char **)&data
) != Success
|| !data
)
132 if ((type
!= AnyPropertyType
&& type
!= type_ret
)
133 || (count
> 0 && nitems_ret
!= count
)
134 || (format
!= 0 && format
!= fmt_ret
)) {
140 *retCount
= nitems_ret
;
145 int PropGetGNUstepWMAttr(Window window
, GNUstepWMAttributes
** attr
)
149 data
= (unsigned long *)PropGetCheckProperty(window
, _XA_GNUSTEP_WM_ATTR
,
150 _XA_GNUSTEP_WM_ATTR
, 32, 9, NULL
);
155 *attr
= malloc(sizeof(GNUstepWMAttributes
));
160 (*attr
)->flags
= data
[0];
161 (*attr
)->window_style
= data
[1];
162 (*attr
)->window_level
= data
[2];
163 (*attr
)->reserved
= data
[3];
164 (*attr
)->miniaturize_pixmap
= data
[4];
165 (*attr
)->close_pixmap
= data
[5];
166 (*attr
)->miniaturize_mask
= data
[6];
167 (*attr
)->close_mask
= data
[7];
168 (*attr
)->extra_flags
= data
[8];
175 void PropSetWMakerProtocols(Window root
)
180 protocols
[count
++] = _XA_WINDOWMAKER_MENU
;
181 protocols
[count
++] = _XA_WINDOWMAKER_WM_FUNCTION
;
182 protocols
[count
++] = _XA_WINDOWMAKER_NOTICEBOARD
;
184 XChangeProperty(dpy
, root
, _XA_WINDOWMAKER_WM_PROTOCOLS
, XA_ATOM
,
185 32, PropModeReplace
, (unsigned char *)protocols
, count
);
188 void PropSetIconTileHint(WScreen
* scr
, RImage
* image
)
190 static Atom imageAtom
= 0;
194 if (scr
->info_window
== None
)
199 * WIDTH, HEIGHT (16 bits, MSB First)
200 * array of R,G,B,A bytes
202 imageAtom
= XInternAtom(dpy
, "_RGBA_IMAGE", False
);
205 tmp
= malloc(image
->width
* image
->height
* 4 + 4);
207 wwarning("could not allocate memory to set _WINDOWMAKER_ICON_TILE hint");
211 tmp
[0] = image
->width
>> 8;
212 tmp
[1] = image
->width
& 0xff;
213 tmp
[2] = image
->height
>> 8;
214 tmp
[3] = image
->height
& 0xff;
216 if (image
->format
== RRGBAFormat
) {
217 memcpy(&tmp
[4], image
->data
, image
->width
* image
->height
* 4);
219 char *ptr
= (char *)(tmp
+ 4);
220 char *src
= (char *)image
->data
;
222 for (y
= 0; y
< image
->height
; y
++) {
223 for (x
= 0; x
< image
->width
; x
++) {
232 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_ICON_TILE
,
233 imageAtom
, 8, PropModeReplace
, tmp
, image
->width
* image
->height
* 4 + 4);
238 Window
PropGetClientLeader(Window window
)
243 win
= (Window
*) PropGetCheckProperty(window
, _XA_WM_CLIENT_LEADER
, XA_WINDOW
, 32, 1, NULL
);
248 leader
= (Window
) * win
;
255 char *PropGetClientID(Window window
)
257 XTextProperty txprop
;
261 if (XGetTextProperty(dpy
, window
, &txprop
, _XA_SM_CLIENT_ID
) != Success
) {
265 if (txprop
.encoding
== XA_STRING
&& txprop
.format
== 8 && txprop
.nitems
> 0) {
267 return (char *)txprop
.value
;
277 char *PropGetWindowRole(Window window
)
279 XTextProperty txprop
;
283 if (XGetTextProperty(dpy
, window
, &txprop
, _XA_WM_WINDOW_ROLE
) != Success
) {
287 if (txprop
.encoding
== XA_STRING
&& txprop
.format
== 8 && txprop
.nitems
> 0) {
289 return (char *)txprop
.value
;
298 #endif /* XSMP_ENABLED */
300 void PropWriteGNUstepWMAttr(Window window
, GNUstepWMAttributes
* attr
)
302 unsigned long data
[9];
304 data
[0] = attr
->flags
;
305 data
[1] = attr
->window_style
;
306 data
[2] = attr
->window_level
;
307 data
[3] = 0; /* reserved */
308 /* The X protocol says XIDs are 32bit */
309 data
[4] = attr
->miniaturize_pixmap
;
310 data
[5] = attr
->close_pixmap
;
311 data
[6] = attr
->miniaturize_mask
;
312 data
[7] = attr
->close_mask
;
313 data
[8] = attr
->extra_flags
;
314 XChangeProperty(dpy
, window
, _XA_GNUSTEP_WM_ATTR
, _XA_GNUSTEP_WM_ATTR
,
315 32, PropModeReplace
, (unsigned char *)data
, 9);
318 int PropGetWindowState(Window window
)
323 data
= (long *)PropGetCheckProperty(window
, _XA_WM_STATE
, _XA_WM_STATE
, 32, 1, NULL
);
334 void PropCleanUp(Window root
)
336 XDeleteProperty(dpy
, root
, _XA_WINDOWMAKER_WM_PROTOCOLS
);
338 XDeleteProperty(dpy
, root
, _XA_WINDOWMAKER_NOTICEBOARD
);
340 XDeleteProperty(dpy
, root
, XA_WM_ICON_SIZE
);