1 #include "cwmcc_internal.h"
4 #include "client_props.h"
9 void cwmcc_client_get_protocols(Window win
, Atom
**protocols
)
13 if (!prop_get_array32(win
, CWMCC_ATOM(client
, wm_protocols
),
14 CWMCC_ATOM(type
, atom
), protocols
, &num
)) {
15 g_warning("Failed to read WM_PROTOCOLS from 0x%lx", win
);
20 void cwmcc_client_set_protocols(Window win
, Atom
*protocols
)
25 for (a
= protocols
, n
= 0; *a
; ++a
, ++n
);
26 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, wm_state
),
27 CWMCC_ATOM(type
, atom
), 32, PropModeReplace
,
28 (guchar
*)protocols
, n
);
31 void cwmcc_client_get_wm_state(Window win
, gulong
*state
)
33 if (!prop_get32(win
, CWMCC_ATOM(client
, wm_state
),
34 CWMCC_ATOM(client
, wm_state
), state
)) {
35 g_warning("Failed to read WM_STATE from 0x%lx", win
);
40 void cwmcc_client_set_wm_state(Window win
, gulong state
)
42 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, wm_state
),
43 CWMCC_ATOM(client
, wm_state
), 32, PropModeReplace
,
47 void cwmcc_client_get_name(Window win
, char **name
)
49 if (!prop_get_string_utf8(win
, CWMCC_ATOM(client
, net_wm_name
), name
))
50 if (!prop_get_string_locale(win
, CWMCC_ATOM(client
, wm_name
), name
)) {
51 g_warning("Failed to read a name from 0x%lx", win
);
52 *name
= g_strdup("Unnamed Window");
56 void cwmcc_client_set_name(Window win
, char *name
)
58 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, net_wm_name
),
59 CWMCC_ATOM(type
, utf8
), 32, PropModeReplace
,
60 (guchar
*)name
, strlen(name
));
63 void cwmcc_client_get_icon_name(Window win
, char **name
)
65 if (!prop_get_string_utf8(win
, CWMCC_ATOM(client
, net_wm_icon_name
), name
))
66 if (!prop_get_string_locale(win
,
67 CWMCC_ATOM(client
, wm_icon_name
), name
)) {
68 g_warning("Failed to read an icon name from 0x%lx", win
);
69 *name
= g_strdup("Unnamed Window");
73 void cwmcc_client_set_icon_name(Window win
, char *name
)
75 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, net_wm_icon_name
),
76 CWMCC_ATOM(type
, utf8
), 32, PropModeReplace
,
77 (guchar
*)name
, strlen(name
));
80 void cwmcc_client_get_class(Window win
, char **class, char **name
)
84 if (!prop_get_strings_locale(win
, CWMCC_ATOM(client
, wm_class
), &s
)) {
85 g_warning("Failed to read WM_CLASS from 0x%lx", win
);
86 *class = g_strdup("");
90 g_warning("Failed to read class element of WM_CLASS from 0x%lx",
92 *class = g_strdup("");
94 *class = g_strdup(s
[0]);
96 g_warning("Failed to read name element of WM_CLASS from 0x%lx",
100 *name
= g_strdup(s
[1]);
105 void cwmcc_client_get_role(Window win
, char **role
)
107 if (!prop_get_string_locale(win
,
108 CWMCC_ATOM(client
, wm_window_role
), role
)) {
109 g_warning("Failed to read WM_WINDOW_ROLE from 0x%lx", win
);
110 *role
= g_strdup("");
114 void cwmcc_client_get_mwmhints(Window win
, struct Cwmcc_MwmHints
*hints
)
116 gulong
*l
= NULL
, num
;
118 if (!prop_get_array32(win
, CWMCC_ATOM(client
, motif_wm_hints
),
119 CWMCC_ATOM(client
, motif_wm_hints
), &l
, &num
)) {
120 g_warning("Failed to read Motif WM Hints from 0x%lx", win
);
122 } else if (num
< 3) {
123 g_warning("Read incomplete Motif WM Hints from 0x%lx", win
);
127 hints
->functions
= l
[1];
128 hints
->decorations
= l
[2];
133 void cwmcc_client_get_desktop(Window win
, gulong
*desk
)
135 if (!prop_get32(win
, CWMCC_ATOM(client
, net_wm_desktop
),
136 CWMCC_ATOM(type
, cardinal
), desk
)) {
137 g_warning("Failed to read NET_WM_DESKTOP from 0x%lx", win
);
142 void cwmcc_client_set_desktop(Window win
, gulong desk
)
144 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, net_wm_desktop
),
145 CWMCC_ATOM(type
, cardinal
), 32, PropModeReplace
,
149 void cwmcc_client_get_type(Window win
, gulong
**types
)
153 if (!prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_window_type
),
154 CWMCC_ATOM(type
, atom
), types
, &num
)) {
155 g_warning("Failed to read NET_WM_WINDOW_TYPE from 0x%lx", win
);
156 *types
= g_new(Atom
, 2);
157 (*types
)[0] = CWMCC_ATOM(data
, net_wm_window_type_normal
);
162 void cwmcc_client_set_type(Window win
, gulong
*types
)
167 for (t
= types
, n
= 0; *t
; ++t
, ++n
);
168 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, wm_state
),
169 CWMCC_ATOM(type
, atom
), 32, PropModeReplace
,
173 void cwmcc_client_get_state(Window win
, gulong
**states
)
177 if (!prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_state
),
178 CWMCC_ATOM(type
, atom
), states
, &num
)) {
179 g_warning("Failed to read NET_WM_STATE from 0x%lx", win
);
180 *states
= g_new(Atom
, 1);
185 void cwmcc_client_set_state(Window win
, gulong
*states
)
190 for (s
= states
, n
= 0; *s
; ++s
, ++n
);
191 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, wm_state
),
192 CWMCC_ATOM(type
, atom
), 32, PropModeReplace
,
196 void cwmcc_client_get_strut(Window win
, int *l
, int *t
, int *r
, int *b
)
198 gulong
*data
= NULL
, num
;
200 if (!prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_strut
),
201 CWMCC_ATOM(type
, cardinal
), &data
, &num
)) {
202 g_warning("Failed to read NET_WM_STRUT from 0x%lx", win
);
203 *l
= *t
= *r
= *b
= 0;
204 } else if (num
!= 4) {
205 g_warning("Read invalid NET_WM_STRUT from 0x%lx", win
);
206 *l
= *t
= *r
= *b
= 0;
216 static void convert_pixmap_to_icon(Pixmap pix
, Pixmap mask
,
217 struct Cwmcc_Icon
*icon
)
220 guint pw, ph, mw, mh, depth;
226 if (!XGetGeometry(cwmcc_display, pix, &wjunk, &ijunk, &ijunk, &pw, &ph,
228 g_message("Unable to read pixmap icon's geometry");
229 icon->width = icon->height = 0;
233 if (!XGetGeometry(cwmcc_display, mask, &wjunk, &ijunk, &ijunk, &mw, &mh,
235 g_message("Unable to read pixmap icon's mask's geometry");
236 icon->width = icon->height = 0;
240 if (pw != mw || ph !_ mh) {
241 g_warning("Pixmap icon's mask does not match icon's dimensions");
242 icon->width = icon->height = 0;
247 for (y = 0; y < ph; ++y)
248 for (x = 0; x < pw; ++x) {
251 icon
->width
= icon
->height
= 0;
255 void cwmcc_client_get_icon(Window win
, struct Cwmcc_Icon
**icons
)
257 gulong
*data
= NULL
, num
;
262 if (!prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_icon
),
263 CWMCC_ATOM(type
, cardinal
), &data
, &num
)) {
264 g_warning("Failed to read NET_WM_ICON from 0x%lx", win
);
268 /* figure out how many valid icons are in here */
271 while (num
- i
> 2) {
279 *icons
= g_new(struct Cwmcc_Icon
, nicons
+ 1);
280 (*icons
)[nicons
].data
= NULL
;
282 /* store the icons */
284 for (j
= 0; j
< nicons
; ++j
) {
285 w
= (*icons
)[j
].width
= data
[i
++];
286 h
= (*icons
)[j
].height
= data
[i
++];
288 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
296 if (!prop_get_array32(win
, CWMCC_ATOM(client
, kwm_win_icon
),
297 CWMCC_ATOM(client
, kwm_win_icon
), &data
, &num
)) {
298 g_warning("Failed to read KWM_WIN_ICON from 0x%lx", win
);
299 } else if (num
!= 2) {
300 g_warning("Read invalid KWM_WIN_ICON from 0x%lx", win
);
303 struct Cwmcc_Icon icon
;
308 convert_pixmap_to_icon(p
, m
, &icon
);
311 *icons
= g_renew(struct Cwmcc_Icon
, *icons
, nicons
+ 2);
312 (*icons
[nicons
+ 1]).data
= NULL
;
313 g_memmove(&(*icons
)[nicons
], &icon
, sizeof(struct Cwmcc_Icon
));
320 void cwmcc_client_get_premax(Window win
, int *x
, int *y
, int *w
, int *h
)
322 gulong
*l
= NULL
, num
;
324 if (!prop_get_array32(win
, CWMCC_ATOM(client
, openbox_premax
),
325 CWMCC_ATOM(type
, cardinal
), &l
, &num
)) {
326 g_warning("Failed to read OPENBOX_PREMAX from 0x%lx", win
);
327 *x
= *y
= *w
= *h
= 0;
328 } else if (num
!= 4) {
329 g_warning("Read invalid OPENBOX_PREMAX from 0x%lx", win
);
330 *x
= *y
= *w
= *h
= 0;
340 void cwmcc_client_set_premax(Window win
, int x
, int y
, int w
, int h
)
348 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, openbox_premax
),
349 CWMCC_ATOM(type
, cardinal
), 32, PropModeReplace
,