9 GList *stacking_list = NULL;
11 static Window top_window = None;
13 void stacking_startup()
15 XSetWindowAttributes attrib;
16 attrib.override_redirect = TRUE;
17 top_window = XCreateWindow(ob_display, ob_root,
19 CopyFromParent, InputOutput, CopyFromParent,
20 CWOverrideRedirect, &attrib);
21 XMapWindow(ob_display, top_window);
24 void stacking_shutdown()
26 XDestroyWindow(ob_display, top_window);
29 void stacking_set_list()
31 Window *windows, *win_it;
33 guint size = g_list_length(stacking_list);
35 /* on shutdown, don't update the properties, so that we can read it back
36 in on startup and re-stack the windows as they were before we shut down
38 if (ob_state == State_Exiting) return;
40 /* create an array of the window ids (from bottom to top,
43 windows = g_new(Window, size);
45 for (it = g_list_last(stacking_list); it != NULL;
46 it = it->prev, ++win_it)
47 *win_it = ((Client*)it->data)->window;
51 PROP_SETA32(ob_root, net_client_list_stacking, window,
52 (guint32*)windows, size);
58 static GList *find_lowest_transient(Client *c)
63 for (it = g_list_last(stacking_list); it; it = it->prev)
64 for (sit = c->transients; sit; sit = sit->next)
65 if (it->data == sit->data) /* found a transient */
70 static void raise_recursive(Client *client)
72 Window wins[2]; /* only ever restack 2 windows. */
76 g_assert(stacking_list != NULL); /* this would be bad */
78 /* remove the client before looking so we can't run into ourselves and our
79 transients can't either. */
80 stacking_list = g_list_remove(stacking_list, client);
82 /* raise transients first */
83 for (sit = client->transients; sit; sit = sit->next)
84 if (((Client*)sit->data)->frame)
85 raise_recursive(sit->data);
87 /* find 'it' where it is the positiion in the stacking order where
88 'client' will be inserted *before* */
90 it = find_lowest_transient(client);
94 /* the stacking list is from highest to lowest */
95 for (it = stacking_list; it; it = it->next) {
96 if (client->layer >= ((Client*)it->data)->layer)
102 if our new position is the top, we want to stack under the focus_backup.
103 otherwise, we want to stack under the previous window in the stack.
105 if (it == stacking_list)
106 wins[0] = focus_backup;
108 wins[0] = ((Client*)it->prev->data)->frame->window;
110 wins[0] = ((Client*)g_list_last(stacking_list)->data)->frame->window;
111 wins[1] = client->frame->window;
113 stacking_list = g_list_insert_before(stacking_list, it, client);
115 XRestackWindows(ob_display, wins, 2);
118 void stacking_raise(Client *client)
120 g_assert(stacking_list != NULL); /* this would be bad */
122 /* move up the transient chain as far as possible first */
123 while (client->transient_for) {
124 if (client->transient_for != TRAN_GROUP) {
125 client = client->transient_for;
129 /* the check for TRAN_GROUP is to prevent an infinate loop with
130 2 transients of the same group at the head of the group's
132 for (it = client->group->members; it; it = it->next) {
133 Client *c = it->data;
135 if (c != client && c->transient_for != TRAN_GROUP) {
140 if (it == NULL) break;
144 raise_recursive(client);
149 static void lower_recursive(Client *client, Client *above)
151 Window wins[2]; /* only ever restack 2 windows. */
155 /* find 'it' where 'it' is the position in the stacking_list where the
156 'client' will be placed *after* */
158 for (it = g_list_last(stacking_list); it != stacking_list; it = it->prev)
159 if (client->layer <= ((Client*)it->data)->layer && it->data != above)
162 if (it->data != client) { /* not already the bottom */
163 wins[0] = ((Client*)it->data)->frame->window;
164 wins[1] = client->frame->window;
166 stacking_list = g_list_remove(stacking_list, client);
167 stacking_list = g_list_insert_before(stacking_list, it->next, client);
168 XRestackWindows(ob_display, wins, 2);
171 for (sit = client->transients; sit; sit = sit->next)
172 lower_recursive(sit->data, client);
175 void stacking_lower(Client *client)
177 g_assert(stacking_list != NULL); /* this would be bad */
179 /* move up the transient chain as far as possible first */
180 while (client->transient_for) {
181 if (client->transient_for != TRAN_GROUP) {
182 client = client->transient_for;
186 /* the check for TRAN_GROUP is to prevent an infinate loop with
187 2 transients of the same group at the head of the group's
189 for (it = client->group->members; it; it = it->next) {
190 Client *c = it->data;
192 if (c != client && c->transient_for != TRAN_GROUP) {
197 if (it == NULL) break;
201 lower_recursive(client, NULL);
206 void stacking_raise_internal(Window win)
208 Window wins[2]; /* only ever restack 2 windows. */
210 wins[0] = top_window;
213 XRestackWindows(ob_display, wins, 2);