]> Dogcows Code - chaz/openbox/blob - openbox/stacking.c
hardcode the button names for themes
[chaz/openbox] / openbox / stacking.c
1 #include "openbox.h"
2 #include "prop.h"
3 #include "focus.h"
4 #include "client.h"
5 #include "group.h"
6 #include "frame.h"
7 #include "window.h"
8 #include <glib.h>
9
10 GList *stacking_list = NULL;
11
12 void stacking_set_list()
13 {
14 Window *windows, *win_it;
15 GList *it;
16 guint size = g_list_length(stacking_list);
17
18 /* on shutdown, don't update the properties, so that we can read it back
19 in on startup and re-stack the windows as they were before we shut down
20 */
21 if (ob_state == State_Exiting) return;
22
23 /* create an array of the window ids (from bottom to top,
24 reverse order!) */
25 if (size > 0) {
26 windows = g_new(Window, size);
27 win_it = windows;
28 for (it = g_list_last(stacking_list); it != NULL;
29 it = it->prev)
30 if (WINDOW_IS_CLIENT(it->data)) {
31 *win_it = WINDOW_AS_CLIENT(it->data)->window;
32 ++win_it;
33 }
34 } else
35 windows = win_it = NULL;
36
37 PROP_SETA32(ob_root, net_client_list_stacking, window,
38 (guint32*)windows, win_it - windows);
39
40 if (windows)
41 g_free(windows);
42 }
43
44 static void do_restack(GList *wins, GList *before)
45 {
46 GList *it, *next;
47 Window *win;
48 int i;
49
50 /* pls only restack stuff in the same layer at a time */
51 for (it = wins; it; it = next) {
52 next = g_list_next(it);
53 if (!next) break;
54 g_assert (window_layer(it->data) == window_layer(next->data));
55 }
56
57
58 win = g_new(Window, g_list_length(wins) + 1);
59
60 if (before == stacking_list)
61 win[0] = focus_backup;
62 else if (!before)
63 win[0] = window_top(g_list_last(stacking_list)->data);
64 else
65 win[0] = window_top(g_list_previous(before)->data);
66
67 for (i = 1, it = wins; it; ++i, it = g_list_next(it)) {
68 win[i] = window_top(it->data);
69 stacking_list = g_list_insert_before(stacking_list, before, it->data);
70 }
71
72 /* XXX some debug checking of the stacking list's order */
73 for (it = stacking_list; ; it = next) {
74 next = g_list_next(it);
75 if (!next) break;
76 g_assert(window_layer(it->data) >= window_layer(next->data));
77 }
78
79 XRestackWindows(ob_display, win, i);
80 g_free(win);
81 }
82
83 static void raise(GList *wins)
84 {
85 GList *it;
86 GList *layer[NUM_STACKLAYER] = {NULL};
87 int i;
88
89 for (it = wins; it; it = g_list_next(it)) {
90 StackLayer l;
91
92 l = window_layer(it->data);
93 layer[l] = g_list_append(layer[l], it->data);
94 }
95
96 it = stacking_list;
97 for (i = NUM_STACKLAYER - 1; i >= 0; --i) {
98 if (layer[i]) {
99 for (; it; it = g_list_next(it)) {
100 /* look for the top of the layer */
101 if (window_layer(it->data) <= (StackLayer) i)
102 break;
103 }
104 do_restack(layer[i], it);
105 g_list_free(layer[i]);
106 }
107 }
108 }
109
110 static void lower(GList *wins)
111 {
112 GList *it;
113 GList *layer[NUM_STACKLAYER] = {NULL};
114 int i;
115
116 for (it = wins; it; it = g_list_next(it)) {
117 StackLayer l;
118
119 l = window_layer(it->data);
120 layer[l] = g_list_append(layer[l], it->data);
121 }
122
123 it = stacking_list;
124 for (i = NUM_STACKLAYER - 1; i >= 0; --i) {
125 if (layer[i]) {
126 for (; it; it = g_list_next(it)) {
127 /* look for the top of the next layer down */
128 if (window_layer(it->data) < (StackLayer) i)
129 break;
130 }
131 do_restack(layer[i], it);
132 g_list_free(layer[i]);
133 }
134 }
135 }
136
137 static GList *pick_windows(ObWindow *win)
138 {
139 GList *ret = NULL;
140 GList *it, *next;
141 GSList *sit;
142 Client *c;
143 int i, n;
144
145 if (!WINDOW_IS_CLIENT(win)) {
146 ret = g_list_append(ret, win);
147 stacking_list = g_list_remove(stacking_list, win);
148 return ret;
149 }
150
151 c = WINDOW_AS_CLIENT(win);
152
153 /* remove first so we can't run into ourself */
154 stacking_list = g_list_remove(stacking_list, win);
155
156 /* add transient children in their stacking order */
157 i = 0;
158 n = g_slist_length(c->transients);
159 for (it = stacking_list; i < n && it; it = next) {
160 next = g_list_next(it);
161 if ((sit = g_slist_find(c->transients, it->data))) {
162 ++i;
163 ret = g_list_concat(ret, pick_windows(sit->data));
164 it = stacking_list;
165 }
166 }
167
168 /* add itself */
169 ret = g_list_append(ret, win);
170
171 return ret;
172 }
173
174 static GList *pick_group_windows(ObWindow *win)
175 {
176 GList *ret = NULL;
177 GList *it, *next;
178 GSList *sit;
179 Client *c;
180 int i, n;
181
182 if (!WINDOW_IS_CLIENT(win))
183 return NULL;
184
185 c = WINDOW_AS_CLIENT(win);
186
187 /* add group members in their stacking order */
188 if (c->group) {
189 i = 0;
190 n = g_slist_length(c->group->members) - 1;
191 for (it = stacking_list; i < n && it; it = next) {
192 next = g_list_next(it);
193 if ((sit = g_slist_find(c->group->members, it->data))) {
194 ++i;
195 ret = g_list_concat(ret, pick_windows(sit->data));
196 it = stacking_list;
197 }
198 }
199 }
200 return ret;
201 }
202
203 static ObWindow *top_transient(ObWindow *window)
204 {
205 Client *client;
206
207 if (!WINDOW_IS_CLIENT(window))
208 return window;
209
210 client = WINDOW_AS_CLIENT(window);
211
212 /* move up the transient chain as far as possible */
213 if (client->transient_for) {
214 if (client->transient_for != TRAN_GROUP) {
215 return top_transient(CLIENT_AS_WINDOW(client->transient_for));
216 } else {
217 GSList *it;
218
219 for (it = client->group->members; it; it = it->next) {
220 Client *c = it->data;
221
222 /* checking transient_for prevents infinate loops! */
223 if (c != client && !c->transient_for)
224 break;
225 }
226 if (it)
227 return it->data;
228 }
229 }
230
231 return window;
232 }
233
234 void stacking_raise(ObWindow *window)
235 {
236 GList *wins;
237
238 window = top_transient(window);
239 wins = pick_windows(window);
240 wins = g_list_concat(wins, pick_group_windows(window));
241 raise(wins);
242 g_list_free(wins);
243 }
244
245 void stacking_lower(ObWindow *window)
246 {
247 GList *wins;
248
249 window = top_transient(window);
250 wins = pick_windows(window);
251 wins = g_list_concat(wins, pick_group_windows(window));
252 lower(wins);
253 g_list_free(wins);
254 }
255
256 void stacking_add(ObWindow *win)
257 {
258 StackLayer l;
259 GList *wins, *it;
260
261 l = window_layer(win);
262 wins = g_list_append(NULL, win); /* list of 1 element */
263
264 for (it = stacking_list; it; it = g_list_next(it))
265 if (window_layer(it->data) <= l)
266 break;
267 do_restack(wins, it);
268 g_list_free(wins);
269
270 stacking_raise(win);
271 }
272
273 void stacking_add_nonintrusive(ObWindow *win)
274 {
275 Client *client;
276 Client *parent = NULL;
277 GList *it_before = NULL;
278
279 if (!WINDOW_IS_CLIENT(win)) {
280 stacking_add(win); /* no special rules for others */
281 return;
282 }
283
284 client = WINDOW_AS_CLIENT(win);
285
286 /* insert above its highest parent */
287 if (client->transient_for) {
288 if (client->transient_for != TRAN_GROUP) {
289 parent = client->transient_for;
290 } else {
291 GSList *sit;
292 GList *it;
293
294 if (client->group)
295 for (it = stacking_list; !parent && it; it = it->next) {
296 if ((sit = g_slist_find(client->group->members, it->data)))
297 for (sit = client->group->members; !parent && sit;
298 sit = sit->next) {
299 Client *c = sit->data;
300 /* checking transient_for prevents infinate loops! */
301 if (sit->data == it->data && !c->transient_for)
302 parent = it->data;
303 }
304 }
305 }
306 }
307
308 if (!(it_before = g_list_find(stacking_list, parent))) {
309 /* no parent to put above, try find the focused client to go
310 under */
311 if (focus_client && focus_client->layer == client->layer) {
312 if ((it_before = g_list_find(stacking_list, focus_client)))
313 it_before = it_before->next;
314 }
315 }
316 if (!it_before) {
317 /* out of ideas, just add it normally... */
318 stacking_add(win);
319 } else {
320 GList *wins = g_list_append(NULL, win);
321 do_restack(wins, it_before);
322 g_list_free(wins);
323 }
324 }
This page took 0.056892 seconds and 4 git commands to generate.