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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <X11/Xutil.h>
25 #include <X11/Xatom.h>
29 #include "WindowMaker.h"
32 #include "properties.h"
35 int PropGetNormalHints(Window window
, XSizeHints
* size_hints
, int *pre_iccm
)
39 if (!XGetWMNormalHints(dpy
, window
, size_hints
, &supplied_hints
)) {
42 if (supplied_hints
== (USPosition
| USSize
| PPosition
| PSize
| PMinSize
| PMaxSize
43 | PResizeInc
| PAspect
)) {
51 int PropGetWMClass(Window window
, char **wm_class
, char **wm_instance
)
53 XClassHint
*class_hint
;
55 class_hint
= XAllocClassHint();
56 if (XGetClassHint(dpy
, window
, class_hint
) == 0) {
57 *wm_class
= strdup("default");
58 *wm_instance
= strdup("default");
62 *wm_instance
= strdup(class_hint
->res_name
);
63 *wm_class
= strdup(class_hint
->res_class
);
65 XFree(class_hint
->res_name
);
66 XFree(class_hint
->res_class
);
72 void PropGetProtocols(Window window
, WProtocols
* prots
)
77 memset(prots
, 0, sizeof(WProtocols
));
78 if (!XGetWMProtocols(dpy
, window
, &protocols
, &count
)) {
81 for (i
= 0; i
< count
; i
++) {
82 if (protocols
[i
] == w_global
.atom
.wm
.take_focus
)
83 prots
->TAKE_FOCUS
= 1;
84 else if (protocols
[i
] == w_global
.atom
.wm
.delete_window
)
85 prots
->DELETE_WINDOW
= 1;
86 else if (protocols
[i
] == w_global
.atom
.wm
.save_yourself
)
87 prots
->SAVE_YOURSELF
= 1;
88 else if (protocols
[i
] == w_global
.atom
.gnustep
.wm_miniaturize_window
)
89 prots
->MINIATURIZE_WINDOW
= 1;
94 unsigned char *PropGetCheckProperty(Window window
, Atom hint
, Atom type
, int format
, int count
, int *retCount
)
98 unsigned long nitems_ret
;
99 unsigned long bytes_after_ret
;
108 if (XGetWindowProperty(dpy
, window
, hint
, 0, tmp
, False
, type
,
109 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
110 (unsigned char **)&data
) != Success
|| !data
)
113 if ((type
!= AnyPropertyType
&& type
!= type_ret
)
114 || (count
> 0 && nitems_ret
!= count
)
115 || (format
!= 0 && format
!= fmt_ret
)) {
121 *retCount
= nitems_ret
;
126 int PropGetGNUstepWMAttr(Window window
, GNUstepWMAttributes
** attr
)
130 data
= (unsigned long *)PropGetCheckProperty(window
, w_global
.atom
.gnustep
.wm_attr
,
131 w_global
.atom
.gnustep
.wm_attr
, 32, 9, NULL
);
136 *attr
= malloc(sizeof(GNUstepWMAttributes
));
141 (*attr
)->flags
= data
[0];
142 (*attr
)->window_style
= data
[1];
143 (*attr
)->window_level
= data
[2];
144 (*attr
)->reserved
= data
[3];
145 (*attr
)->miniaturize_pixmap
= data
[4];
146 (*attr
)->close_pixmap
= data
[5];
147 (*attr
)->miniaturize_mask
= data
[6];
148 (*attr
)->close_mask
= data
[7];
149 (*attr
)->extra_flags
= data
[8];
156 void PropSetWMakerProtocols(Window root
)
161 protocols
[count
++] = w_global
.atom
.wmaker
.menu
;
162 protocols
[count
++] = w_global
.atom
.wmaker
.wm_function
;
163 protocols
[count
++] = w_global
.atom
.wmaker
.noticeboard
;
165 XChangeProperty(dpy
, root
, w_global
.atom
.wmaker
.wm_protocols
, XA_ATOM
,
166 32, PropModeReplace
, (unsigned char *)protocols
, count
);
169 void PropSetIconTileHint(WScreen
* scr
, RImage
* image
)
171 static Atom imageAtom
= 0;
175 if (scr
->info_window
== None
)
180 * WIDTH, HEIGHT (16 bits, MSB First)
181 * array of R,G,B,A bytes
183 imageAtom
= XInternAtom(dpy
, "_RGBA_IMAGE", False
);
186 tmp
= malloc(image
->width
* image
->height
* 4 + 4);
188 wwarning("could not allocate memory to set _WINDOWMAKER_ICON_TILE hint");
192 tmp
[0] = image
->width
>> 8;
193 tmp
[1] = image
->width
& 0xff;
194 tmp
[2] = image
->height
>> 8;
195 tmp
[3] = image
->height
& 0xff;
197 if (image
->format
== RRGBAFormat
) {
198 memcpy(&tmp
[4], image
->data
, image
->width
* image
->height
* 4);
200 char *ptr
= (char *)(tmp
+ 4);
201 char *src
= (char *)image
->data
;
203 for (y
= 0; y
< image
->height
; y
++) {
204 for (x
= 0; x
< image
->width
; x
++) {
213 XChangeProperty(dpy
, scr
->info_window
, w_global
.atom
.wmaker
.icon_tile
,
214 imageAtom
, 8, PropModeReplace
, tmp
, image
->width
* image
->height
* 4 + 4);
219 Window
PropGetClientLeader(Window window
)
224 win
= (Window
*) PropGetCheckProperty(window
, w_global
.atom
.wm
.client_leader
, XA_WINDOW
, 32, 1, NULL
);
229 leader
= (Window
) * win
;
235 int PropGetWindowState(Window window
)
240 data
= (long *)PropGetCheckProperty(window
, w_global
.atom
.wm
.state
,
241 w_global
.atom
.wm
.state
, 32, 1, NULL
);
252 void PropCleanUp(Window root
)
254 XDeleteProperty(dpy
, root
, w_global
.atom
.wmaker
.wm_protocols
);
255 XDeleteProperty(dpy
, root
, w_global
.atom
.wmaker
.noticeboard
);
256 XDeleteProperty(dpy
, root
, XA_WM_ICON_SIZE
);