]>
Dogcows Code - chaz/openbox/blob - openbox/stacking.c
2fa4b2e6d9dc8c83d15c2641193da527ccf9c6fa
10 GList
*stacking_list
= NULL
;
12 void stacking_set_list()
14 Window
*windows
= NULL
;
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
, g_list_length(stacking_list
));
27 for (it
= g_list_last(stacking_list
); it
; it
= g_list_previous(it
)) {
28 if (WINDOW_IS_CLIENT(it
->data
))
29 windows
[i
++] = WINDOW_AS_CLIENT(it
->data
)->window
;
33 PROP_SETA32(ob_root
, net_client_list_stacking
, window
,
34 (guint32
*)windows
, i
);
39 static void do_restack(GList
*wins
, GList
*before
)
45 /* pls only restack stuff in the same layer at a time */
46 for (it
= wins
; it
; it
= next
) {
47 next
= g_list_next(it
);
49 g_assert (window_layer(it
->data
) == window_layer(next
->data
));
53 win
= g_new(Window
, g_list_length(wins
) + 1);
55 if (before
== stacking_list
)
56 win
[0] = focus_backup
;
58 win
[0] = window_top(g_list_last(stacking_list
)->data
);
60 win
[0] = window_top(g_list_previous(before
)->data
);
62 for (i
= 1, it
= wins
; it
; ++i
, it
= g_list_next(it
)) {
63 win
[i
] = window_top(it
->data
);
64 stacking_list
= g_list_insert_before(stacking_list
, before
, it
->data
);
67 /* XXX some debug checking of the stacking list's order */
68 for (it
= stacking_list
; ; it
= next
) {
69 next
= g_list_next(it
);
71 g_assert(window_layer(it
->data
) >= window_layer(next
->data
));
74 XRestackWindows(ob_display
, win
, i
);
80 static void raise(GList
*wins
)
83 GList
*layer
[NUM_STACKLAYER
] = {NULL
};
86 for (it
= wins
; it
; it
= g_list_next(it
)) {
89 l
= window_layer(it
->data
);
90 layer
[l
] = g_list_append(layer
[l
], it
->data
);
94 for (i
= NUM_STACKLAYER
- 1; i
>= 0; --i
) {
96 for (; it
; it
= g_list_next(it
)) {
97 /* look for the top of the layer */
98 if (window_layer(it
->data
) <= (StackLayer
) i
)
101 do_restack(layer
[i
], it
);
102 g_list_free(layer
[i
]);
107 static void lower(GList
*wins
)
110 GList
*layer
[NUM_STACKLAYER
] = {NULL
};
113 for (it
= wins
; it
; it
= g_list_next(it
)) {
116 l
= window_layer(it
->data
);
117 layer
[l
] = g_list_append(layer
[l
], it
->data
);
121 for (i
= NUM_STACKLAYER
- 1; i
>= 0; --i
) {
123 for (; it
; it
= g_list_next(it
)) {
124 /* look for the top of the next layer down */
125 if (window_layer(it
->data
) < (StackLayer
) i
)
128 do_restack(layer
[i
], it
);
129 g_list_free(layer
[i
]);
134 static GList
*pick_windows(ObWindow
*win
)
142 if (!WINDOW_IS_CLIENT(win
)) {
143 ret
= g_list_append(ret
, win
);
144 stacking_list
= g_list_remove(stacking_list
, win
);
148 c
= WINDOW_AS_CLIENT(win
);
150 /* remove first so we can't run into ourself */
151 stacking_list
= g_list_remove(stacking_list
, win
);
153 /* add transient children in their stacking order */
155 n
= g_slist_length(c
->transients
);
156 for (it
= stacking_list
; i
< n
&& it
; it
= next
) {
157 next
= g_list_next(it
);
158 if ((sit
= g_slist_find(c
->transients
, it
->data
))) {
160 ret
= g_list_concat(ret
, pick_windows(sit
->data
));
166 ret
= g_list_append(ret
, win
);
171 static GList
*pick_group_windows(ObWindow
*win
)
179 if (!WINDOW_IS_CLIENT(win
))
182 c
= WINDOW_AS_CLIENT(win
);
184 /* add group members in their stacking order */
187 n
= g_slist_length(c
->group
->members
) - 1;
188 for (it
= stacking_list
; i
< n
&& it
; it
= next
) {
189 next
= g_list_next(it
);
190 if ((sit
= g_slist_find(c
->group
->members
, it
->data
))) {
192 ret
= g_list_concat(ret
, pick_windows(sit
->data
));
200 static ObWindow
*top_transient(ObWindow
*window
)
204 if (!WINDOW_IS_CLIENT(window
))
207 client
= WINDOW_AS_CLIENT(window
);
209 /* move up the transient chain as far as possible */
210 if (client
->transient_for
) {
211 if (client
->transient_for
!= TRAN_GROUP
) {
212 return top_transient(CLIENT_AS_WINDOW(client
->transient_for
));
216 for (it
= client
->group
->members
; it
; it
= it
->next
) {
217 Client
*c
= it
->data
;
219 /* checking transient_for prevents infinate loops! */
220 if (c
!= client
&& !c
->transient_for
)
231 void stacking_raise(ObWindow
*window
)
235 window
= top_transient(window
);
236 wins
= pick_windows(window
);
237 wins
= g_list_concat(wins
, pick_group_windows(window
));
242 void stacking_lower(ObWindow
*window
)
246 window
= top_transient(window
);
247 wins
= pick_windows(window
);
248 wins
= g_list_concat(pick_group_windows(window
), wins
);
253 void stacking_add(ObWindow
*win
)
258 l
= window_layer(win
);
259 wins
= g_list_append(NULL
, win
); /* list of 1 element */
261 stacking_list
= g_list_append(stacking_list
, win
);
265 void stacking_add_nonintrusive(ObWindow
*win
)
268 Client
*parent
= NULL
;
269 GList
*it_before
= NULL
;
271 if (!WINDOW_IS_CLIENT(win
)) {
272 stacking_add(win
); /* no special rules for others */
276 client
= WINDOW_AS_CLIENT(win
);
278 /* insert above its highest parent */
279 if (client
->transient_for
) {
280 if (client
->transient_for
!= TRAN_GROUP
) {
281 parent
= client
->transient_for
;
287 for (it
= stacking_list
; !parent
&& it
; it
= it
->next
) {
288 if ((sit
= g_slist_find(client
->group
->members
, it
->data
)))
289 for (sit
= client
->group
->members
; !parent
&& sit
;
291 Client
*c
= sit
->data
;
292 /* checking transient_for prevents infinate loops! */
293 if (sit
->data
== it
->data
&& !c
->transient_for
)
300 if (!(it_before
= g_list_find(stacking_list
, parent
))) {
301 /* no parent to put above, try find the focused client to go
303 if (focus_client
&& focus_client
->layer
== client
->layer
) {
304 if ((it_before
= g_list_find(stacking_list
, focus_client
)))
305 it_before
= it_before
->next
;
309 /* out of ideas, just add it normally... */
312 GList
*wins
= g_list_append(NULL
, win
);
313 do_restack(wins
, it_before
);
This page took 0.045445 seconds and 4 git commands to generate.