10 GList *stacking_list = NULL;
12 void stacking_set_list()
14 Window *windows = NULL;
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
21 if (ob_state() == OB_STATE_EXITING) return;
23 /* create an array of the window ids (from bottom to top,
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;
33 PROP_SETA32(RootWindow(ob_display, ob_screen),
34 net_client_list_stacking, window, (guint32*)windows, i);
39 static void do_restack(GList *wins, GList *before)
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);
50 g_assert (window_layer(it->data) == window_layer(next->data));
53 g_assert(window_layer(it->data) >= window_layer(before->data));
56 win = g_new(Window, g_list_length(wins) + 1);
58 if (before == stacking_list)
59 win[0] = screen_support_win;
61 win[0] = window_top(g_list_last(stacking_list)->data);
63 win[0] = window_top(g_list_previous(before)->data);
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);
73 /* some debug checking of the stacking list's order */
74 for (it = stacking_list; ; it = next) {
75 next = g_list_next(it);
77 g_assert(window_layer(it->data) >= window_layer(next->data));
81 XRestackWindows(ob_display, win, i);
87 static void do_raise(GList *wins)
90 GList *layer[OB_NUM_STACKING_LAYERS] = {NULL};
93 for (it = wins; it; it = g_list_next(it)) {
96 l = window_layer(it->data);
97 layer[l] = g_list_append(layer[l], it->data);
101 for (i = OB_NUM_STACKING_LAYERS - 1; i >= 0; --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)
108 do_restack(layer[i], it);
109 g_list_free(layer[i]);
114 static void do_lower(GList *wins)
117 GList *layer[OB_NUM_STACKING_LAYERS] = {NULL};
120 for (it = wins; it; it = g_list_next(it)) {
123 l = window_layer(it->data);
124 layer[l] = g_list_append(layer[l], it->data);
128 for (i = OB_NUM_STACKING_LAYERS - 1; i >= 0; --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)
135 do_restack(layer[i], it);
136 g_list_free(layer[i]);
141 static GList *pick_windows(ObClient *top, ObClient *selected, gboolean raise)
144 GList *it, *next, *prev;
147 GList *modals = NULL;
149 GList *modal_sel = NULL; /* the selected guys if modal */
150 GList *trans_sel = NULL; /* the selected guys if not */
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);
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);
164 if ((sit = g_slist_find(top->transients, it->data))) {
165 ObClient *c = sit->data;
173 sel_child = client_search_transient(c, selected) != NULL;
177 trans = g_list_concat(trans,
178 pick_windows(c, selected, raise));
180 trans_sel = g_list_concat(trans_sel,
181 pick_windows(c, selected,
186 modals = g_list_concat(modals,
187 pick_windows(c, selected, raise));
189 modal_sel = g_list_concat(modal_sel,
190 pick_windows(c, selected,
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;
200 ret = g_list_concat((raise ? modal_sel : modals),
201 (raise ? modals : modal_sel));
203 ret = g_list_concat(ret, (raise ? trans_sel : trans));
204 ret = g_list_concat(ret, (raise ? trans : trans_sel));
208 ret = g_list_append(ret, top);
214 static GList *pick_group_windows(ObClient *top, ObClient *selected,
218 GList *it, *next, *prev;
222 /* add group members in their stacking order */
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);
230 if ((sit = g_slist_find(top->group->members, it->data))) {
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;
244 void stacking_raise(ObWindow *window)
248 if (WINDOW_IS_CLIENT(window)) {
251 selected = WINDOW_AS_CLIENT(window);
252 g_message("raising 0x%x", selected->window);
253 /*c = client_search_top_transient(selected);*/ c = selected;
254 wins = pick_windows(c, selected, TRUE);
255 /*wins = g_list_concat(wins, pick_group_windows(c, selected, TRUE));*/
257 wins = g_list_append(NULL, window);
258 stacking_list = g_list_remove(stacking_list, window);
264 void stacking_lower(ObWindow *window)
268 if (WINDOW_IS_CLIENT(window)) {
271 selected = WINDOW_AS_CLIENT(window);
272 c = client_search_top_transient(selected);
273 wins = pick_windows(c, selected, FALSE);
274 /*wins = g_list_concat(pick_group_windows(c, selected, FALSE), wins);*/
276 wins = g_list_append(NULL, window);
277 stacking_list = g_list_remove(stacking_list, window);
283 void stacking_below(ObWindow *window, ObWindow *below)
285 GList *wins, *before;
287 if (window_layer(window) != window_layer(below))
290 wins = g_list_append(NULL, window);
291 stacking_list = g_list_remove(stacking_list, window);
292 before = g_list_next(g_list_find(stacking_list, below));
293 do_restack(wins, before);
297 void stacking_add(ObWindow *win)
302 g_assert(screen_support_win != None); /* make sure I dont break this in the
305 l = window_layer(win);
306 wins = g_list_append(NULL, win); /* list of 1 element */
308 stacking_list = g_list_append(stacking_list, win);
312 void stacking_add_nonintrusive(ObWindow *win)
315 ObClient *parent = NULL;
316 GList *it_before = NULL;
318 if (!WINDOW_IS_CLIENT(win)) {
319 stacking_add(win); /* no special rules for others */
323 client = WINDOW_AS_CLIENT(win);
325 /* insert above its highest parent */
326 if (client->transient_for) {
327 if (client->transient_for != OB_TRAN_GROUP) {
328 parent = client->transient_for;
334 for (it = stacking_list; !parent && it; it = it->next) {
335 if ((sit = g_slist_find(client->group->members, it->data)))
336 for (sit = client->group->members; !parent && sit;
338 ObClient *c = sit->data;
339 /* checking transient_for prevents infinate loops! */
340 if (sit->data == it->data && !c->transient_for)
347 if (!(it_before = g_list_find(stacking_list, parent))) {
348 /* no parent to put above, try find the focused client to go
350 if (focus_client && focus_client->layer == client->layer) {
351 if ((it_before = g_list_find(stacking_list, focus_client)))
352 it_before = it_before->next;
356 /* out of ideas, just add it normally... */
359 GList *wins = g_list_append(NULL, win);
360 do_restack(wins, it_before);