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_top(it->data);
35 windows = win_it = NULL;
37 PROP_SETA32(ob_root, net_client_list_stacking, window,
38 (guint32*)windows, win_it - windows);
40 g_print("Client list:");
41 for (it = client_list; it; it = it->next)
42 g_print("0x%lx ", ((Client*)it->data)->window);
44 g_print("Stacking order: ");
45 for (it = stacking_list; it; it = it->next)
46 if (WINDOW_IS_CLIENT(it->data))
47 g_print("0x%lx ", ((Client*)it->data)->window);
54 static GList *find_lowest_transient(Client *c)
59 for (it = g_list_last(stacking_list); it; it = it->prev)
60 for (sit = c->transients; sit; sit = sit->next)
61 if (it->data == sit->data) /* found a transient */
66 static void raise_recursive(ObWindow *window)
68 Window wins[2]; /* only ever restack 2 windows. */
72 g_assert(stacking_list != NULL); /* this would be bad */
74 /* remove the window before looking so we can't run into ourselves and our
75 transients can't either. */
76 stacking_list = g_list_remove(stacking_list, window);
78 /* raise transients first */
79 if (WINDOW_IS_CLIENT(window)) {
80 Client *client = WINDOW_AS_CLIENT(window);
81 for (sit = client->transients; sit; sit = sit->next)
82 raise_recursive(sit->data);
85 /* find 'it' where it is the positiion in the stacking order where
86 'window' will be inserted *before* */
88 if (WINDOW_IS_CLIENT(window))
89 low = find_lowest_transient(WINDOW_AS_CLIENT(window));
92 /* the stacking list is from highest to lowest */
93 for (it = g_list_last(stacking_list); it; it = it->prev) {
94 if (it == low || window_layer(window) < window_layer(it->data)) {
98 if (it == stacking_list)
103 if our new position is the top, we want to stack under the focus_backup.
104 otherwise, we want to stack under the previous window in the stack.
106 if (it == stacking_list)
107 wins[0] = focus_backup;
109 wins[0] = window_top(it->prev->data);
111 wins[0] = window_top(g_list_last(stacking_list)->data);
112 wins[1] = window_top(window);
114 stacking_list = g_list_insert_before(stacking_list, it, window);
116 XRestackWindows(ob_display, wins, 2);
119 void stacking_raise(ObWindow *window)
121 g_assert(stacking_list != NULL); /* this would be bad */
123 if (WINDOW_IS_CLIENT(window)) {
124 Client *client = WINDOW_AS_CLIENT(window);
125 /* move up the transient chain as far as possible first */
126 while (client->transient_for) {
127 if (client->transient_for != TRAN_GROUP) {
128 client = client->transient_for;
132 /* the check for TRAN_GROUP is to prevent an infinate loop with
133 2 transients of the same group at the head of the group's
135 for (it = client->group->members; it; it = it->next) {
136 Client *c = it->data;
138 if (c != client && c->transient_for != TRAN_GROUP) {
143 if (it == NULL) break;
146 window = CLIENT_AS_WINDOW(client);
149 raise_recursive(window);
154 static void lower_recursive(ObWindow *window, ObWindow *above)
156 Window wins[2]; /* only ever restack 2 windows. */
160 /* find 'it' where 'it' is the position in the stacking_list where the
161 'window' will be placed *after* */
163 for (it = g_list_last(stacking_list); it != stacking_list; it = it->prev)
164 if (window_layer(window) <= window_layer(it->data) &&
168 if (it->data != window) { /* not already the bottom */
169 wins[0] = window_top(it->data);
170 wins[1] = window_top(window);
172 stacking_list = g_list_remove(stacking_list, window);
173 stacking_list = g_list_insert_before(stacking_list, it->next, window);
174 XRestackWindows(ob_display, wins, 2);
177 if (WINDOW_IS_CLIENT(window)) {
178 Client *client = WINDOW_AS_CLIENT(window);
179 for (sit = client->transients; sit; sit = sit->next)
180 lower_recursive(CLIENT_AS_WINDOW(sit->data), window);
184 void stacking_lower(ObWindow *window)
186 g_assert(stacking_list != NULL); /* this would be bad */
188 if (WINDOW_IS_CLIENT(window)) {
189 Client *client = WINDOW_AS_CLIENT(window);
190 /* move up the transient chain as far as possible first */
191 while (client->transient_for) {
192 if (client->transient_for != TRAN_GROUP) {
193 client = client->transient_for;
197 /* the check for TRAN_GROUP is to prevent an infinate loop with
198 2 transients of the same group at the head of the group's
200 for (it = client->group->members; it; it = it->next) {
201 Client *c = it->data;
203 if (c != client && c->transient_for != TRAN_GROUP) {
208 if (it == NULL) break;
211 window = CLIENT_AS_WINDOW(client);
214 lower_recursive(window, NULL);