]>
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(RootWindow(ob_display
, ob_screen
),
34 net_client_list_stacking
, window
, (guint32
*)windows
, i
);
39 static void do_restack(GList
*wins
, GList
*before
)
46 /* pls only restack stuff in the same layer at a time */
47 for (it
= wins
; it
; it
= next
) {
48 next
= g_list_next(it
);
50 g_assert (window_layer(it
->data
) == window_layer(next
->data
));
53 g_assert(window_layer(it
->data
) >= window_layer(before
->data
));
56 win
= g_new(Window
, g_list_length(wins
) + 1);
58 if (before
== stacking_list
)
59 win
[0] = screen_support_win
;
61 win
[0] = window_top(g_list_last(stacking_list
)->data
);
63 win
[0] = window_top(g_list_previous(before
)->data
);
65 for (i
= 1, it
= wins
; it
; ++i
, it
= g_list_next(it
)) {
66 win
[i
] = window_top(it
->data
);
67 g_assert(win
[i
] != None
); /* better not call stacking shit before
68 setting your top level window value */
69 stacking_list
= g_list_insert_before(stacking_list
, before
, it
->data
);
73 /* some debug checking of the stacking list's order */
74 for (it
= stacking_list
; ; it
= next
) {
75 next
= g_list_next(it
);
77 g_assert(window_layer(it
->data
) >= window_layer(next
->data
));
81 XRestackWindows(ob_display
, win
, i
);
87 static void do_raise(GList
*wins
)
90 GList
*layer
[OB_NUM_STACKING_LAYERS
] = {NULL
};
93 for (it
= wins
; it
; it
= g_list_next(it
)) {
96 l
= window_layer(it
->data
);
97 layer
[l
] = g_list_append(layer
[l
], it
->data
);
101 for (i
= OB_NUM_STACKING_LAYERS
- 1; i
>= 0; --i
) {
103 for (; it
; it
= g_list_next(it
)) {
104 /* look for the top of the layer */
105 if (window_layer(it
->data
) <= (ObStackingLayer
) i
)
108 do_restack(layer
[i
], it
);
109 g_list_free(layer
[i
]);
114 static void do_lower(GList
*wins
)
117 GList
*layer
[OB_NUM_STACKING_LAYERS
] = {NULL
};
120 for (it
= wins
; it
; it
= g_list_next(it
)) {
123 l
= window_layer(it
->data
);
124 layer
[l
] = g_list_append(layer
[l
], it
->data
);
128 for (i
= OB_NUM_STACKING_LAYERS
- 1; i
>= 0; --i
) {
130 for (; it
; it
= g_list_next(it
)) {
131 /* look for the top of the next layer down */
132 if (window_layer(it
->data
) < (ObStackingLayer
) i
)
135 do_restack(layer
[i
], it
);
136 g_list_free(layer
[i
]);
141 static GList
*pick_windows(ObClient
*top
, ObClient
*selected
, gboolean raise
)
144 GList
*it
, *next
, *prev
;
147 GList
*modals
= NULL
;
149 GList
*modal_sel
= NULL
; /* the selected guys if modal */
150 GList
*trans_sel
= NULL
; /* the selected guys if not */
152 /* remove first so we can't run into ourself */
153 if ((it
= g_list_find(stacking_list
, top
)))
154 stacking_list
= g_list_delete_link(stacking_list
, it
);
159 n
= g_slist_length(top
->transients
);
160 for (it
= stacking_list
; i
< n
&& it
; it
= next
) {
161 prev
= g_list_previous(it
);
162 next
= g_list_next(it
);
164 if ((sit
= g_slist_find(top
->transients
, it
->data
))) {
165 ObClient
*c
= sit
->data
;
173 sel_child
= client_search_transient(c
, selected
) != NULL
;
177 trans
= g_list_concat(trans
,
178 pick_windows(c
, selected
, raise
));
180 trans_sel
= g_list_concat(trans_sel
,
181 pick_windows(c
, selected
,
186 modals
= g_list_concat(modals
,
187 pick_windows(c
, selected
, raise
));
189 modal_sel
= g_list_concat(modal_sel
,
190 pick_windows(c
, selected
,
194 /* if we dont have a prev then start back at the beginning,
195 otherwise skip back to the prev's next */
196 next
= prev
? g_list_next(prev
) : stacking_list
;
200 ret
= g_list_concat((raise
? modal_sel
: modals
),
201 (raise
? modals
: modal_sel
));
203 ret
= g_list_concat(ret
, (raise
? trans_sel
: trans
));
204 ret
= g_list_concat(ret
, (raise
? trans
: trans_sel
));
208 ret
= g_list_append(ret
, top
);
214 static GList
*pick_group_windows(ObClient
*top
, ObClient
*selected
,
218 GList
*it
, *next
, *prev
;
222 /* add group members in their stacking order */
225 n
= g_slist_length(top
->group
->members
) - 1;
226 for (it
= stacking_list
; i
< n
&& it
; it
= next
) {
227 prev
= g_list_previous(it
);
228 next
= g_list_next(it
);
230 if ((sit
= g_slist_find(top
->group
->members
, it
->data
))) {
232 ret
= g_list_concat(ret
,
233 pick_windows(sit
->data
, selected
, raise
));
234 /* if we dont have a prev then start back at the beginning,
235 otherwise skip back to the prev's next */
236 next
= prev
? g_list_next(prev
) : stacking_list
;
244 void stacking_raise(ObWindow
*window
)
248 if (WINDOW_IS_CLIENT(window
)) {
251 selected
= WINDOW_AS_CLIENT(window
);
252 c
= client_search_top_transient(selected
);
253 wins
= pick_windows(c
, selected
, TRUE
);
254 /*wins = g_list_concat(wins, pick_group_windows(c, selected, TRUE));*/
256 wins
= g_list_append(NULL
, window
);
257 stacking_list
= g_list_remove(stacking_list
, window
);
263 void stacking_lower(ObWindow
*window
)
267 if (WINDOW_IS_CLIENT(window
)) {
270 selected
= WINDOW_AS_CLIENT(window
);
271 c
= client_search_top_transient(selected
);
272 wins
= pick_windows(c
, selected
, FALSE
);
273 /*wins = g_list_concat(pick_group_windows(c, selected, FALSE), wins);*/
275 wins
= g_list_append(NULL
, window
);
276 stacking_list
= g_list_remove(stacking_list
, window
);
282 void stacking_below(ObWindow
*window
, ObWindow
*below
)
284 GList
*wins
, *before
;
286 if (window_layer(window
) != window_layer(below
))
289 wins
= g_list_append(NULL
, window
);
290 stacking_list
= g_list_remove(stacking_list
, window
);
291 before
= g_list_next(g_list_find(stacking_list
, below
));
292 do_restack(wins
, before
);
296 void stacking_add(ObWindow
*win
)
301 g_assert(screen_support_win
!= None
); /* make sure I dont break this in the
304 l
= window_layer(win
);
305 wins
= g_list_append(NULL
, win
); /* list of 1 element */
307 stacking_list
= g_list_append(stacking_list
, win
);
311 void stacking_add_nonintrusive(ObWindow
*win
)
314 ObClient
*parent
= NULL
;
315 GList
*it_before
= NULL
;
317 if (!WINDOW_IS_CLIENT(win
)) {
318 stacking_add(win
); /* no special rules for others */
322 client
= WINDOW_AS_CLIENT(win
);
324 /* insert above its highest parent */
325 if (client
->transient_for
) {
326 if (client
->transient_for
!= OB_TRAN_GROUP
) {
327 parent
= client
->transient_for
;
333 for (it
= stacking_list
; !parent
&& it
; it
= it
->next
) {
334 if ((sit
= g_slist_find(client
->group
->members
, it
->data
)))
335 for (sit
= client
->group
->members
; !parent
&& sit
;
337 ObClient
*c
= sit
->data
;
338 /* checking transient_for prevents infinate loops! */
339 if (sit
->data
== it
->data
&& !c
->transient_for
)
346 if (!(it_before
= g_list_find(stacking_list
, parent
))) {
347 /* no parent to put above, try find the focused client to go
349 if (focus_client
&& focus_client
->layer
== client
->layer
) {
350 if ((it_before
= g_list_find(stacking_list
, focus_client
)))
351 it_before
= it_before
->next
;
355 /* out of ideas, just add it normally... */
358 GList
*wins
= g_list_append(NULL
, win
);
359 do_restack(wins
, it_before
);
This page took 0.048795 seconds and 4 git commands to generate.