2 * WindowMaker 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"
39 extern Atom _XA_WM_STATE
;
40 extern Atom _XA_WM_CHANGE_STATE
;
41 extern Atom _XA_WM_PROTOCOLS
;
42 extern Atom _XA_WM_CLIENT_LEADER
;
43 extern Atom _XA_WM_TAKE_FOCUS
;
44 extern Atom _XA_WM_DELETE_WINDOW
;
45 extern Atom _XA_WM_SAVE_YOURSELF
;
47 extern Atom _XA_GNUSTEP_WM_ATTR
;
48 extern Atom _XA_WINDOWMAKER_WM_MINIATURIZE_WINDOW
;
50 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
51 extern Atom _XA_WINDOWMAKER_MENU
;
52 extern Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
56 PropGetNormalHints(Window window
, XSizeHints
*size_hints
, int *pre_iccm
)
60 if (!XGetWMNormalHints(dpy
, window
, size_hints
, &supplied_hints
)) {
63 if (supplied_hints
==(USPosition
|USSize
|PPosition
|PSize
|PMinSize
|PMaxSize
64 |PResizeInc
|PAspect
)) {
74 PropGetWMClass(Window window
, char **wm_class
, char **wm_instance
)
76 XClassHint
*class_hint
;
78 class_hint
= XAllocClassHint();
79 if (XGetClassHint(dpy
,window
,class_hint
) == 0) {
85 *wm_instance
= class_hint
->res_name
;
86 *wm_class
= class_hint
->res_class
;
93 PropGetProtocols(Window window
, WProtocols
*prots
)
98 memset(prots
, 0, sizeof(WProtocols
));
99 if (!XGetWMProtocols(dpy
, window
, &protocols
, &count
)) {
102 for (i
=0; i
<count
; i
++) {
103 if (protocols
[i
]==_XA_WM_TAKE_FOCUS
)
105 else if (protocols
[i
]==_XA_WM_DELETE_WINDOW
)
106 prots
->DELETE_WINDOW
=1;
107 else if (protocols
[i
]==_XA_WM_SAVE_YOURSELF
)
108 prots
->SAVE_YOURSELF
=1;
109 else if (protocols
[i
]==_XA_WINDOWMAKER_WM_MINIATURIZE_WINDOW
)
110 prots
->MINIATURIZE_WINDOW
=1;
117 PropGetGNUstepWMAttr(Window window
, GNUstepWMAttributes
**attr
)
121 unsigned long nitems_ret
;
122 unsigned long bytes_after_ret
;
125 if (XGetWindowProperty(dpy
, window
, _XA_GNUSTEP_WM_ATTR
, 0,
126 sizeof(GNUstepWMAttributes
),
127 False
, _XA_GNUSTEP_WM_ATTR
,
128 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
129 (unsigned char **)&data
)!=Success
)
131 if (type_ret
!=_XA_GNUSTEP_WM_ATTR
|| !data
|| fmt_ret
!=32)
134 *attr
= malloc(sizeof(GNUstepWMAttributes
));
139 (*attr
)->flags
= data
[0];
140 (*attr
)->window_style
= data
[1];
141 (*attr
)->window_level
= data
[2];
142 (*attr
)->reserved
= data
[3];
143 (*attr
)->miniaturize_pixmap
= data
[4];
144 (*attr
)->close_pixmap
= data
[5];
145 (*attr
)->miniaturize_mask
= data
[6];
146 (*attr
)->close_mask
= data
[7];
147 (*attr
)->extra_flags
= data
[8];
159 PropGetMotifWMHints(Window window
, MWMHints
**mwmhints
)
163 unsigned long nitems_ret
;
164 unsigned long bytes_after_ret
;
166 if (XGetWindowProperty(dpy
, window
, _XA_MOTIF_WM_HINTS
, 0, 20,
167 False
, _XA_MOTIF_WM_HINTS
,
168 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
169 (unsigned char **)mwmhints
)!=Success
)
171 if (type_ret
==_XA_MOTIF_WM_HINTS
)
176 #endif /* MWM_HINTS */
180 PropSetWMakerProtocols(Window root
)
185 protocols
[count
++] = _XA_WINDOWMAKER_MENU
;
186 protocols
[count
++] = _XA_WINDOWMAKER_WM_FUNCTION
;
188 XChangeProperty(dpy
, root
, _XA_WINDOWMAKER_WM_PROTOCOLS
, XA_ATOM
,
189 32, PropModeReplace
, (unsigned char *)protocols
, count
);
194 PropGetClientLeader(Window window
, Window
*leader
)
198 unsigned long nitems_ret
;
199 unsigned long bytes_after_ret
;
202 if (XGetWindowProperty(dpy
, window
, _XA_WM_CLIENT_LEADER
, 0,
203 sizeof(Window
), False
, AnyPropertyType
,
204 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
205 (unsigned char**)&win
)!=Success
)
209 *leader
= (Window
)*win
;
217 PropWriteGNUstepWMAttr(Window window
, GNUstepWMAttributes
*attr
)
221 /* handle idiot compilers where array of CARD32 != struct of CARD32 */
222 data
[0] = attr
->flags
;
223 data
[1] = attr
->window_style
;
224 data
[2] = attr
->window_level
;
225 data
[3] = 0; /* reserved */
226 /* The X protocol says XIDs are 32bit */
227 data
[4] = attr
->miniaturize_pixmap
;
228 data
[5] = attr
->close_pixmap
;
229 data
[6] = attr
->miniaturize_mask
;
230 data
[7] = attr
->close_mask
;
231 data
[8] = attr
->extra_flags
;
232 XChangeProperty(dpy
, window
, _XA_GNUSTEP_WM_ATTR
, _XA_GNUSTEP_WM_ATTR
,
233 32, PropModeReplace
, (unsigned char *)data
, 9);
238 PropCleanUp(Window root
)
240 XDeleteProperty(dpy
, root
, _XA_WINDOWMAKER_WM_PROTOCOLS
);
242 XDeleteProperty(dpy
, root
, XA_WM_ICON_SIZE
);