2 * Window Maker window manager
4 * Copyright (c) 1997, 1998 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
;
58 PropGetNormalHints(Window window
, XSizeHints
*size_hints
, int *pre_iccm
)
62 if (!XGetWMNormalHints(dpy
, window
, size_hints
, &supplied_hints
)) {
65 if (supplied_hints
==(USPosition
|USSize
|PPosition
|PSize
|PMinSize
|PMaxSize
66 |PResizeInc
|PAspect
)) {
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) {
87 *wm_instance
= class_hint
->res_name
;
88 *wm_class
= class_hint
->res_class
;
96 PropGetProtocols(Window window
, WProtocols
*prots
)
101 memset(prots
, 0, sizeof(WProtocols
));
102 if (!XGetWMProtocols(dpy
, window
, &protocols
, &count
)) {
105 for (i
=0; i
<count
; i
++) {
106 if (protocols
[i
]==_XA_WM_TAKE_FOCUS
)
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;
120 PropGetCheckProperty(Window window
, Atom hint
, Atom type
, int format
,
121 int count
, int *retCount
)
125 unsigned long nitems_ret
;
126 unsigned long bytes_after_ret
;
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
)
138 if ((type
!=AnyPropertyType
&& type
!=type_ret
)
139 || (count
> 0 && nitems_ret
!= count
)
140 || (format
!= 0 && format
!= fmt_ret
)) {
146 *retCount
= nitems_ret
;
153 PropGetGNUstepWMAttr(Window window
, GNUstepWMAttributes
**attr
)
157 data
= (unsigned long*)PropGetCheckProperty(window
, _XA_GNUSTEP_WM_ATTR
,
158 _XA_GNUSTEP_WM_ATTR
, 32, 9,
164 *attr
= malloc(sizeof(GNUstepWMAttributes
));
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];
187 PropSetWMakerProtocols(Window root
)
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
);
201 PropGetClientLeader(Window window
)
206 win
= (Window
*)PropGetCheckProperty(window
, _XA_WM_CLIENT_LEADER
,
207 XA_WINDOW
, 32, 1, NULL
);
212 leader
= (Window
)*win
;
221 PropGetClientID(Window window
)
223 XTextProperty txprop
;
227 if (XGetTextProperty(dpy
, window
, &txprop
, _XA_SM_CLIENT_ID
)!=Success
) {
231 if (txprop
.encoding
== XA_STRING
&& txprop
.format
== 8
232 && txprop
.nitems
> 0) {
234 return (char*)txprop
.value
;
246 PropGetWindowRole(Window window
)
248 XTextProperty txprop
;
252 if (XGetTextProperty(dpy
, window
, &txprop
, _XA_WM_WINDOW_ROLE
)!=Success
) {
256 if (txprop
.encoding
== XA_STRING
&& txprop
.format
== 8
257 && txprop
.nitems
> 0) {
259 return (char*)txprop
.value
;
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);
292 PropCleanUp(Window root
)
294 XDeleteProperty(dpy
, root
, _XA_WINDOWMAKER_WM_PROTOCOLS
);
296 XDeleteProperty(dpy
, root
, XA_WM_ICON_SIZE
);
299 XDeleteProperty(dpy
, root
, XInternAtom(dpy
, "KWM_RUNNING", False
));