1 #include "cwmcc_internal.h"
4 #include "client_props.h"
5 #include "render/render.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
)) {
19 void cwmcc_client_set_protocols(Window win
, Atom
*protocols
)
24 for (a
= protocols
, n
= 0; *a
; ++a
, ++n
);
25 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, wm_state
),
26 CWMCC_ATOM(type
, atom
), 32, PropModeReplace
,
27 (guchar
*)protocols
, n
);
30 void cwmcc_client_get_wm_state(Window win
, gulong
*state
)
32 if (!prop_get32(win
, CWMCC_ATOM(client
, wm_state
),
33 CWMCC_ATOM(client
, wm_state
), state
)) {
34 g_warning("Failed to read WM_STATE from 0x%lx", win
);
39 void cwmcc_client_set_wm_state(Window win
, gulong state
)
41 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, wm_state
),
42 CWMCC_ATOM(client
, wm_state
), 32, PropModeReplace
,
46 void cwmcc_client_get_name(Window win
, char **name
)
48 if (!prop_get_string_utf8(win
, CWMCC_ATOM(client
, net_wm_name
), name
))
49 if (!prop_get_string_locale(win
, CWMCC_ATOM(client
, wm_name
), name
)) {
50 g_warning("Failed to read a name from 0x%lx", win
);
51 *name
= g_strdup("Unnamed Window");
55 void cwmcc_client_get_icon_name(Window win
, char **name
)
57 if (!prop_get_string_utf8(win
, CWMCC_ATOM(client
, net_wm_icon_name
), name
))
58 if (!prop_get_string_locale(win
,
59 CWMCC_ATOM(client
, wm_icon_name
), name
)) {
60 g_warning("Failed to read an icon name from 0x%lx", win
);
61 *name
= g_strdup("Unnamed Window");
65 void cwmcc_client_get_class(Window win
, char **class, char **name
)
69 if (!prop_get_strings_locale(win
, CWMCC_ATOM(client
, wm_class
), &s
)) {
70 g_warning("Failed to read WM_CLASS from 0x%lx", win
);
71 *class = g_strdup("");
75 g_warning("Failed to read class element of WM_CLASS from 0x%lx",
77 *class = g_strdup("");
79 *class = g_strdup(s
[0]);
81 g_warning("Failed to read name element of WM_CLASS from 0x%lx",
85 *name
= g_strdup(s
[1]);
90 void cwmcc_client_get_role(Window win
, char **role
)
92 if (!prop_get_string_locale(win
,
93 CWMCC_ATOM(client
, wm_window_role
), role
)) {
94 g_warning("Failed to read WM_WINDOW_ROLE from 0x%lx", win
);
99 void cwmcc_client_get_mwmhints(Window win
, struct Cwmcc_MwmHints
*hints
)
101 gulong
*l
= NULL
, num
;
103 if (!prop_get_array32(win
, CWMCC_ATOM(client
, motif_wm_hints
),
104 CWMCC_ATOM(client
, motif_wm_hints
), &l
, &num
)) {
105 g_warning("Failed to read Motif WM Hints from 0x%lx", win
);
107 } else if (num
< 3) {
108 g_warning("Read incomplete Motif WM Hints from 0x%lx", win
);
112 hints
->functions
= l
[1];
113 hints
->decorations
= l
[2];
118 void cwmcc_client_get_desktop(Window win
, gulong
*desk
)
120 if (!prop_get32(win
, CWMCC_ATOM(client
, net_wm_desktop
),
121 CWMCC_ATOM(type
, cardinal
), desk
)) {
122 g_warning("Failed to read NET_WM_DESKTOP from 0x%lx", win
);
127 void cwmcc_client_set_desktop(Window win
, gulong desk
)
129 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, net_wm_desktop
),
130 CWMCC_ATOM(type
, cardinal
), 32, PropModeReplace
,
134 void cwmcc_client_get_type(Window win
, gulong
**types
)
138 if (!prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_window_type
),
139 CWMCC_ATOM(type
, atom
), types
, &num
)) {
140 g_warning("Failed to read NET_WM_WINDOW_TYPE from 0x%lx", win
);
141 *types
= g_new(Atom
, 2);
142 (*types
)[0] = CWMCC_ATOM(data
, net_wm_window_type_normal
);
147 void cwmcc_client_set_type(Window win
, gulong
*types
)
152 for (t
= types
, n
= 0; *t
; ++t
, ++n
);
153 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, wm_state
),
154 CWMCC_ATOM(type
, atom
), 32, PropModeReplace
,
158 void cwmcc_client_get_state(Window win
, gulong
**states
)
162 if (!prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_state
),
163 CWMCC_ATOM(type
, atom
), states
, &num
)) {
164 g_warning("Failed to read NET_WM_STATE from 0x%lx", win
);
165 *states
= g_new(Atom
, 1);
170 void cwmcc_client_set_state(Window win
, gulong
*states
)
175 for (s
= states
, n
= 0; *s
; ++s
, ++n
);
176 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, wm_state
),
177 CWMCC_ATOM(type
, atom
), 32, PropModeReplace
,
181 void cwmcc_client_get_strut(Window win
, int *l
, int *t
, int *r
, int *b
)
183 gulong
*data
= NULL
, num
;
185 if (!prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_strut
),
186 CWMCC_ATOM(type
, cardinal
), &data
, &num
)) {
187 g_warning("Failed to read NET_WM_STRUT from 0x%lx", win
);
188 *l
= *t
= *r
= *b
= 0;
189 } else if (num
!= 4) {
190 g_warning("Read invalid NET_WM_STRUT from 0x%lx", win
);
191 *l
= *t
= *r
= *b
= 0;
201 static void convert_pixmap_to_icon(Pixmap pix
, Pixmap mask
,
202 struct Cwmcc_Icon
*icon
)
205 guint pw, ph, mw, mh, depth;
211 if (!XGetGeometry(cwmcc_display, pix, &wjunk, &ijunk, &ijunk, &pw, &ph,
213 g_message("Unable to read pixmap icon's geometry");
214 icon->width = icon->height = 0;
218 if (!XGetGeometry(cwmcc_display, mask, &wjunk, &ijunk, &ijunk, &mw, &mh,
220 g_message("Unable to read pixmap icon's mask's geometry");
221 icon->width = icon->height = 0;
225 if (pw != mw || ph !_ mh) {
226 g_warning("Pixmap icon's mask does not match icon's dimensions");
227 icon->width = icon->height = 0;
232 for (y = 0; y < ph; ++y)
233 for (x = 0; x < pw; ++x) {
236 icon
->width
= icon
->height
= 0;
240 void cwmcc_client_get_icon(Window win
, struct Cwmcc_Icon
**icons
)
242 gulong
*data
= NULL
, num
;
247 if (!prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_icon
),
248 CWMCC_ATOM(type
, cardinal
), &data
, &num
)) {
249 g_warning("Failed to read NET_WM_ICON from 0x%lx", win
);
253 /* figure out how many valid icons are in here */
256 while (num
- i
> 2) {
264 *icons
= g_new(struct Cwmcc_Icon
, nicons
+ 1);
265 (*icons
)[nicons
].data
= NULL
;
267 /* store the icons */
269 for (j
= 0; j
< nicons
; ++j
) {
270 w
= (*icons
)[j
].width
= data
[i
++];
271 h
= (*icons
)[j
].height
= data
[i
++];
273 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
281 if (!prop_get_array32(win
, CWMCC_ATOM(client
, kwm_win_icon
),
282 CWMCC_ATOM(client
, kwm_win_icon
), &data
, &num
)) {
283 g_warning("Failed to read KWM_WIN_ICON from 0x%lx", win
);
284 } else if (num
!= 2) {
285 g_warning("Read invalid KWM_WIN_ICON from 0x%lx", win
);
288 struct Cwmcc_Icon icon
;
293 convert_pixmap_to_icon(p
, m
, &icon
);
296 *icons
= g_renew(struct Cwmcc_Icon
, *icons
, nicons
+ 2);
297 (*icons
[nicons
+ 1]).data
= NULL
;
298 g_memmove(&(*icons
)[nicons
], &icon
, sizeof(struct Cwmcc_Icon
));
305 void cwmcc_client_get_premax(Window win
, int *x
, int *y
, int *w
, int *h
)
307 gulong
*l
= NULL
, num
;
309 if (!prop_get_array32(win
, CWMCC_ATOM(client
, openbox_premax
),
310 CWMCC_ATOM(type
, cardinal
), &l
, &num
)) {
311 g_warning("Failed to read OPENBOX_PREMAX from 0x%lx", win
);
312 *x
= *y
= *w
= *h
= 0;
313 } else if (num
!= 4) {
314 g_warning("Read invalid OPENBOX_PREMAX from 0x%lx", win
);
315 *x
= *y
= *w
= *h
= 0;
325 void cwmcc_client_set_premax(Window win
, int x
, int y
, int w
, int h
)
333 XChangeProperty(cwmcc_display
, win
, CWMCC_ATOM(client
, openbox_premax
),
334 CWMCC_ATOM(type
, cardinal
), 32, PropModeReplace
,