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 int cwmcc_client_get_wm_state(Window win)
23 if (!prop_get32(win, CWMCC_ATOM(client, wm_state),
24 CWMCC_ATOM(client, wm_state), &s)) {
25 g_warning("Failed to read WM_STATE from 0x%lx", win);
31 void cwmcc_client_get_name(Window win, char **name)
33 if (!prop_get_string_utf8(win, CWMCC_ATOM(client, net_wm_name), name))
34 if (!prop_get_string_locale(win, CWMCC_ATOM(client, wm_name), name)) {
35 g_warning("Failed to read a name from 0x%lx", win);
36 *name = g_strdup("Unnamed Window");
40 void cwmcc_client_get_icon_name(Window win, char **name)
42 if (!prop_get_string_utf8(win, CWMCC_ATOM(client, net_wm_icon_name), name))
43 if (!prop_get_string_locale(win,
44 CWMCC_ATOM(client, wm_icon_name), name)) {
45 g_warning("Failed to read an icon name from 0x%lx", win);
46 *name = g_strdup("Unnamed Window");
50 void cwmcc_client_get_class(Window win, char **class, char **name)
54 if (!prop_get_strings_locale(win, CWMCC_ATOM(client, wm_class), &s)) {
55 g_warning("Failed to read WM_CLASS from 0x%lx", win);
56 *class = g_strdup("");
60 g_warning("Failed to read class element of WM_CLASS from 0x%lx",
62 *class = g_strdup("");
64 *class = g_strdup(s[0]);
66 g_warning("Failed to read name element of WM_CLASS from 0x%lx",
70 *name = g_strdup(s[1]);
75 void cwmcc_client_get_role(Window win, char **role)
77 if (!prop_get_string_locale(win,
78 CWMCC_ATOM(client, wm_window_role), role)) {
79 g_warning("Failed to read WM_WINDOW_ROLE from 0x%lx", win);
84 void cwmcc_client_get_mwmhints(Window win, struct Cwmcc_MwmHints *hints)
86 gulong *l = NULL, num;
88 if (!prop_get_array32(win, CWMCC_ATOM(client, motif_wm_hints),
89 CWMCC_ATOM(client, motif_wm_hints), &l, &num)) {
90 g_warning("Failed to read Motif WM Hints from 0x%lx", win);
93 g_warning("Read incomplete Motif WM Hints from 0x%lx", win);
97 hints->functions = l[1];
98 hints->decorations = l[2];
103 void cwmcc_client_get_desktop(Window win, gulong *desk)
105 if (!prop_get32(win, CWMCC_ATOM(client, net_wm_desktop),
106 CWMCC_ATOM(type, cardinal), desk)) {
107 g_warning("Failed to read NET_WM_DESKTOP from 0x%lx", win);
112 void cwmcc_client_get_type(Window win, gulong **types)
116 if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_window_type),
117 CWMCC_ATOM(type, atom), types, &num)) {
118 g_warning("Failed to read NET_WM_WINDOW_TYPE from 0x%lx", win);
119 *types = g_new(Atom, 2);
120 (*types)[0] = CWMCC_ATOM(data, net_wm_window_type_normal);
125 void cwmcc_client_get_state(Window win, gulong **states)
129 if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_state),
130 CWMCC_ATOM(type, atom), states, &num)) {
131 g_warning("Failed to read NET_WM_STATE from 0x%lx", win);
132 *states = g_new(Atom, 1);
137 void cwmcc_client_get_strut(Window win, int *l, int *t, int *r, int *b)
139 gulong *data = NULL, num;
141 if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_strut),
142 CWMCC_ATOM(type, cardinal), &data, &num)) {
143 g_warning("Failed to read NET_WM_STRUT from 0x%lx", win);
144 *l = *t = *r = *b = 0;
145 } else if (num != 4) {
146 g_warning("Read invalid NET_WM_STRUT from 0x%lx", win);
147 *l = *t = *r = *b = 0;
157 static void convert_pixmap_to_icon(Pixmap pix, Pixmap mask,
158 struct Cwmcc_Icon *icon)
161 guint pw, ph, mw, mh, depth;
167 if (!XGetGeometry(cwmcc_display, pix, &wjunk, &ijunk, &ijunk, &pw, &ph,
169 g_message("Unable to read pixmap icon's geometry");
170 icon->width = icon->height = 0;
174 if (!XGetGeometry(cwmcc_display, mask, &wjunk, &ijunk, &ijunk, &mw, &mh,
176 g_message("Unable to read pixmap icon's mask's geometry");
177 icon->width = icon->height = 0;
181 if (pw != mw || ph !_ mh) {
182 g_warning("Pixmap icon's mask does not match icon's dimensions");
183 icon->width = icon->height = 0;
188 for (y = 0; y < ph; ++y)
189 for (x = 0; x < pw; ++x) {
192 icon->width = icon->height = 0;
196 void cwmcc_client_get_icon(Window win, struct Cwmcc_Icon **icons)
198 gulong *data = NULL, num;
203 if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_icon),
204 CWMCC_ATOM(type, cardinal), &data, &num)) {
205 g_warning("Failed to read NET_WM_ICON from 0x%lx", win);
209 /* figure out how many valid icons are in here */
212 while (num - i > 2) {
220 *icons = g_new(struct Cwmcc_Icon, nicons + 1);
221 (*icons)[nicons].data = NULL;
223 /* store the icons */
225 for (j = 0; j < nicons; ++j) {
226 w = (*icons)[j].width = data[i++];
227 h = (*icons)[j].height = data[i++];
229 g_memdup(&data[i], w * h * sizeof(gulong));
237 if (!prop_get_array32(win, CWMCC_ATOM(client, kwm_win_icon),
238 CWMCC_ATOM(client, kwm_win_icon), &data, &num)) {
239 g_warning("Failed to read KWM_WIN_ICON from 0x%lx", win);
240 } else if (num != 2) {
241 g_warning("Read invalid KWM_WIN_ICON from 0x%lx", win);
244 struct Cwmcc_Icon icon;
249 convert_pixmap_to_icon(p, m, &icon);
252 *icons = g_renew(struct Cwmcc_Icon, *icons, nicons + 2);
253 (*icons[nicons + 1]).data = NULL;
254 g_memmove(&(*icons)[nicons], &icon, sizeof(struct Cwmcc_Icon));
261 void cwmcc_client_get_premax(Window win, int *x, int *y, int *w, int *h)
263 gulong *l = NULL, num;
265 if (!prop_get_array32(win, CWMCC_ATOM(client, openbox_premax),
266 CWMCC_ATOM(type, cardinal), &l, &num)) {
267 g_warning("Failed to read OPENBOX_PREMAX from 0x%lx", win);
268 *x = *y = *w = *h = 0;
269 } else if (num != 4) {
270 g_warning("Read invalid OPENBOX_PREMAX from 0x%lx", win);
271 *x = *y = *w = *h = 0;
281 void cwmcc_client_set_premax(Window win, int x, int y, int w, int h)
289 XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, openbox_premax),
290 CWMCC_ATOM(type, cardinal), 32, PropModeReplace,