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)
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] = screen_support_win;
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[OB_NUM_STACKING_LAYERS] = {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 = OB_NUM_STACKING_LAYERS - 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) <= (ObStackingLayer) i)
103 do_restack(layer[i], it);
104 g_list_free(layer[i]);
109 static void do_lower(GList *wins)
112 GList *layer[OB_NUM_STACKING_LAYERS] = {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 = OB_NUM_STACKING_LAYERS - 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) < (ObStackingLayer) i)
130 do_restack(layer[i], it);
131 g_list_free(layer[i]);
136 static GList *pick_windows(ObClient *top, ObClient *selected, gboolean raise)
139 GList *it, *next, *prev;
142 GList *modals = NULL;
144 GList *modal_sel = NULL; /* the selected guys if modal */
145 GList *trans_sel = NULL; /* the selected guys if not */
147 /* remove first so we can't run into ourself */
148 if ((it = g_list_find(stacking_list, top)))
149 stacking_list = g_list_delete_link(stacking_list, it);
154 n = g_slist_length(top->transients);
155 for (it = stacking_list; i < n && it; it = next) {
156 prev = g_list_previous(it);
157 next = g_list_next(it);
159 if ((sit = g_slist_find(top->transients, it->data))) {
160 ObClient *c = sit->data;
168 sel_child = client_search_transient(c, selected) != NULL;
172 trans = g_list_concat(trans,
173 pick_windows(c, selected, raise));
175 trans_sel = g_list_concat(trans_sel,
176 pick_windows(c, selected,
181 modals = g_list_concat(modals,
182 pick_windows(c, selected, raise));
184 modal_sel = g_list_concat(modal_sel,
185 pick_windows(c, selected,
189 /* if we dont have a prev then start back at the beginning,
190 otherwise skip back to the prev's next */
191 next = prev ? g_list_next(prev) : stacking_list;
195 ret = g_list_concat((raise ? modal_sel : modals),
196 (raise ? modals : modal_sel));
198 ret = g_list_concat(ret, (raise ? trans_sel : trans));
199 ret = g_list_concat(ret, (raise ? trans : trans_sel));
203 ret = g_list_append(ret, top);
208 static GList *pick_group_windows(ObClient *top, ObClient *selected,
212 GList *it, *next, *prev;
216 /* add group members in their stacking order */
219 n = g_slist_length(top->group->members) - 1;
220 for (it = stacking_list; i < n && it; it = next) {
221 prev = g_list_previous(it);
222 next = g_list_next(it);
224 if ((sit = g_slist_find(top->group->members, it->data))) {
226 ret = g_list_concat(ret,
227 pick_windows(sit->data, selected, raise));
228 /* if we dont have a prev then start back at the beginning,
229 otherwise skip back to the prev's next */
230 next = prev ? g_list_next(prev) : stacking_list;
237 void stacking_raise(ObWindow *window)
241 if (WINDOW_IS_CLIENT(window)) {
244 selected = WINDOW_AS_CLIENT(window);
245 c = client_search_top_transient(selected);
246 wins = pick_windows(c, selected, TRUE);
247 /*wins = g_list_concat(wins, pick_group_windows(c, selected, TRUE));*/
249 wins = g_list_append(NULL, window);
250 stacking_list = g_list_remove(stacking_list, window);
256 void stacking_lower(ObWindow *window)
260 if (WINDOW_IS_CLIENT(window)) {
263 selected = WINDOW_AS_CLIENT(window);
264 c = client_search_top_transient(selected);
265 wins = pick_windows(c, selected, FALSE);
266 /*wins = g_list_concat(pick_group_windows(c, selected, FALSE), wins);*/
268 wins = g_list_append(NULL, window);
269 stacking_list = g_list_remove(stacking_list, window);
275 void stacking_add(ObWindow *win)
280 g_assert(screen_support_win != None); /* make sure I dont break this in the
283 l = window_layer(win);
284 wins = g_list_append(NULL, win); /* list of 1 element */
286 stacking_list = g_list_append(stacking_list, win);
290 void stacking_add_nonintrusive(ObWindow *win)
293 ObClient *parent = NULL;
294 GList *it_before = NULL;
296 if (!WINDOW_IS_CLIENT(win)) {
297 stacking_add(win); /* no special rules for others */
301 client = WINDOW_AS_CLIENT(win);
303 /* insert above its highest parent */
304 if (client->transient_for) {
305 if (client->transient_for != OB_TRAN_GROUP) {
306 parent = client->transient_for;
312 for (it = stacking_list; !parent && it; it = it->next) {
313 if ((sit = g_slist_find(client->group->members, it->data)))
314 for (sit = client->group->members; !parent && sit;
316 ObClient *c = sit->data;
317 /* checking transient_for prevents infinate loops! */
318 if (sit->data == it->data && !c->transient_for)
325 if (!(it_before = g_list_find(stacking_list, parent))) {
326 /* no parent to put above, try find the focused client to go
328 if (focus_client && focus_client->layer == client->layer) {
329 if ((it_before = g_list_find(stacking_list, focus_client)))
330 it_before = it_before->next;
334 /* out of ideas, just add it normally... */
337 GList *wins = g_list_append(NULL, win);
338 do_restack(wins, it_before);