9 GList *stacking_list = NULL;
11 void stacking_set_list()
13 Window *windows, *win_it;
15 guint size = g_list_length(stacking_list);
17 /* on shutdown, don't update the properties, so that we can read it back
18 in on startup and re-stack the windows as they were before we shut down
20 if (ob_state == State_Exiting) return;
22 /* create an array of the window ids (from bottom to top,
25 windows = g_new(Window, size);
27 for (it = g_list_last(stacking_list); it != NULL;
28 it = it->prev, ++win_it)
29 *win_it = ((Client*)it->data)->window;
33 PROP_SET32A(ob_root, net_client_list_stacking, window, windows, size);
39 static GList *find_lowest_transient(Client *c)
44 for (it = g_list_last(stacking_list); it; it = it->prev)
45 for (sit = c->transients; sit; sit = sit->next)
46 if (it->data == sit->data) /* found a transient */
47 if (((Client*)it->data)->layer == c->layer) /* same layer? */
52 void stacking_raise(Client *client)
54 Window wins[2]; /* only ever restack 2 windows. */
58 g_assert(stacking_list != NULL); /* this would be bad */
60 /* if we have a transients raise them */
61 for (sit = client->transients; sit; sit = sit->next)
62 stacking_raise(sit->data);
64 /* remove the client before looking so we can't run into ourselves */
65 stacking_list = g_list_remove(stacking_list, client);
67 /* find 'it' where it is the positiion in the stacking order where
68 'client' will be inserted *after* */
70 it = find_lowest_transient(client);
74 /* the stacking list is from highest to lowest */
75 for (it = stacking_list; it; it = it->next) {
76 if (client->layer >= ((Client*)it->data)->layer)
82 if our new position is the top, we want to stack under the focus_backup.
83 otherwise, we want to stack under the previous window in the stack.
85 if (it == stacking_list)
86 wins[0] = focus_backup;
88 wins[0] = ((Client*)it->prev->data)->frame->window;
90 wins[0] = ((Client*)g_list_last(stacking_list)->data)->frame->window;
91 wins[1] = client->frame->window;
93 stacking_list = g_list_insert_before(stacking_list, it, client);
95 XRestackWindows(ob_display, wins, 2);
100 static void lower_recursive(Client *client, Client *above)
102 Window wins[2]; /* only ever restack 2 windows. */
106 it = g_list_last(stacking_list);
108 /* find 'it' where 'it' is the position in the stacking_list where the
109 'client' will be placed *after* */
111 while (it != stacking_list) {
112 Client *c = it->data;
113 if (client->layer <= c->layer && c != above)
118 if (it->data != client) { /* not already the bottom */
119 wins[0] = ((Client*)it->data)->frame->window;
120 wins[1] = client->frame->window;
122 stacking_list = g_list_remove(stacking_list, client);
123 stacking_list = g_list_insert_before(stacking_list,
125 XRestackWindows(ob_display, wins, 2);
128 for (sit = client->transients; sit; sit = sit->next)
129 lower_recursive(sit->data, client);
131 if (!above) /* only need to do this once */
135 void stacking_lower(Client *client)
137 g_assert(stacking_list != NULL); /* this would be bad */
139 /* move up the transient chain as far as possible first */
140 while (client->transient_for) {
141 if (client->transient_for != TRAN_GROUP) {
142 client = client->transient_for;
146 /* the check for TRAN_GROUP is to prevent an infinate loop with
147 2 transients of the same group at the head of the group's
149 for (it = client->group->members; it; it = it->next) {
150 Client *c = it->data;
152 if (c != client && c->transient_for != TRAN_GROUP) {
157 if (it == NULL) break;
161 lower_recursive(client, NULL);