]> Dogcows Code - chaz/openbox/blob - openbox/stacking.c
add internal popups n shit to the stacking list.
[chaz/openbox] / openbox / stacking.c
1 #include "openbox.h"
2 #include "prop.h"
3 #include "focus.h"
4 #include "client.h"
5 #include "group.h"
6 #include "frame.h"
7 #include "window.h"
8 #include <glib.h>
9
10 GList *stacking_list = NULL;
11
12 void stacking_set_list()
13 {
14 Window *windows, *win_it;
15 GList *it;
16 guint size = g_list_length(stacking_list);
17
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
20 */
21 if (ob_state == State_Exiting) return;
22
23 /* create an array of the window ids (from bottom to top,
24 reverse order!) */
25 if (size > 0) {
26 windows = g_new(Window, size);
27 win_it = windows;
28 for (it = g_list_last(stacking_list); it != NULL;
29 it = it->prev)
30 if (WINDOW_IS_CLIENT(it->data)) {
31 *win_it = window_top(it->data);
32 ++win_it;
33 }
34 } else
35 windows = win_it = NULL;
36
37 PROP_SETA32(ob_root, net_client_list_stacking, window,
38 (guint32*)windows, win_it - windows);
39
40 g_print("Client list:");
41 for (it = client_list; it; it = it->next)
42 g_print("0x%lx ", ((Client*)it->data)->window);
43 g_print("\n");
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);
48 g_print("\n");
49
50 if (windows)
51 g_free(windows);
52 }
53
54 static GList *find_lowest_transient(Client *c)
55 {
56 GList *it;
57 GSList *sit;
58
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 */
62 return it;
63 return NULL;
64 }
65
66 static void raise_recursive(ObWindow *window)
67 {
68 Window wins[2]; /* only ever restack 2 windows. */
69 GList *it, *low;
70 GSList *sit;
71
72 g_assert(stacking_list != NULL); /* this would be bad */
73
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);
77
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);
83 }
84
85 /* find 'it' where it is the positiion in the stacking order where
86 'window' will be inserted *before* */
87
88 if (WINDOW_IS_CLIENT(window))
89 low = find_lowest_transient(WINDOW_AS_CLIENT(window));
90 else
91 low = NULL;
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)) {
95 it = it->next;
96 break;
97 }
98 if (it == stacking_list)
99 break;
100 }
101
102 /*
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.
105 */
106 if (it == stacking_list)
107 wins[0] = focus_backup;
108 else if (it != NULL)
109 wins[0] = window_top(it->prev->data);
110 else
111 wins[0] = window_top(g_list_last(stacking_list)->data);
112 wins[1] = window_top(window);
113
114 stacking_list = g_list_insert_before(stacking_list, it, window);
115
116 XRestackWindows(ob_display, wins, 2);
117 }
118
119 void stacking_raise(ObWindow *window)
120 {
121 g_assert(stacking_list != NULL); /* this would be bad */
122
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;
129 } else {
130 GSList *it;
131
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
134 members list */
135 for (it = client->group->members; it; it = it->next) {
136 Client *c = it->data;
137
138 if (c != client && c->transient_for != TRAN_GROUP) {
139 client = it->data;
140 break;
141 }
142 }
143 if (it == NULL) break;
144 }
145 }
146 window = CLIENT_AS_WINDOW(client);
147 }
148
149 raise_recursive(window);
150
151 stacking_set_list();
152 }
153
154 static void lower_recursive(ObWindow *window, ObWindow *above)
155 {
156 Window wins[2]; /* only ever restack 2 windows. */
157 GList *it;
158 GSList *sit;
159
160 /* find 'it' where 'it' is the position in the stacking_list where the
161 'window' will be placed *after* */
162
163 for (it = g_list_last(stacking_list); it != stacking_list; it = it->prev)
164 if (window_layer(window) <= window_layer(it->data) &&
165 it->data != above)
166 break;
167
168 if (it->data != window) { /* not already the bottom */
169 wins[0] = window_top(it->data);
170 wins[1] = window_top(window);
171
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);
175 }
176
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);
181 }
182 }
183
184 void stacking_lower(ObWindow *window)
185 {
186 g_assert(stacking_list != NULL); /* this would be bad */
187
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;
194 } else {
195 GSList *it;
196
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
199 members list */
200 for (it = client->group->members; it; it = it->next) {
201 Client *c = it->data;
202
203 if (c != client && c->transient_for != TRAN_GROUP) {
204 client = it->data;
205 break;
206 }
207 }
208 if (it == NULL) break;
209 }
210 }
211 window = CLIENT_AS_WINDOW(client);
212 }
213
214 lower_recursive(window, NULL);
215
216 stacking_set_list();
217 }
This page took 0.0429 seconds and 4 git commands to generate.