]> icculus.org git repositories - dana/openbox.git/blob - cwmcc/root_props.c
add most of the root window props get functions
[dana/openbox.git] / cwmcc / root_props.c
1 #include "cwmcc_internal.h"
2 #include "atom.h"
3 #include "prop.h"
4 #include "root_props.h"
5
6 #ifdef HAVE_STRING_H
7 #  include <string.h>
8 #endif
9
10 void cwmcc_root_get_supported(Window win, Atom **atoms)
11 {
12     gulong num;
13
14     if (!prop_get_array32(win, CWMCC_ATOM(root, net_supported),
15                           CWMCC_ATOM(type, atom), atoms, &num)) {
16         g_warning("Failed to read NET_SUPPORTED from 0x%lx", win);
17         *atoms = NULL;
18     }
19 }
20
21 void cwmcc_root_get_client_list(Window win, Window **windows)
22 {
23     gulong num;
24
25     if (!prop_get_array32(win, CWMCC_ATOM(root, net_client_list),
26                           CWMCC_ATOM(type, window), windows, &num)) {
27         g_warning("Failed to read NET_CLIENT_LIST from 0x%lx", win);
28         *windows = NULL;
29     }
30 }
31
32 void cwmcc_root_get_client_list_stacking(Window win, Window **windows)
33 {
34     gulong num;
35
36     if (!prop_get_array32(win, CWMCC_ATOM(root, net_client_list_stacking),
37                           CWMCC_ATOM(type, window), windows, &num)) {
38         g_warning("Failed to read NET_CLIENT_LIST_STACKING from 0x%lx", win);
39         *windows = NULL;
40     }
41 }
42
43 void cwmcc_root_get_number_of_desktops(Window win, gulong *desktops)
44 {
45     if (!prop_get32(win, CWMCC_ATOM(root, net_number_of_desktops),
46                     CWMCC_ATOM(type, cardinal), desktops)) {
47         g_warning("Failed to read NET_NUMBER_OF_DESKTOPS from 0x%lx", win);
48         *desktops = 1;
49     }
50 }
51
52 void cwmcc_root_get_desktop_geometry(Window win, gulong *w, gulong *h)
53 {
54     gulong *data = NULL, num;
55
56     if (!prop_get_array32(win, CWMCC_ATOM(root, net_desktop_geometry),
57                     CWMCC_ATOM(type, cardinal), &data, &num)) {
58         g_warning("Failed to read NET_DESKTOP_GEOMETRY from 0x%lx", win);
59         *w = *h = 0;
60     } else if (num != 2) {
61         g_warning("Read invalid NET_DESKTOP_GEOMETRY from 0x%lx", win);
62         *w = *h = 0;
63     } else {
64         *w = data[0];
65         *h = data[1];
66     }
67     g_free(data);
68 }
69
70 void cwmcc_root_get_desktop_viewport(Window win, gulong *x, gulong *y)
71 {
72     gulong *data = NULL, num;
73
74     if (!prop_get_array32(win, CWMCC_ATOM(root, net_desktop_viewport),
75                     CWMCC_ATOM(type, cardinal), &data, &num)) {
76         g_warning("Failed to read NET_DESKTOP_VIEWPORT from 0x%lx", win);
77         *x = *y = 0;
78     } else if (num != 2) {
79         g_warning("Read invalid NET_DESKTOP_VIEWPORT from 0x%lx", win);
80         *x = *y = 0;
81     } else {
82         *x = data[0];
83         *y = data[1];
84     }
85     g_free(data);
86 }
87
88 void cwmcc_root_get_current_desktop(Window win, gulong *desktop)
89 {
90     if (!prop_get32(win, CWMCC_ATOM(root, net_current_desktop),
91                     CWMCC_ATOM(type, cardinal), desktop)) {
92         g_warning("Failed to read NET_CURRENT_DESKTOP from 0x%lx", win);
93         *desktop = 0;
94     }
95 }
96
97 void cwmcc_root_get_desktop_names(Window win, char ***names)
98 {
99     if (!prop_get_strings_utf8(win,
100                                CWMCC_ATOM(root, net_desktop_names), names)) {
101         g_warning("Failed to read NET_DESKTOP_NAMES from 0x%lx", win);
102         *names = NULL;
103     }
104 }
105
106 void cwmcc_root_get_active_window(Window win, Window *window)
107 {
108     if (!prop_get32(win, CWMCC_ATOM(root, net_active_window),
109                     CWMCC_ATOM(type, window), window)) {
110         g_warning("Failed to read NET_ACTIVE_WINDOW from 0x%lx", win);
111         *window = None;
112     }
113 }
114
115 /*void cwmcc_root_get_workarea(Window win, Rect a)
116 {
117 }*/
118
119 void cwmcc_root_get_supporting_wm_check(Window win, Window *window)
120 {
121     if (!prop_get32(win, CWMCC_ATOM(root, net_supporting_wm_check),
122                     CWMCC_ATOM(type, window), window)) {
123         g_warning("Failed to read NET_SUPPORTING_WM_CHECK from 0x%lx", win);
124         *window = None;
125     }
126 }
127
128 void cwmcc_root_get_desktop_layout(Window win,
129                                    struct Cwmcc_DesktopLayout *layout)
130 {
131     gulong *data = NULL, num;
132     gulong desks;
133
134     /* need the number of desktops */
135     cwmcc_root_get_number_of_desktops(win, &desks);
136
137     layout->orientation = Cwmcc_Orientation_Horz;
138     layout->start_corner = Cwmcc_Corner_TopLeft;
139     layout->rows = 1;
140     layout->columns = desks;
141
142     if (!prop_get_array32(win, CWMCC_ATOM(root, net_desktop_layout),
143                     CWMCC_ATOM(type, cardinal), &data, &num)) {
144         g_warning("Failed to read NET_DESKTOP_LAYOUT from 0x%lx", win);
145     } else if (num != 4) {
146         g_warning("Read invalid NET_DESKTOP_LAYOUT from 0x%lx", win);
147     } else {
148         if (data[0] == Cwmcc_Orientation_Horz ||
149             data[0] == Cwmcc_Orientation_Vert)
150             layout->orientation = data[0];
151         if (data[3] == Cwmcc_Corner_TopLeft ||
152             data[3] == Cwmcc_Corner_TopRight ||
153             data[3] == Cwmcc_Corner_BottomLeft ||
154             data[3] == Cwmcc_Corner_BottomRight)
155             layout->start_corner = data[3];
156         layout->rows = data[2];
157         layout->columns = data[1];
158
159         /* bounds checking */
160         if (layout->orientation == Cwmcc_Orientation_Horz) {
161             if (layout->rows > desks)
162                 layout->rows = desks;
163             if (layout->columns > ((desks + desks % layout->rows) /
164                                    layout->rows))
165                 layout->columns = ((desks + desks % layout->rows) /
166                                    layout->rows);
167         } else {
168             if (layout->columns > desks)
169                 layout->columns = desks;
170             if (layout->rows > ((desks + desks % layout->columns) /
171                                 layout->columns))
172                 layout->rows = ((desks + desks % layout->columns) /
173                                 layout->columns);
174         }
175     }
176     g_free(data);
177 }
178
179 void cwmcc_root_get_showing_desktop(Window win, gboolean *showing)
180 {
181     gulong a;
182
183     if (!prop_get32(win, CWMCC_ATOM(root, net_showing_desktop),
184                     CWMCC_ATOM(type, cardinal), &a)) {
185         g_warning("Failed to read NET_SHOWING_DESKTOP from 0x%lx", win);
186         a = FALSE;
187     }
188     *showing = !!a;
189 }
190
191 void cwmcc_root_get_openbox_pid(Window win, gulong *pid)
192 {
193     if (!prop_get32(win, CWMCC_ATOM(root, openbox_pid),
194                     CWMCC_ATOM(type, cardinal), pid)) {
195         g_warning("Failed to read OPENBOX_PID from 0x%lx", win);
196         *pid = 0;
197     }
198 }
199