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
;
55 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
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
;
135 if (XGetWindowProperty(dpy
, window
, hint
, 0, tmp
, False
, type
,
136 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
137 (unsigned char **)&data
)!=Success
|| !data
)
140 if ((type
!=AnyPropertyType
&& type
!=type_ret
)
141 || (count
> 0 && nitems_ret
!= count
)
142 || (format
!= 0 && format
!= fmt_ret
)) {
148 *retCount
= nitems_ret
;
155 PropGetGNUstepWMAttr(Window window
, GNUstepWMAttributes
**attr
)
159 data
= (unsigned long*)PropGetCheckProperty(window
, _XA_GNUSTEP_WM_ATTR
,
160 _XA_GNUSTEP_WM_ATTR
, 32, 9,
166 *attr
= malloc(sizeof(GNUstepWMAttributes
));
171 (*attr
)->flags
= data
[0];
172 (*attr
)->window_style
= data
[1];
173 (*attr
)->window_level
= data
[2];
174 (*attr
)->reserved
= data
[3];
175 (*attr
)->miniaturize_pixmap
= data
[4];
176 (*attr
)->close_pixmap
= data
[5];
177 (*attr
)->miniaturize_mask
= data
[6];
178 (*attr
)->close_mask
= data
[7];
179 (*attr
)->extra_flags
= data
[8];
189 PropSetWMakerProtocols(Window root
)
194 protocols
[count
++] = _XA_WINDOWMAKER_MENU
;
195 protocols
[count
++] = _XA_WINDOWMAKER_WM_FUNCTION
;
196 protocols
[count
++] = _XA_WINDOWMAKER_NOTICEBOARD
;
198 XChangeProperty(dpy
, root
, _XA_WINDOWMAKER_WM_PROTOCOLS
, XA_ATOM
,
199 32, PropModeReplace
, (unsigned char *)protocols
, count
);
204 PropGetClientLeader(Window window
)
209 win
= (Window
*)PropGetCheckProperty(window
, _XA_WM_CLIENT_LEADER
,
210 XA_WINDOW
, 32, 1, NULL
);
215 leader
= (Window
)*win
;
224 PropGetClientID(Window window
)
226 XTextProperty txprop
;
230 if (XGetTextProperty(dpy
, window
, &txprop
, _XA_SM_CLIENT_ID
)!=Success
) {
234 if (txprop
.encoding
== XA_STRING
&& txprop
.format
== 8
235 && txprop
.nitems
> 0) {
237 return (char*)txprop
.value
;
249 PropGetWindowRole(Window window
)
251 XTextProperty txprop
;
255 if (XGetTextProperty(dpy
, window
, &txprop
, _XA_WM_WINDOW_ROLE
)!=Success
) {
259 if (txprop
.encoding
== XA_STRING
&& txprop
.format
== 8
260 && txprop
.nitems
> 0) {
262 return (char*)txprop
.value
;
271 #endif /* XSMP_ENABLED */
275 PropWriteGNUstepWMAttr(Window window
, GNUstepWMAttributes
*attr
)
277 unsigned long data
[9];
279 data
[0] = attr
->flags
;
280 data
[1] = attr
->window_style
;
281 data
[2] = attr
->window_level
;
282 data
[3] = 0; /* reserved */
283 /* The X protocol says XIDs are 32bit */
284 data
[4] = attr
->miniaturize_pixmap
;
285 data
[5] = attr
->close_pixmap
;
286 data
[6] = attr
->miniaturize_mask
;
287 data
[7] = attr
->close_mask
;
288 data
[8] = attr
->extra_flags
;
289 XChangeProperty(dpy
, window
, _XA_GNUSTEP_WM_ATTR
, _XA_GNUSTEP_WM_ATTR
,
290 32, PropModeReplace
, (unsigned char *)data
, 9);
295 PropGetWindowState(Window window
)
300 data
= (long*)PropGetCheckProperty(window
, _XA_WM_STATE
, _XA_WM_STATE
,
314 PropCleanUp(Window root
)
316 XDeleteProperty(dpy
, root
, _XA_WINDOWMAKER_WM_PROTOCOLS
);
318 XDeleteProperty(dpy
, root
, _XA_WINDOWMAKER_NOTICEBOARD
);
320 XDeleteProperty(dpy
, root
, XA_WM_ICON_SIZE
);
323 XDeleteProperty(dpy
, root
, XInternAtom(dpy
, "KWM_RUNNING", False
));