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