1 #include "cwmcc_internal.h"
4 #include "client_props.h"
9 void cwmcc_client_get_protocols(Window win
, Atom
**protocols
, gulong
*num
)
11 if (!cwmcc_prop_get_array32(win
, CWMCC_ATOM(client
, wm_protocols
),
12 CWMCC_ATOM(type
, atom
), protocols
, num
)) {
13 g_warning("Failed to read WM_PROTOCOLS from 0x%lx", win
);
19 void cwmcc_client_set_protocols(Window win
, Atom
*protocols
, gulong num
)
21 cwmcc_prop_set_array32(win
, CWMCC_ATOM(client
, wm_state
),
22 CWMCC_ATOM(type
, atom
), protocols
, num
);
25 void cwmcc_client_get_wm_state(Window win
, gulong
*state
)
27 if (!cwmcc_prop_get32(win
, CWMCC_ATOM(client
, wm_state
),
28 CWMCC_ATOM(client
, wm_state
), state
)) {
29 g_warning("Failed to read WM_STATE from 0x%lx", win
);
34 void cwmcc_client_set_wm_state(Window win
, gulong state
)
36 cwmcc_prop_set32(win
, CWMCC_ATOM(client
, wm_state
),
37 CWMCC_ATOM(client
, wm_state
), state
);
40 void cwmcc_client_get_name(Window win
, char **name
)
42 if (!cwmcc_prop_get_string_utf8(win
, CWMCC_ATOM(client
, net_wm_name
),
44 if (!cwmcc_prop_get_string_locale(win
, CWMCC_ATOM(client
, wm_name
),
46 g_warning("Failed to read a name from 0x%lx", win
);
47 *name
= g_strdup("Unnamed Window");
51 void cwmcc_client_set_name(Window win
, char *name
)
53 cwmcc_prop_set_string_utf8(win
, CWMCC_ATOM(client
, net_wm_name
), name
);
56 void cwmcc_client_get_icon_name(Window win
, char **name
)
58 if (!cwmcc_prop_get_string_utf8(win
, CWMCC_ATOM(client
, net_wm_icon_name
),
60 if (!cwmcc_prop_get_string_locale(win
,CWMCC_ATOM(client
, wm_icon_name
),
62 g_warning("Failed to read an icon name from 0x%lx", win
);
63 *name
= g_strdup("Unnamed Window");
67 void cwmcc_client_set_icon_name(Window win
, char *name
)
69 cwmcc_prop_set_string_utf8(win
, CWMCC_ATOM(client
, net_wm_icon_name
),name
);
72 void cwmcc_client_get_class(Window win
, char **class, char **name
)
76 if (!cwmcc_prop_get_strings_locale(win
, CWMCC_ATOM(client
, wm_class
), &s
)){
77 g_warning("Failed to read WM_CLASS from 0x%lx", win
);
78 *class = g_strdup("");
82 g_warning("Failed to read class element of WM_CLASS from 0x%lx",
84 *class = g_strdup("");
86 *class = g_strdup(s
[0]);
88 g_warning("Failed to read name element of WM_CLASS from 0x%lx",
92 *name
= g_strdup(s
[1]);
97 void cwmcc_client_get_role(Window win
, char **role
)
99 if (!cwmcc_prop_get_string_locale(win
, CWMCC_ATOM(client
, wm_window_role
),
101 g_warning("Failed to read WM_WINDOW_ROLE from 0x%lx", win
);
102 *role
= g_strdup("");
106 void cwmcc_client_get_mwmhints(Window win
, struct Cwmcc_MwmHints
*hints
)
108 gulong
*l
= NULL
, num
;
110 if (!cwmcc_prop_get_array32(win
, CWMCC_ATOM(client
, motif_wm_hints
),
111 CWMCC_ATOM(client
, motif_wm_hints
), &l
, &num
)){
112 g_warning("Failed to read Motif WM Hints from 0x%lx", win
);
114 } else if (num
< 3) {
115 g_warning("Read incomplete Motif WM Hints from 0x%lx", win
);
119 hints
->functions
= l
[1];
120 hints
->decorations
= l
[2];
125 void cwmcc_client_get_desktop(Window win
, gulong
*desk
)
127 if (!cwmcc_prop_get32(win
, CWMCC_ATOM(client
, net_wm_desktop
),
128 CWMCC_ATOM(type
, cardinal
), desk
)) {
129 g_warning("Failed to read NET_WM_DESKTOP from 0x%lx", win
);
134 void cwmcc_client_set_desktop(Window win
, gulong desk
)
136 cwmcc_prop_set32(win
, CWMCC_ATOM(client
, net_wm_desktop
),
137 CWMCC_ATOM(type
, cardinal
), desk
);
140 void cwmcc_client_get_type(Window win
, gulong
**types
, gulong
*num
)
142 if (!cwmcc_prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_window_type
),
143 CWMCC_ATOM(type
, atom
), types
, num
)) {
144 g_warning("Failed to read NET_WM_WINDOW_TYPE from 0x%lx", win
);
145 *types
= g_new(Atom
, 1);
146 (*types
)[0] = CWMCC_ATOM(data
, net_wm_window_type_normal
);
151 void cwmcc_client_set_type(Window win
, gulong
*types
, gulong num
)
153 cwmcc_prop_set_array32(win
, CWMCC_ATOM(client
, net_wm_window_type
),
154 CWMCC_ATOM(type
, atom
), types
, num
);
157 void cwmcc_client_get_state(Window win
, gulong
**states
, gulong
*num
)
159 if (!cwmcc_prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_state
),
160 CWMCC_ATOM(type
, atom
), states
, num
)) {
161 g_warning("Failed to read NET_WM_STATE from 0x%lx", win
);
167 void cwmcc_client_set_state(Window win
, gulong
*states
, gulong num
)
169 cwmcc_prop_set_array32(win
, CWMCC_ATOM(client
, net_wm_state
),
170 CWMCC_ATOM(type
, atom
), states
, num
);
173 void cwmcc_client_get_strut(Window win
, int *l
, int *t
, int *r
, int *b
)
175 gulong
*data
= NULL
, num
;
177 if (!cwmcc_prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_strut
),
178 CWMCC_ATOM(type
, cardinal
), &data
, &num
)) {
179 g_warning("Failed to read NET_WM_STRUT from 0x%lx", win
);
180 *l
= *t
= *r
= *b
= 0;
181 } else if (num
!= 4) {
182 g_warning("Read invalid NET_WM_STRUT from 0x%lx", win
);
183 *l
= *t
= *r
= *b
= 0;
193 void cwmcc_client_set_strut(Window win
, int l
, int t
, int r
, int b
)
201 cwmcc_prop_set_array32(win
, CWMCC_ATOM(client
, net_wm_strut
),
202 CWMCC_ATOM(type
, cardinal
), data
, 4);
205 static void convert_pixmap_to_icon(Pixmap pix
, Pixmap mask
,
206 struct Cwmcc_Icon
*icon
)
209 guint pw, ph, mw, mh, depth;
215 if (!XGetGeometry(cwmcc_display, pix, &wjunk, &ijunk, &ijunk, &pw, &ph,
217 g_message("Unable to read pixmap icon's geometry");
218 icon->width = icon->height = 0;
222 if (!XGetGeometry(cwmcc_display, mask, &wjunk, &ijunk, &ijunk, &mw, &mh,
224 g_message("Unable to read pixmap icon's mask's geometry");
225 icon->width = icon->height = 0;
229 if (pw != mw || ph !_ mh) {
230 g_warning("Pixmap icon's mask does not match icon's dimensions");
231 icon->width = icon->height = 0;
236 for (y = 0; y < ph; ++y)
237 for (x = 0; x < pw; ++x) {
240 icon
->width
= icon
->height
= 0;
244 void cwmcc_client_get_icon(Window win
, struct Cwmcc_Icon
**icons
, gulong
*num
)
251 if (!cwmcc_prop_get_array32(win
, CWMCC_ATOM(client
, net_wm_icon
),
252 CWMCC_ATOM(type
, cardinal
), &data
, num
)) {
253 g_warning("Failed to read NET_WM_ICON from 0x%lx", win
);
257 /* figure out how many valid icons are in here */
260 while (*num
- i
> 2) {
268 *icons
= g_new(struct Cwmcc_Icon
, nicons
);
270 /* store the icons */
272 for (j
= 0; j
< nicons
; ++j
) {
273 w
= (*icons
)[j
].width
= data
[i
++];
274 h
= (*icons
)[j
].height
= data
[i
++];
276 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
284 if (!cwmcc_prop_get_array32(win
, CWMCC_ATOM(client
, kwm_win_icon
),
285 CWMCC_ATOM(client
, kwm_win_icon
), &data
, num
)){
286 g_warning("Failed to read KWM_WIN_ICON from 0x%lx", win
);
287 } else if (*num
!= 2) {
288 g_warning("Read invalid KWM_WIN_ICON from 0x%lx", win
);
291 struct Cwmcc_Icon icon
;
296 convert_pixmap_to_icon(p
, m
, &icon
);
300 *icons
= g_renew(struct Cwmcc_Icon
, *icons
, nicons
);
301 (*icons
[nicons
]).data
= NULL
;
302 g_memmove(&(*icons
)[nicons
-1], &icon
, sizeof(struct Cwmcc_Icon
));
310 void cwmcc_client_get_premax(Window win
, int *x
, int *y
, int *w
, int *h
)
312 gulong
*l
= NULL
, num
;
314 if (!cwmcc_prop_get_array32(win
, CWMCC_ATOM(client
, openbox_premax
),
315 CWMCC_ATOM(type
, cardinal
), &l
, &num
)) {
316 g_warning("Failed to read OPENBOX_PREMAX from 0x%lx", win
);
317 *x
= *y
= *w
= *h
= 0;
318 } else if (num
!= 4) {
319 g_warning("Read invalid OPENBOX_PREMAX from 0x%lx", win
);
320 *x
= *y
= *w
= *h
= 0;
330 void cwmcc_client_set_premax(Window win
, int x
, int y
, int w
, int h
)
338 cwmcc_prop_set_array32(win
, CWMCC_ATOM(client
, openbox_premax
),
339 CWMCC_ATOM(type
, cardinal
), l
, 4);