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)) {
22 void cwmcc_client_set_protocols(Window win, Atom *protocols)
27 for (a = protocols, n = 0; *a; ++a, ++n);
28 XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, wm_state),
29 CWMCC_ATOM(type, atom), 32, PropModeReplace,
30 (guchar*)protocols, n);
33 void cwmcc_client_get_wm_state(Window win, gulong *state)
35 if (!prop_get32(win, CWMCC_ATOM(client, wm_state),
36 CWMCC_ATOM(client, wm_state), state)) {
37 g_warning("Failed to read WM_STATE from 0x%lx", win);
42 void cwmcc_client_set_wm_state(Window win, gulong state)
44 XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, wm_state),
45 CWMCC_ATOM(client, wm_state), 32, PropModeReplace,
49 void cwmcc_client_get_name(Window win, char **name)
51 if (!prop_get_string_utf8(win, CWMCC_ATOM(client, net_wm_name), name))
52 if (!prop_get_string_locale(win, CWMCC_ATOM(client, wm_name), name)) {
53 g_warning("Failed to read a name from 0x%lx", win);
54 *name = g_strdup("Unnamed Window");
58 void cwmcc_client_set_name(Window win, char *name)
60 XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, net_wm_name),
61 CWMCC_ATOM(type, utf8), 32, PropModeReplace,
62 (guchar*)name, strlen(name));
65 void cwmcc_client_get_icon_name(Window win, char **name)
67 if (!prop_get_string_utf8(win, CWMCC_ATOM(client, net_wm_icon_name), name))
68 if (!prop_get_string_locale(win,
69 CWMCC_ATOM(client, wm_icon_name), name)) {
70 g_warning("Failed to read an icon name from 0x%lx", win);
71 *name = g_strdup("Unnamed Window");
75 void cwmcc_client_set_icon_name(Window win, char *name)
77 XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, net_wm_icon_name),
78 CWMCC_ATOM(type, utf8), 32, PropModeReplace,
79 (guchar*)name, strlen(name));
82 void cwmcc_client_get_class(Window win, char **class, char **name)
86 if (!prop_get_strings_locale(win, CWMCC_ATOM(client, wm_class), &s)) {
87 g_warning("Failed to read WM_CLASS from 0x%lx", win);
88 *class = g_strdup("");
92 g_warning("Failed to read class element of WM_CLASS from 0x%lx",
94 *class = g_strdup("");
96 *class = g_strdup(s[0]);
98 g_warning("Failed to read name element of WM_CLASS from 0x%lx",
100 *name = g_strdup("");
102 *name = g_strdup(s[1]);
107 void cwmcc_client_get_role(Window win, char **role)
109 if (!prop_get_string_locale(win,
110 CWMCC_ATOM(client, wm_window_role), role)) {
111 g_warning("Failed to read WM_WINDOW_ROLE from 0x%lx", win);
112 *role = g_strdup("");
116 void cwmcc_client_get_mwmhints(Window win, struct Cwmcc_MwmHints *hints)
118 gulong *l = NULL, num;
120 if (!prop_get_array32(win, CWMCC_ATOM(client, motif_wm_hints),
121 CWMCC_ATOM(client, motif_wm_hints), &l, &num)) {
122 g_warning("Failed to read Motif WM Hints from 0x%lx", win);
124 } else if (num < 3) {
125 g_warning("Read incomplete Motif WM Hints from 0x%lx", win);
129 hints->functions = l[1];
130 hints->decorations = l[2];
135 void cwmcc_client_get_desktop(Window win, gulong *desk)
137 if (!prop_get32(win, CWMCC_ATOM(client, net_wm_desktop),
138 CWMCC_ATOM(type, cardinal), desk)) {
139 g_warning("Failed to read NET_WM_DESKTOP from 0x%lx", win);
144 void cwmcc_client_set_desktop(Window win, gulong desk)
146 XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, net_wm_desktop),
147 CWMCC_ATOM(type, cardinal), 32, PropModeReplace,
151 void cwmcc_client_get_type(Window win, gulong **types)
155 if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_window_type),
156 CWMCC_ATOM(type, atom), types, &num)) {
157 g_warning("Failed to read NET_WM_WINDOW_TYPE from 0x%lx", win);
158 *types = g_new(Atom, 2);
159 (*types)[0] = CWMCC_ATOM(data, net_wm_window_type_normal);
164 void cwmcc_client_set_type(Window win, gulong *types)
169 for (t = types, n = 0; *t; ++t, ++n);
170 XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, wm_state),
171 CWMCC_ATOM(type, atom), 32, PropModeReplace,
175 void cwmcc_client_get_state(Window win, gulong **states)
179 if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_state),
180 CWMCC_ATOM(type, atom), states, &num)) {
181 g_warning("Failed to read NET_WM_STATE from 0x%lx", win);
182 *states = g_new(Atom, 1);
187 void cwmcc_client_set_state(Window win, gulong *states)
192 for (s = states, n = 0; *s; ++s, ++n);
193 XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, wm_state),
194 CWMCC_ATOM(type, atom), 32, PropModeReplace,
198 void cwmcc_client_get_strut(Window win, int *l, int *t, int *r, int *b)
200 gulong *data = NULL, num;
202 if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_strut),
203 CWMCC_ATOM(type, cardinal), &data, &num)) {
204 g_warning("Failed to read NET_WM_STRUT from 0x%lx", win);
205 *l = *t = *r = *b = 0;
206 } else if (num != 4) {
207 g_warning("Read invalid NET_WM_STRUT from 0x%lx", win);
208 *l = *t = *r = *b = 0;
218 static void convert_pixmap_to_icon(Pixmap pix, Pixmap mask,
219 struct Cwmcc_Icon *icon)
222 guint pw, ph, mw, mh, depth;
228 if (!XGetGeometry(cwmcc_display, pix, &wjunk, &ijunk, &ijunk, &pw, &ph,
230 g_message("Unable to read pixmap icon's geometry");
231 icon->width = icon->height = 0;
235 if (!XGetGeometry(cwmcc_display, mask, &wjunk, &ijunk, &ijunk, &mw, &mh,
237 g_message("Unable to read pixmap icon's mask's geometry");
238 icon->width = icon->height = 0;
242 if (pw != mw || ph !_ mh) {
243 g_warning("Pixmap icon's mask does not match icon's dimensions");
244 icon->width = icon->height = 0;
249 for (y = 0; y < ph; ++y)
250 for (x = 0; x < pw; ++x) {
253 icon->width = icon->height = 0;
257 void cwmcc_client_get_icon(Window win, struct Cwmcc_Icon **icons)
259 gulong *data = NULL, num;
264 if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_icon),
265 CWMCC_ATOM(type, cardinal), &data, &num)) {
266 g_warning("Failed to read NET_WM_ICON from 0x%lx", win);
270 /* figure out how many valid icons are in here */
273 while (num - i > 2) {
281 *icons = g_new(struct Cwmcc_Icon, nicons + 1);
282 (*icons)[nicons].data = NULL;
284 /* store the icons */
286 for (j = 0; j < nicons; ++j) {
287 w = (*icons)[j].width = data[i++];
288 h = (*icons)[j].height = data[i++];
290 g_memdup(&data[i], w * h * sizeof(gulong));
298 if (!prop_get_array32(win, CWMCC_ATOM(client, kwm_win_icon),
299 CWMCC_ATOM(client, kwm_win_icon), &data, &num)) {
300 g_warning("Failed to read KWM_WIN_ICON from 0x%lx", win);
301 } else if (num != 2) {
302 g_warning("Read invalid KWM_WIN_ICON from 0x%lx", win);
305 struct Cwmcc_Icon icon;
310 convert_pixmap_to_icon(p, m, &icon);
313 *icons = g_renew(struct Cwmcc_Icon, *icons, nicons + 2);
314 (*icons[nicons + 1]).data = NULL;
315 g_memmove(&(*icons)[nicons], &icon, sizeof(struct Cwmcc_Icon));
322 void cwmcc_client_get_premax(Window win, int *x, int *y, int *w, int *h)
324 gulong *l = NULL, num;
326 if (!prop_get_array32(win, CWMCC_ATOM(client, openbox_premax),
327 CWMCC_ATOM(type, cardinal), &l, &num)) {
328 g_warning("Failed to read OPENBOX_PREMAX from 0x%lx", win);
329 *x = *y = *w = *h = 0;
330 } else if (num != 4) {
331 g_warning("Read invalid OPENBOX_PREMAX from 0x%lx", win);
332 *x = *y = *w = *h = 0;
342 void cwmcc_client_set_premax(Window win, int x, int y, int w, int h)
350 XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, openbox_premax),
351 CWMCC_ATOM(type, cardinal), 32, PropModeReplace,