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 == 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(ob_root, net_client_list_stacking, window,
34 (guint32*)windows, i);
39 static void do_restack(GList *wins, GList *before)
45 /* pls only restack stuff in the same layer at a time */
46 for (it = wins; it; it = next) {
47 next = g_list_next(it);
49 g_assert (window_layer(it->data) == window_layer(next->data));
53 win = g_new(Window, g_list_length(wins) + 1);
55 if (before == stacking_list)
56 win[0] = focus_backup;
58 win[0] = window_top(g_list_last(stacking_list)->data);
60 win[0] = window_top(g_list_previous(before)->data);
62 for (i = 1, it = wins; it; ++i, it = g_list_next(it)) {
63 win[i] = window_top(it->data);
64 g_assert(win[i] != None); /* better not call stacking shit before
65 setting your top level window value */
66 stacking_list = g_list_insert_before(stacking_list, before, it->data);
69 /* XXX some debug checking of the stacking list's order */
70 for (it = stacking_list; ; it = next) {
71 next = g_list_next(it);
73 g_assert(window_layer(it->data) >= window_layer(next->data));
76 XRestackWindows(ob_display, win, i);
82 static void do_raise(GList *wins)
85 GList *layer[NUM_STACKLAYER] = {NULL};
88 for (it = wins; it; it = g_list_next(it)) {
91 l = window_layer(it->data);
92 layer[l] = g_list_append(layer[l], it->data);
96 for (i = NUM_STACKLAYER - 1; i >= 0; --i) {
98 for (; it; it = g_list_next(it)) {
99 /* look for the top of the layer */
100 if (window_layer(it->data) <= (StackLayer) i)
103 do_restack(layer[i], it);
104 g_list_free(layer[i]);
109 static void do_lower(GList *wins)
112 GList *layer[NUM_STACKLAYER] = {NULL};
115 for (it = wins; it; it = g_list_next(it)) {
118 l = window_layer(it->data);
119 layer[l] = g_list_append(layer[l], it->data);
123 for (i = NUM_STACKLAYER - 1; i >= 0; --i) {
125 for (; it; it = g_list_next(it)) {
126 /* look for the top of the next layer down */
127 if (window_layer(it->data) < (StackLayer) i)
130 do_restack(layer[i], it);
131 g_list_free(layer[i]);
136 static GList *pick_windows(Client *top, Client *selected, gboolean raise)
139 GList *it, *next, *prev;
142 GList *modals = NULL;
144 GList *modal_sel_it = NULL; /* the selected guy if modal */
145 GList *trans_sel_it = NULL; /* the selected guy if not */
147 /* remove first so we can't run into ourself */
148 stacking_list = g_list_remove(stacking_list, top);
151 n = g_slist_length(top->transients);
152 for (it = stacking_list; i < n && it; it = next) {
153 prev = g_list_previous(it);
154 next = g_list_next(it);
156 if ((sit = g_slist_find(top->transients, it->data))) {
157 Client *c = sit->data;
163 trans = g_list_concat(trans,
164 pick_windows(c, selected, raise));
166 g_assert(modal_sel_it == NULL);
167 g_assert(trans_sel_it == NULL);
168 trans_sel_it = pick_windows(c, selected, raise);
172 modals = g_list_concat(modals,
173 pick_windows(c, selected, raise));
175 g_assert(modal_sel_it == NULL);
176 g_assert(trans_sel_it == NULL);
177 modal_sel_it = pick_windows(c, selected, raise);
180 /* if we dont have a prev then start back at the beginning,
181 otherwise skip back to the prev's next */
182 next = prev ? g_list_next(prev) : stacking_list;
186 ret = g_list_concat((raise ? modal_sel_it : modals),
187 (raise ? modals : modal_sel_it));
189 ret = g_list_concat(ret, (raise ? trans_sel_it : trans));
190 ret = g_list_concat(ret, (raise ? trans : trans_sel_it));
194 ret = g_list_append(ret, top);
199 static GList *pick_group_windows(Client *top, Client *selected, gboolean raise)
206 /* add group members in their stacking order */
209 n = g_slist_length(top->group->members) - 1;
210 for (it = stacking_list; i < n && it; it = next) {
211 next = g_list_next(it);
212 if ((sit = g_slist_find(top->group->members, it->data))) {
214 ret = g_list_concat(ret, pick_windows(sit->data,
223 void stacking_raise(ObWindow *window)
227 if (WINDOW_IS_CLIENT(window)) {
230 selected = WINDOW_AS_CLIENT(window);
231 c = client_search_top_transient(selected);
232 wins = pick_windows(c, selected, TRUE);
233 wins = g_list_concat(wins, pick_group_windows(c, selected, TRUE));
235 wins = g_list_append(NULL, window);
236 stacking_list = g_list_remove(stacking_list, window);
242 void stacking_lower(ObWindow *window)
246 if (WINDOW_IS_CLIENT(window)) {
249 selected = WINDOW_AS_CLIENT(window);
250 c = client_search_top_transient(selected);
251 wins = pick_windows(c, selected, FALSE);
252 wins = g_list_concat(pick_group_windows(c, selected, FALSE), wins);
254 wins = g_list_append(NULL, window);
255 stacking_list = g_list_remove(stacking_list, window);
261 void stacking_add(ObWindow *win)
266 g_assert(focus_backup != None); /* make sure I dont break this in the
269 l = window_layer(win);
270 wins = g_list_append(NULL, win); /* list of 1 element */
272 stacking_list = g_list_append(stacking_list, win);
276 void stacking_add_nonintrusive(ObWindow *win)
279 Client *parent = NULL;
280 GList *it_before = NULL;
282 if (!WINDOW_IS_CLIENT(win)) {
283 stacking_add(win); /* no special rules for others */
287 client = WINDOW_AS_CLIENT(win);
289 /* insert above its highest parent */
290 if (client->transient_for) {
291 if (client->transient_for != TRAN_GROUP) {
292 parent = client->transient_for;
298 for (it = stacking_list; !parent && it; it = it->next) {
299 if ((sit = g_slist_find(client->group->members, it->data)))
300 for (sit = client->group->members; !parent && sit;
302 Client *c = sit->data;
303 /* checking transient_for prevents infinate loops! */
304 if (sit->data == it->data && !c->transient_for)
311 if (!(it_before = g_list_find(stacking_list, parent))) {
312 /* no parent to put above, try find the focused client to go
314 if (focus_client && focus_client->layer == client->layer) {
315 if ((it_before = g_list_find(stacking_list, focus_client)))
316 it_before = it_before->next;
320 /* out of ideas, just add it normally... */
323 GList *wins = g_list_append(NULL, win);
324 do_restack(wins, it_before);