]>
Dogcows Code - chaz/openbox/blob - openbox/stacking.c
e205d4b05b952032ef0dc65f4a7a6c801164fc19
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 GList
*find_lowest_transient(Client
*c
)
49 for (it
= g_list_last(stacking_list
); it
; it
= it
->prev
)
50 for (sit
= c
->transients
; sit
; sit
= sit
->next
)
51 if (it
->data
== sit
->data
) /* found a transient */
56 static void raise_recursive(ObWindow
*window
)
58 Window wins
[2]; /* only ever restack 2 windows. */
62 g_assert(stacking_list
!= NULL
); /* this would be bad */
64 /* remove the window before looking so we can't run into ourselves and our
65 transients can't either. */
66 stacking_list
= g_list_remove(stacking_list
, window
);
68 /* raise transients first */
69 if (WINDOW_IS_CLIENT(window
)) {
70 Client
*client
= WINDOW_AS_CLIENT(window
);
71 for (sit
= client
->transients
; sit
; sit
= sit
->next
)
72 raise_recursive(sit
->data
);
75 /* find 'it' where it is the positiion in the stacking order where
76 'window' will be inserted *before* */
78 if (WINDOW_IS_CLIENT(window
))
79 low
= find_lowest_transient(WINDOW_AS_CLIENT(window
));
82 /* the stacking list is from highest to lowest */
83 for (it
= g_list_last(stacking_list
); it
; it
= it
->prev
) {
84 if (it
== low
|| window_layer(window
) < window_layer(it
->data
)) {
88 if (it
== stacking_list
)
93 if our new position is the top, we want to stack under the focus_backup.
94 otherwise, we want to stack under the previous window in the stack.
96 if (it
== stacking_list
)
97 wins
[0] = focus_backup
;
99 wins
[0] = window_top(it
->prev
->data
);
101 wins
[0] = window_top(g_list_last(stacking_list
)->data
);
102 wins
[1] = window_top(window
);
104 stacking_list
= g_list_insert_before(stacking_list
, it
, window
);
106 XRestackWindows(ob_display
, wins
, 2);
109 void stacking_raise(ObWindow
*window
)
111 g_assert(stacking_list
!= NULL
); /* this would be bad */
113 if (WINDOW_IS_CLIENT(window
)) {
114 Client
*client
= WINDOW_AS_CLIENT(window
);
115 /* move up the transient chain as far as possible first */
116 if (client
->transient_for
) {
117 if (client
->transient_for
!= TRAN_GROUP
) {
118 stacking_raise(CLIENT_AS_WINDOW(client
->transient_for
));
123 for (it
= client
->group
->members
; it
; it
= it
->next
) {
124 Client
*c
= it
->data
;
126 /* checking transient_for prevents infinate loops! */
127 if (c
!= client
&& !c
->transient_for
)
128 stacking_raise(it
->data
);
130 if (it
== NULL
) return;
135 raise_recursive(window
);
140 static void lower_recursive(ObWindow
*window
, ObWindow
*above
)
142 Window wins
[2]; /* only ever restack 2 windows. */
146 /* find 'it' where 'it' is the position in the stacking_list where the
147 'window' will be placed *after* */
149 for (it
= g_list_last(stacking_list
); it
!= stacking_list
; it
= it
->prev
)
150 if (window_layer(window
) <= window_layer(it
->data
) &&
154 if (it
->data
!= window
) { /* not already the bottom */
155 wins
[0] = window_top(it
->data
);
156 wins
[1] = window_top(window
);
158 stacking_list
= g_list_remove(stacking_list
, window
);
159 stacking_list
= g_list_insert_before(stacking_list
, it
->next
, window
);
160 XRestackWindows(ob_display
, wins
, 2);
163 if (WINDOW_IS_CLIENT(window
)) {
164 Client
*client
= WINDOW_AS_CLIENT(window
);
165 for (sit
= client
->transients
; sit
; sit
= sit
->next
)
166 lower_recursive(CLIENT_AS_WINDOW(sit
->data
), window
);
170 void stacking_lower(ObWindow
*window
)
172 g_assert(stacking_list
!= NULL
); /* this would be bad */
174 if (WINDOW_IS_CLIENT(window
)) {
175 Client
*client
= WINDOW_AS_CLIENT(window
);
176 /* move up the transient chain as far as possible first */
177 while (client
->transient_for
) {
178 if (client
->transient_for
!= TRAN_GROUP
) {
179 stacking_lower(CLIENT_AS_WINDOW(client
->transient_for
));
184 for (it
= client
->group
->members
; it
; it
= it
->next
) {
185 Client
*c
= it
->data
;
187 /* checking transient_for prevents infinate loops! */
188 if (c
!= client
&& !c
->transient_for
)
189 stacking_lower(it
->data
);
191 if (it
== NULL
) return;
194 window
= CLIENT_AS_WINDOW(client
);
197 lower_recursive(window
, NULL
);
202 void stacking_add(ObWindow
*win
)
204 stacking_list
= g_list_append(stacking_list
, win
);
208 void stacking_add_nonintrusive(ObWindow
*win
)
210 Window wins
[2]; /* only ever restack 2 windows. */
212 if (!WINDOW_IS_CLIENT(win
))
213 stacking_add(win
); /* no special rules for others */
215 Client
*client
= WINDOW_AS_CLIENT(win
);
216 Client
*parent
= NULL
;
217 GList
*it_before
= NULL
;
219 /* insert above its highest parent */
220 if (client
->transient_for
) {
221 if (client
->transient_for
!= TRAN_GROUP
) {
222 parent
= client
->transient_for
;
227 for (it
= stacking_list
; !parent
&& it
; it
= it
->next
) {
228 for (sit
= client
->group
->members
; !parent
&& sit
;
230 Client
*c
= sit
->data
;
231 /* checking transient_for prevents infinate loops! */
232 if (sit
->data
== it
->data
&& !c
->transient_for
)
239 if (!(it_before
= g_list_find(stacking_list
, parent
))) {
240 /* no parent to put above, try find the focused client to go
242 if ((it_before
= g_list_find(stacking_list
, focus_client
)))
243 it_before
= it_before
->next
;
245 /* out of ideas, just add it normally... */
250 stacking_list
= g_list_insert_before(stacking_list
, it_before
, win
);
252 it_before
= g_list_find(stacking_list
, win
)->prev
;
254 wins
[0] = focus_backup
;
256 wins
[0] = window_top(it_before
->data
);
257 wins
[1] = window_top(win
);
259 XRestackWindows(ob_display
, wins
, 2);
This page took 0.047012 seconds and 4 git commands to generate.