1 #include "cwmcc_internal.h"
4 #include "client_props.h"
5 #include "render/render.h"
12 void cwmcc_client_get_protocols(Window win
, Atom
**protocols
)
16 if (!prop_get_array32(win
, CWMCC_ATOM(client
, wm_protocols
),
17 CWMCC_ATOM(type
, atom
), protocols
, &num
)) {
18 g_warning("Failed to read WM_PROTOCOLS from 0x%lx", win
);
23 void cwmcc_client_set_protocols(Window win
, Atom
*protocols
)
28 for (a
= protocols
, n
= 0; *a
; ++a
, ++n
);
29 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, wm_state
),
30 CWMCC_ATOM(type
, atom
), 32, PropModeReplace
,
31 (guchar
*)protocols
, n
);
34 void cwmcc_client_get_wm_state(Window win
, gulong
*state
)
36 if (!prop_get32(win
, CWMCC_ATOM(client
, wm_state
),
37 CWMCC_ATOM(client
, wm_state
), state
)) {
38 g_warning("Failed to read WM_STATE from 0x%lx", win
);
43 void cwmcc_client_set_wm_state(Window win
, gulong state
)
45 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, wm_state
),
46 CWMCC_ATOM(client
, wm_state
), 32, PropModeReplace
,
50 void cwmcc_client_get_name(Window win
, char **name
)
52 if (!prop_get_string_utf8(win
, CWMCC_ATOM(client
, net_wm_name
), name
))
53 if (!prop_get_string_locale(win
, CWMCC_ATOM(client
, wm_name
), name
)) {
54 g_warning("Failed to read a name from 0x%lx", win
);
55 *name
= g_strdup("Unnamed Window");
59 void cwmcc_client_set_name(Window win
, char *name
)
61 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, net_wm_name
),
62 CWMCC_ATOM(type
, utf8
), 32, PropModeReplace
,
63 (guchar
*)name
, strlen(name
));
66 void cwmcc_client_get_icon_name(Window win
, char **name
)
68 if (!prop_get_string_utf8(win
, CWMCC_ATOM(client
, net_wm_icon_name
), name
))
69 if (!prop_get_string_locale(win
,
70 CWMCC_ATOM(client
, wm_icon_name
), name
)) {
71 g_warning("Failed to read an icon name from 0x%lx", win
);
72 *name
= g_strdup("Unnamed Window");
76 void cwmcc_client_set_icon_name(Window win
, char *name
)
78 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, net_wm_icon_name
),
79 CWMCC_ATOM(type
, utf8
), 32, PropModeReplace
,
80 (guchar
*)name
, strlen(name
));
83 void cwmcc_client_get_class(Window win
, char **class, char **name
)
87 if (!prop_get_strings_locale(win
, CWMCC_ATOM(client
, wm_class
), &s
)) {
88 g_warning("Failed to read WM_CLASS from 0x%lx", win
);
89 *class = g_strdup("");
93 g_warning("Failed to read class element of WM_CLASS from 0x%lx",
95 *class = g_strdup("");
97 *class = g_strdup(s
[0]);
99 g_warning("Failed to read name element of WM_CLASS from 0x%lx",
101 *name
= g_strdup("");
103 *name
= g_strdup(s
[1]);
108 void cwmcc_client_get_role(Window win
, char **role
)
110 if (!prop_get_string_locale(win
,
111 CWMCC_ATOM(client
, wm_window_role
), role
)) {
112 g_warning("Failed to read WM_WINDOW_ROLE from 0x%lx", win
);
113 *role
= g_strdup("");
117 void cwmcc_client_get_mwmhints(Window win
, struct Cwmcc_MwmHints
*hints
)
119 gulong
*l
= NULL
, num
;
121 if (!prop_get_array32(win
, CWMCC_ATOM(client
, motif_wm_hints
),
122 CWMCC_ATOM(client
, motif_wm_hints
), &l
, &num
)) {
123 g_warning("Failed to read Motif WM Hints from 0x%lx", win
);
125 } else if (num
< 3) {
126 g_warning("Read incomplete Motif WM Hints from 0x%lx", win
);
130 hints
->functions
= l
[1];
131 hints
->decorations
= l
[2];
136 void cwmcc_client_get_desktop(Window win
, gulong
*desk
)
138 if (!prop_get32(win
, CWMCC_ATOM(client
, net_wm_desktop
),
139 CWMCC_ATOM(type
, cardinal
), desk
)) {
140 g_warning("Failed to read NET_WM_DESKTOP from 0x%lx", win
);
145 void cwmcc_client_set_desktop(Window win
, gulong desk
)
147 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, net_wm_desktop
),
148 CWMCC_ATOM(type
, cardinal
), 32, PropModeReplace
,
152 void cwmcc_client_get_type(Window win
, gulong
**types
)
156 if (!prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_window_type
),
157 CWMCC_ATOM(type
, atom
), types
, &num
)) {
158 g_warning("Failed to read NET_WM_WINDOW_TYPE from 0x%lx", win
);
159 *types
= g_new(Atom
, 2);
160 (*types
)[0] = CWMCC_ATOM(data
, net_wm_window_type_normal
);
165 void cwmcc_client_set_type(Window win
, gulong
*types
)
170 for (t
= types
, n
= 0; *t
; ++t
, ++n
);
171 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, wm_state
),
172 CWMCC_ATOM(type
, atom
), 32, PropModeReplace
,
176 void cwmcc_client_get_state(Window win
, gulong
**states
)
180 if (!prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_state
),
181 CWMCC_ATOM(type
, atom
), states
, &num
)) {
182 g_warning("Failed to read NET_WM_STATE from 0x%lx", win
);
183 *states
= g_new(Atom
, 1);
188 void cwmcc_client_set_state(Window win
, gulong
*states
)
193 for (s
= states
, n
= 0; *s
; ++s
, ++n
);
194 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, wm_state
),
195 CWMCC_ATOM(type
, atom
), 32, PropModeReplace
,
199 void cwmcc_client_get_strut(Window win
, int *l
, int *t
, int *r
, int *b
)
201 gulong
*data
= NULL
, num
;
203 if (!prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_strut
),
204 CWMCC_ATOM(type
, cardinal
), &data
, &num
)) {
205 g_warning("Failed to read NET_WM_STRUT from 0x%lx", win
);
206 *l
= *t
= *r
= *b
= 0;
207 } else if (num
!= 4) {
208 g_warning("Read invalid NET_WM_STRUT from 0x%lx", win
);
209 *l
= *t
= *r
= *b
= 0;
219 static void convert_pixmap_to_icon(Pixmap pix
, Pixmap mask
,
220 struct Cwmcc_Icon
*icon
)
223 guint pw, ph, mw, mh, depth;
229 if (!XGetGeometry(cwmcc_display, pix, &wjunk, &ijunk, &ijunk, &pw, &ph,
231 g_message("Unable to read pixmap icon's geometry");
232 icon->width = icon->height = 0;
236 if (!XGetGeometry(cwmcc_display, mask, &wjunk, &ijunk, &ijunk, &mw, &mh,
238 g_message("Unable to read pixmap icon's mask's geometry");
239 icon->width = icon->height = 0;
243 if (pw != mw || ph !_ mh) {
244 g_warning("Pixmap icon's mask does not match icon's dimensions");
245 icon->width = icon->height = 0;
250 for (y = 0; y < ph; ++y)
251 for (x = 0; x < pw; ++x) {
254 icon
->width
= icon
->height
= 0;
258 void cwmcc_client_get_icon(Window win
, struct Cwmcc_Icon
**icons
)
260 gulong
*data
= NULL
, num
;
265 if (!prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_icon
),
266 CWMCC_ATOM(type
, cardinal
), &data
, &num
)) {
267 g_warning("Failed to read NET_WM_ICON from 0x%lx", win
);
271 /* figure out how many valid icons are in here */
274 while (num
- i
> 2) {
282 *icons
= g_new(struct Cwmcc_Icon
, nicons
+ 1);
283 (*icons
)[nicons
].data
= NULL
;
285 /* store the icons */
287 for (j
= 0; j
< nicons
; ++j
) {
288 w
= (*icons
)[j
].width
= data
[i
++];
289 h
= (*icons
)[j
].height
= data
[i
++];
291 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
299 if (!prop_get_array32(win
, CWMCC_ATOM(client
, kwm_win_icon
),
300 CWMCC_ATOM(client
, kwm_win_icon
), &data
, &num
)) {
301 g_warning("Failed to read KWM_WIN_ICON from 0x%lx", win
);
302 } else if (num
!= 2) {
303 g_warning("Read invalid KWM_WIN_ICON from 0x%lx", win
);
306 struct Cwmcc_Icon icon
;
311 convert_pixmap_to_icon(p
, m
, &icon
);
314 *icons
= g_renew(struct Cwmcc_Icon
, *icons
, nicons
+ 2);
315 (*icons
[nicons
+ 1]).data
= NULL
;
316 g_memmove(&(*icons
)[nicons
], &icon
, sizeof(struct Cwmcc_Icon
));
323 void cwmcc_client_get_premax(Window win
, int *x
, int *y
, int *w
, int *h
)
325 gulong
*l
= NULL
, num
;
327 if (!prop_get_array32(win
, CWMCC_ATOM(client
, openbox_premax
),
328 CWMCC_ATOM(type
, cardinal
), &l
, &num
)) {
329 g_warning("Failed to read OPENBOX_PREMAX from 0x%lx", win
);
330 *x
= *y
= *w
= *h
= 0;
331 } else if (num
!= 4) {
332 g_warning("Read invalid OPENBOX_PREMAX from 0x%lx", win
);
333 *x
= *y
= *w
= *h
= 0;
343 void cwmcc_client_set_premax(Window win
, int x
, int y
, int w
, int h
)
351 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, openbox_premax
),
352 CWMCC_ATOM(type
, cardinal
), 32, PropModeReplace
,