10 GList *stacking_list = NULL;
12 void stacking_set_list()
14 Window *windows, *win_it;
16 guint size = g_list_length(stacking_list);
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, size);
28 for (it = g_list_last(stacking_list); it != NULL;
30 if (WINDOW_IS_CLIENT(it->data)) {
31 *win_it = WINDOW_AS_CLIENT(it->data)->window;
35 windows = win_it = NULL;
37 PROP_SETA32(ob_root, net_client_list_stacking, window,
38 (guint32*)windows, win_it - windows);
44 static void do_restack(GList *wins, GList *before)
50 /* pls only restack stuff in the same layer at a time */
51 for (it = wins; it; it = next) {
52 next = g_list_next(it);
54 g_assert (window_layer(it->data) == window_layer(next->data));
58 win = g_new(Window, g_list_length(wins) + 1);
60 if (before == stacking_list)
61 win[0] = focus_backup;
63 win[0] = window_top(g_list_last(stacking_list)->data);
65 win[0] = window_top(g_list_previous(before)->data);
67 for (i = 1, it = wins; it; ++i, it = g_list_next(it)) {
68 win[i] = window_top(it->data);
69 stacking_list = g_list_insert_before(stacking_list, before, it->data);
72 /* XXX some debug checking of the stacking list's order */
73 for (it = stacking_list; ; it = next) {
74 next = g_list_next(it);
76 g_assert(window_layer(it->data) >= window_layer(next->data));
79 XRestackWindows(ob_display, win, i);
83 static void raise(GList *wins)
86 GList *layer[NUM_STACKLAYER] = {NULL};
89 for (it = wins; it; it = g_list_next(it)) {
92 l = window_layer(it->data);
93 layer[l] = g_list_append(layer[l], it->data);
97 for (i = NUM_STACKLAYER - 1; i >= 0; --i) {
99 for (; it; it = g_list_next(it)) {
100 /* look for the top of the layer */
101 if (window_layer(it->data) <= (StackLayer) i)
104 do_restack(layer[i], it);
105 g_list_free(layer[i]);
110 static void lower(GList *wins)
113 GList *layer[NUM_STACKLAYER] = {NULL};
116 for (it = wins; it; it = g_list_next(it)) {
119 l = window_layer(it->data);
120 layer[l] = g_list_append(layer[l], it->data);
124 for (i = NUM_STACKLAYER - 1; i >= 0; --i) {
126 for (; it; it = g_list_next(it)) {
127 /* look for the top of the next layer down */
128 if (window_layer(it->data) < (StackLayer) i)
131 do_restack(layer[i], it);
132 g_list_free(layer[i]);
137 static GList *pick_windows(ObWindow *win)
145 if (!WINDOW_IS_CLIENT(win)) {
146 ret = g_list_append(ret, win);
147 stacking_list = g_list_remove(stacking_list, win);
151 c = WINDOW_AS_CLIENT(win);
153 /* remove first so we can't run into ourself */
154 stacking_list = g_list_remove(stacking_list, win);
156 /* add transient children in their stacking order */
158 n = g_slist_length(c->transients);
159 for (it = stacking_list; i < n && it; it = next) {
160 next = g_list_next(it);
161 if ((sit = g_slist_find(c->transients, it->data))) {
163 ret = g_list_concat(ret, pick_windows(sit->data));
169 ret = g_list_append(ret, win);
174 static GList *pick_group_windows(ObWindow *win)
182 if (!WINDOW_IS_CLIENT(win))
185 c = WINDOW_AS_CLIENT(win);
187 /* add group members in their stacking order */
190 n = g_slist_length(c->group->members) - 1;
191 for (it = stacking_list; i < n && it; it = next) {
192 next = g_list_next(it);
193 if ((sit = g_slist_find(c->group->members, it->data))) {
195 ret = g_list_concat(ret, pick_windows(sit->data));
203 static ObWindow *top_transient(ObWindow *window)
207 if (!WINDOW_IS_CLIENT(window))
210 client = WINDOW_AS_CLIENT(window);
212 /* move up the transient chain as far as possible */
213 if (client->transient_for) {
214 if (client->transient_for != TRAN_GROUP) {
215 return top_transient(CLIENT_AS_WINDOW(client->transient_for));
219 for (it = client->group->members; it; it = it->next) {
220 Client *c = it->data;
222 /* checking transient_for prevents infinate loops! */
223 if (c != client && !c->transient_for)
234 void stacking_raise(ObWindow *window)
238 window = top_transient(window);
239 wins = pick_windows(window);
240 wins = g_list_concat(wins, pick_group_windows(window));
245 void stacking_lower(ObWindow *window)
249 window = top_transient(window);
250 wins = pick_windows(window);
251 wins = g_list_concat(wins, pick_group_windows(window));
256 void stacking_add(ObWindow *win)
261 l = window_layer(win);
262 wins = g_list_append(NULL, win); /* list of 1 element */
264 for (it = stacking_list; it; it = g_list_next(it))
265 if (window_layer(it->data) <= l)
267 do_restack(wins, it);
273 void stacking_add_nonintrusive(ObWindow *win)
276 Client *parent = NULL;
277 GList *it_before = NULL;
279 if (!WINDOW_IS_CLIENT(win)) {
280 stacking_add(win); /* no special rules for others */
284 client = WINDOW_AS_CLIENT(win);
286 /* insert above its highest parent */
287 if (client->transient_for) {
288 if (client->transient_for != TRAN_GROUP) {
289 parent = client->transient_for;
295 for (it = stacking_list; !parent && it; it = it->next) {
296 if ((sit = g_slist_find(client->group->members, it->data)))
297 for (sit = client->group->members; !parent && sit;
299 Client *c = sit->data;
300 /* checking transient_for prevents infinate loops! */
301 if (sit->data == it->data && !c->transient_for)
308 if (!(it_before = g_list_find(stacking_list, parent))) {
309 /* no parent to put above, try find the focused client to go
311 if (focus_client && focus_client->layer == client->layer) {
312 if ((it_before = g_list_find(stacking_list, focus_client)))
313 it_before = it_before->next;
317 /* out of ideas, just add it normally... */
320 GList *wins = g_list_append(NULL, win);
321 do_restack(wins, it_before);