]> Dogcows Code - chaz/openbox/blob - openbox/stacking.c
expose focus_cycle_client
[chaz/openbox] / openbox / stacking.c
1 #include "openbox.h"
2 #include "prop.h"
3 #include "screen.h"
4 #include "focus.h"
5 #include "client.h"
6 #include "group.h"
7 #include "frame.h"
8 #include "window.h"
9
10 GList *stacking_list = NULL;
11
12 void stacking_set_list()
13 {
14 Window *windows = NULL;
15 GList *it;
16 guint i = 0;
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() == OB_STATE_EXITING) return;
22
23 /* create an array of the window ids (from bottom to top,
24 reverse order!) */
25 if (stacking_list) {
26 windows = g_new(Window, g_list_length(stacking_list));
27 for (it = g_list_last(stacking_list); it; it = g_list_previous(it)) {
28 if (WINDOW_IS_CLIENT(it->data))
29 windows[i++] = WINDOW_AS_CLIENT(it->data)->window;
30 }
31 }
32
33 PROP_SETA32(RootWindow(ob_display, ob_screen),
34 net_client_list_stacking, window, (guint32*)windows, i);
35
36 g_free(windows);
37 }
38
39 static void do_restack(GList *wins, GList *before)
40 {
41 GList *it, *next;
42 Window *win;
43 int i;
44
45 #ifdef DEBUG
46 /* pls only restack stuff in the same layer at a time */
47 for (it = wins; it; it = next) {
48 next = g_list_next(it);
49 if (!next) break;
50 g_assert (window_layer(it->data) == window_layer(next->data));
51 }
52 if (before)
53 g_assert(window_layer(it->data) >= window_layer(before->data));
54 #endif
55
56 win = g_new(Window, g_list_length(wins) + 1);
57
58 if (before == stacking_list)
59 win[0] = screen_support_win;
60 else if (!before)
61 win[0] = window_top(g_list_last(stacking_list)->data);
62 else
63 win[0] = window_top(g_list_previous(before)->data);
64
65 for (i = 1, it = wins; it; ++i, it = g_list_next(it)) {
66 win[i] = window_top(it->data);
67 g_assert(win[i] != None); /* better not call stacking shit before
68 setting your top level window value */
69 stacking_list = g_list_insert_before(stacking_list, before, it->data);
70 }
71
72 #ifdef DEBUG
73 /* some debug checking of the stacking list's order */
74 for (it = stacking_list; ; it = next) {
75 next = g_list_next(it);
76 if (!next) break;
77 g_assert(window_layer(it->data) >= window_layer(next->data));
78 }
79 #endif
80
81 XRestackWindows(ob_display, win, i);
82 g_free(win);
83
84 stacking_set_list();
85 }
86
87 static void do_raise(GList *wins)
88 {
89 GList *it;
90 GList *layer[OB_NUM_STACKING_LAYERS] = {NULL};
91 int i;
92
93 for (it = wins; it; it = g_list_next(it)) {
94 ObStackingLayer l;
95
96 l = window_layer(it->data);
97 layer[l] = g_list_append(layer[l], it->data);
98 }
99
100 it = stacking_list;
101 for (i = OB_NUM_STACKING_LAYERS - 1; i >= 0; --i) {
102 if (layer[i]) {
103 for (; it; it = g_list_next(it)) {
104 /* look for the top of the layer */
105 if (window_layer(it->data) <= (ObStackingLayer) i)
106 break;
107 }
108 do_restack(layer[i], it);
109 g_list_free(layer[i]);
110 }
111 }
112 }
113
114 static void do_lower(GList *wins)
115 {
116 GList *it;
117 GList *layer[OB_NUM_STACKING_LAYERS] = {NULL};
118 int i;
119
120 for (it = wins; it; it = g_list_next(it)) {
121 ObStackingLayer l;
122
123 l = window_layer(it->data);
124 layer[l] = g_list_append(layer[l], it->data);
125 }
126
127 it = stacking_list;
128 for (i = OB_NUM_STACKING_LAYERS - 1; i >= 0; --i) {
129 if (layer[i]) {
130 for (; it; it = g_list_next(it)) {
131 /* look for the top of the next layer down */
132 if (window_layer(it->data) < (ObStackingLayer) i)
133 break;
134 }
135 do_restack(layer[i], it);
136 g_list_free(layer[i]);
137 }
138 }
139 }
140
141 static GList *pick_windows(ObClient *top, ObClient *selected, gboolean raise)
142 {
143 GList *ret = NULL;
144 GList *it, *next, *prev;
145 GSList *sit;
146 int i, n;
147 GList *modals = NULL;
148 GList *trans = NULL;
149 GList *modal_sel = NULL; /* the selected guys if modal */
150 GList *trans_sel = NULL; /* the selected guys if not */
151
152 /* remove first so we can't run into ourself */
153 if ((it = g_list_find(stacking_list, top)))
154 stacking_list = g_list_delete_link(stacking_list, it);
155 else
156 return NULL;
157
158 i = 0;
159 n = g_slist_length(top->transients);
160 for (it = stacking_list; i < n && it; it = next) {
161 prev = g_list_previous(it);
162 next = g_list_next(it);
163
164 if ((sit = g_slist_find(top->transients, it->data))) {
165 ObClient *c = sit->data;
166 gboolean sel_child;
167
168 ++i;
169
170 if (c == selected)
171 sel_child = TRUE;
172 else
173 sel_child = client_search_transient(c, selected) != NULL;
174
175 if (!c->modal) {
176 if (!sel_child) {
177 trans = g_list_concat(trans,
178 pick_windows(c, selected, raise));
179 } else {
180 trans_sel = g_list_concat(trans_sel,
181 pick_windows(c, selected,
182 raise));
183 }
184 } else {
185 if (!sel_child) {
186 modals = g_list_concat(modals,
187 pick_windows(c, selected, raise));
188 } else {
189 modal_sel = g_list_concat(modal_sel,
190 pick_windows(c, selected,
191 raise));
192 }
193 }
194 /* if we dont have a prev then start back at the beginning,
195 otherwise skip back to the prev's next */
196 next = prev ? g_list_next(prev) : stacking_list;
197 }
198 }
199
200 ret = g_list_concat((raise ? modal_sel : modals),
201 (raise ? modals : modal_sel));
202
203 ret = g_list_concat(ret, (raise ? trans_sel : trans));
204 ret = g_list_concat(ret, (raise ? trans : trans_sel));
205
206
207 /* add itself */
208 ret = g_list_append(ret, top);
209
210 return ret;
211 }
212
213 #if 0
214 static GList *pick_group_windows(ObClient *top, ObClient *selected,
215 gboolean raise)
216 {
217 GList *ret = NULL;
218 GList *it, *next, *prev;
219 GSList *sit;
220 int i, n;
221
222 /* add group members in their stacking order */
223 if (top->group) {
224 i = 0;
225 n = g_slist_length(top->group->members) - 1;
226 for (it = stacking_list; i < n && it; it = next) {
227 prev = g_list_previous(it);
228 next = g_list_next(it);
229
230 if ((sit = g_slist_find(top->group->members, it->data))) {
231 ++i;
232 ret = g_list_concat(ret,
233 pick_windows(sit->data, selected, raise));
234 /* if we dont have a prev then start back at the beginning,
235 otherwise skip back to the prev's next */
236 next = prev ? g_list_next(prev) : stacking_list;
237 }
238 }
239 }
240 return ret;
241 }
242 #endif
243
244 void stacking_raise(ObWindow *window)
245 {
246 GList *wins;
247
248 if (WINDOW_IS_CLIENT(window)) {
249 ObClient *c;
250 ObClient *selected;
251 selected = WINDOW_AS_CLIENT(window);
252 c = client_search_top_transient(selected);
253 wins = pick_windows(c, selected, TRUE);
254 /*wins = g_list_concat(wins, pick_group_windows(c, selected, TRUE));*/
255 } else {
256 wins = g_list_append(NULL, window);
257 stacking_list = g_list_remove(stacking_list, window);
258 }
259 do_raise(wins);
260 g_list_free(wins);
261 }
262
263 void stacking_lower(ObWindow *window)
264 {
265 GList *wins;
266
267 if (WINDOW_IS_CLIENT(window)) {
268 ObClient *c;
269 ObClient *selected;
270 selected = WINDOW_AS_CLIENT(window);
271 c = client_search_top_transient(selected);
272 wins = pick_windows(c, selected, FALSE);
273 /*wins = g_list_concat(pick_group_windows(c, selected, FALSE), wins);*/
274 } else {
275 wins = g_list_append(NULL, window);
276 stacking_list = g_list_remove(stacking_list, window);
277 }
278 do_lower(wins);
279 g_list_free(wins);
280 }
281
282 void stacking_below(ObWindow *window, ObWindow *below)
283 {
284 GList *wins, *before;
285
286 if (window_layer(window) != window_layer(below))
287 return;
288
289 wins = g_list_append(NULL, window);
290 stacking_list = g_list_remove(stacking_list, window);
291 before = g_list_next(g_list_find(stacking_list, below));
292 do_restack(wins, before);
293 g_list_free(wins);
294 }
295
296 void stacking_add(ObWindow *win)
297 {
298 ObStackingLayer l;
299 GList *wins;
300
301 g_assert(screen_support_win != None); /* make sure I dont break this in the
302 future */
303
304 l = window_layer(win);
305 wins = g_list_append(NULL, win); /* list of 1 element */
306
307 stacking_list = g_list_append(stacking_list, win);
308 stacking_raise(win);
309 }
310
311 void stacking_add_nonintrusive(ObWindow *win)
312 {
313 ObClient *client;
314 ObClient *parent = NULL;
315 GList *it_before = NULL;
316
317 if (!WINDOW_IS_CLIENT(win)) {
318 stacking_add(win); /* no special rules for others */
319 return;
320 }
321
322 client = WINDOW_AS_CLIENT(win);
323
324 /* insert above its highest parent */
325 if (client->transient_for) {
326 if (client->transient_for != OB_TRAN_GROUP) {
327 parent = client->transient_for;
328 } else {
329 GSList *sit;
330 GList *it;
331
332 if (client->group)
333 for (it = stacking_list; !parent && it; it = it->next) {
334 if ((sit = g_slist_find(client->group->members, it->data)))
335 for (sit = client->group->members; !parent && sit;
336 sit = sit->next) {
337 ObClient *c = sit->data;
338 /* checking transient_for prevents infinate loops! */
339 if (sit->data == it->data && !c->transient_for)
340 parent = it->data;
341 }
342 }
343 }
344 }
345
346 if (!(it_before = g_list_find(stacking_list, parent))) {
347 /* no parent to put above, try find the focused client to go
348 under */
349 if (focus_client && focus_client->layer == client->layer) {
350 if ((it_before = g_list_find(stacking_list, focus_client)))
351 it_before = it_before->next;
352 }
353 }
354 if (!it_before) {
355 /* out of ideas, just add it normally... */
356 stacking_add(win);
357 } else {
358 GList *wins = g_list_append(NULL, win);
359 do_restack(wins, it_before);
360 g_list_free(wins);
361 }
362 }
This page took 0.048795 seconds and 4 git commands to generate.