]>
Dogcows Code - chaz/openbox/blob - openbox/stacking.c
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
== OB_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 g_assert(win
[i
] != None
); /* better not call stacking shit before
65 setting your top level window value */
66 stacking_list
= g_list_insert_before(stacking_list
, before
, it
->data
);
69 /* XXX some debug checking of the stacking list's order */
70 for (it
= stacking_list
; ; it
= next
) {
71 next
= g_list_next(it
);
73 g_assert(window_layer(it
->data
) >= window_layer(next
->data
));
76 XRestackWindows(ob_display
, win
, i
);
82 static void do_raise(GList
*wins
)
85 GList
*layer
[NUM_STACKLAYER
] = {NULL
};
88 for (it
= wins
; it
; it
= g_list_next(it
)) {
91 l
= window_layer(it
->data
);
92 layer
[l
] = g_list_append(layer
[l
], it
->data
);
96 for (i
= NUM_STACKLAYER
- 1; i
>= 0; --i
) {
98 for (; it
; it
= g_list_next(it
)) {
99 /* look for the top of the layer */
100 if (window_layer(it
->data
) <= (StackLayer
) i
)
103 do_restack(layer
[i
], it
);
104 g_list_free(layer
[i
]);
109 static void do_lower(GList
*wins
)
112 GList
*layer
[NUM_STACKLAYER
] = {NULL
};
115 for (it
= wins
; it
; it
= g_list_next(it
)) {
118 l
= window_layer(it
->data
);
119 layer
[l
] = g_list_append(layer
[l
], it
->data
);
123 for (i
= NUM_STACKLAYER
- 1; i
>= 0; --i
) {
125 for (; it
; it
= g_list_next(it
)) {
126 /* look for the top of the next layer down */
127 if (window_layer(it
->data
) < (StackLayer
) i
)
130 do_restack(layer
[i
], it
);
131 g_list_free(layer
[i
]);
136 static GList
*pick_windows(ObClient
*top
, ObClient
*selected
, gboolean raise
)
139 GList
*it
, *next
, *prev
;
142 GList
*modals
= NULL
;
144 GList
*modal_sel_it
= NULL
; /* the selected guy if modal */
145 GList
*trans_sel_it
= NULL
; /* the selected guy if not */
147 /* remove first so we can't run into ourself */
148 stacking_list
= g_list_remove(stacking_list
, top
);
151 n
= g_slist_length(top
->transients
);
152 for (it
= stacking_list
; i
< n
&& it
; it
= next
) {
153 prev
= g_list_previous(it
);
154 next
= g_list_next(it
);
156 if ((sit
= g_slist_find(top
->transients
, it
->data
))) {
157 ObClient
*c
= sit
->data
;
163 trans
= g_list_concat(trans
,
164 pick_windows(c
, selected
, raise
));
166 g_assert(modal_sel_it
== NULL
);
167 g_assert(trans_sel_it
== NULL
);
168 trans_sel_it
= pick_windows(c
, selected
, raise
);
172 modals
= g_list_concat(modals
,
173 pick_windows(c
, selected
, raise
));
175 g_assert(modal_sel_it
== NULL
);
176 g_assert(trans_sel_it
== NULL
);
177 modal_sel_it
= pick_windows(c
, selected
, raise
);
180 /* if we dont have a prev then start back at the beginning,
181 otherwise skip back to the prev's next */
182 next
= prev
? g_list_next(prev
) : stacking_list
;
186 ret
= g_list_concat((raise
? modal_sel_it
: modals
),
187 (raise
? modals
: modal_sel_it
));
189 ret
= g_list_concat(ret
, (raise
? trans_sel_it
: trans
));
190 ret
= g_list_concat(ret
, (raise
? trans
: trans_sel_it
));
194 ret
= g_list_append(ret
, top
);
199 static GList
*pick_group_windows(ObClient
*top
, ObClient
*selected
, gboolean raise
)
202 GList
*it
, *next
, *prev
;
206 /* add group members in their stacking order */
209 n
= g_slist_length(top
->group
->members
) - 1;
210 for (it
= stacking_list
; i
< n
&& it
; it
= next
) {
211 prev
= g_list_previous(it
);
212 next
= g_list_next(it
);
214 if ((sit
= g_slist_find(top
->group
->members
, it
->data
))) {
216 ret
= g_list_concat(ret
,
217 pick_windows(sit
->data
, selected
, raise
));
218 /* if we dont have a prev then start back at the beginning,
219 otherwise skip back to the prev's next */
220 next
= prev
? g_list_next(prev
) : stacking_list
;
227 void stacking_raise(ObWindow
*window
)
231 if (WINDOW_IS_CLIENT(window
)) {
234 selected
= WINDOW_AS_CLIENT(window
);
235 c
= client_search_top_transient(selected
);
236 wins
= pick_windows(c
, selected
, TRUE
);
237 wins
= g_list_concat(wins
, pick_group_windows(c
, selected
, TRUE
));
239 wins
= g_list_append(NULL
, window
);
240 stacking_list
= g_list_remove(stacking_list
, window
);
246 void stacking_lower(ObWindow
*window
)
250 if (WINDOW_IS_CLIENT(window
)) {
253 selected
= WINDOW_AS_CLIENT(window
);
254 c
= client_search_top_transient(selected
);
255 wins
= pick_windows(c
, selected
, FALSE
);
256 wins
= g_list_concat(pick_group_windows(c
, selected
, FALSE
), wins
);
258 wins
= g_list_append(NULL
, window
);
259 stacking_list
= g_list_remove(stacking_list
, window
);
265 void stacking_add(ObWindow
*win
)
270 g_assert(focus_backup
!= None
); /* make sure I dont break this in the
273 l
= window_layer(win
);
274 wins
= g_list_append(NULL
, win
); /* list of 1 element */
276 stacking_list
= g_list_append(stacking_list
, win
);
280 void stacking_add_nonintrusive(ObWindow
*win
)
283 ObClient
*parent
= NULL
;
284 GList
*it_before
= NULL
;
286 if (!WINDOW_IS_CLIENT(win
)) {
287 stacking_add(win
); /* no special rules for others */
291 client
= WINDOW_AS_CLIENT(win
);
293 /* insert above its highest parent */
294 if (client
->transient_for
) {
295 if (client
->transient_for
!= OB_TRAN_GROUP
) {
296 parent
= client
->transient_for
;
302 for (it
= stacking_list
; !parent
&& it
; it
= it
->next
) {
303 if ((sit
= g_slist_find(client
->group
->members
, it
->data
)))
304 for (sit
= client
->group
->members
; !parent
&& sit
;
306 ObClient
*c
= sit
->data
;
307 /* checking transient_for prevents infinate loops! */
308 if (sit
->data
== it
->data
&& !c
->transient_for
)
315 if (!(it_before
= g_list_find(stacking_list
, parent
))) {
316 /* no parent to put above, try find the focused client to go
318 if (focus_client
&& focus_client
->layer
== client
->layer
) {
319 if ((it_before
= g_list_find(stacking_list
, focus_client
)))
320 it_before
= it_before
->next
;
324 /* out of ideas, just add it normally... */
327 GList
*wins
= g_list_append(NULL
, win
);
328 do_restack(wins
, it_before
);
This page took 0.050109 seconds and 4 git commands to generate.