]>
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
)
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] = screen_support_win
;
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
[OB_NUM_STACKING_LAYERS
] = {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
= OB_NUM_STACKING_LAYERS
- 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
) <= (ObStackingLayer
) i
)
103 do_restack(layer
[i
], it
);
104 g_list_free(layer
[i
]);
109 static void do_lower(GList
*wins
)
112 GList
*layer
[OB_NUM_STACKING_LAYERS
] = {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
= OB_NUM_STACKING_LAYERS
- 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
) < (ObStackingLayer
) 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
= NULL
; /* the selected guys if modal */
145 GList
*trans_sel
= NULL
; /* the selected guys if not */
147 /* remove first so we can't run into ourself */
148 if ((it
= g_list_find(stacking_list
, top
)))
149 stacking_list
= g_list_delete_link(stacking_list
, it
);
154 n
= g_slist_length(top
->transients
);
155 for (it
= stacking_list
; i
< n
&& it
; it
= next
) {
156 prev
= g_list_previous(it
);
157 next
= g_list_next(it
);
159 if ((sit
= g_slist_find(top
->transients
, it
->data
))) {
160 ObClient
*c
= sit
->data
;
168 sel_child
= client_search_transient(c
, selected
) != NULL
;
172 trans
= g_list_concat(trans
,
173 pick_windows(c
, selected
, raise
));
175 trans_sel
= g_list_concat(trans_sel
,
176 pick_windows(c
, selected
,
181 modals
= g_list_concat(modals
,
182 pick_windows(c
, selected
, raise
));
184 modal_sel
= g_list_concat(modal_sel
,
185 pick_windows(c
, selected
,
189 /* if we dont have a prev then start back at the beginning,
190 otherwise skip back to the prev's next */
191 next
= prev
? g_list_next(prev
) : stacking_list
;
195 ret
= g_list_concat((raise
? modal_sel
: modals
),
196 (raise
? modals
: modal_sel
));
198 ret
= g_list_concat(ret
, (raise
? trans_sel
: trans
));
199 ret
= g_list_concat(ret
, (raise
? trans
: trans_sel
));
203 ret
= g_list_append(ret
, top
);
208 static GList
*pick_group_windows(ObClient
*top
, ObClient
*selected
, gboolean raise
)
211 GList
*it
, *next
, *prev
;
215 /* add group members in their stacking order */
218 n
= g_slist_length(top
->group
->members
) - 1;
219 for (it
= stacking_list
; i
< n
&& it
; it
= next
) {
220 prev
= g_list_previous(it
);
221 next
= g_list_next(it
);
223 if ((sit
= g_slist_find(top
->group
->members
, it
->data
))) {
225 ret
= g_list_concat(ret
,
226 pick_windows(sit
->data
, selected
, raise
));
227 /* if we dont have a prev then start back at the beginning,
228 otherwise skip back to the prev's next */
229 next
= prev
? g_list_next(prev
) : stacking_list
;
236 void stacking_raise(ObWindow
*window
)
240 if (WINDOW_IS_CLIENT(window
)) {
243 selected
= WINDOW_AS_CLIENT(window
);
244 c
= client_search_top_transient(selected
);
245 wins
= pick_windows(c
, selected
, TRUE
);
246 /*wins = g_list_concat(wins, pick_group_windows(c, selected, TRUE));*/
248 wins
= g_list_append(NULL
, window
);
249 stacking_list
= g_list_remove(stacking_list
, window
);
255 void stacking_lower(ObWindow
*window
)
259 if (WINDOW_IS_CLIENT(window
)) {
262 selected
= WINDOW_AS_CLIENT(window
);
263 c
= client_search_top_transient(selected
);
264 wins
= pick_windows(c
, selected
, FALSE
);
265 /*wins = g_list_concat(pick_group_windows(c, selected, FALSE), wins);*/
267 wins
= g_list_append(NULL
, window
);
268 stacking_list
= g_list_remove(stacking_list
, window
);
274 void stacking_add(ObWindow
*win
)
279 g_assert(screen_support_win
!= None
); /* make sure I dont break this in the
282 l
= window_layer(win
);
283 wins
= g_list_append(NULL
, win
); /* list of 1 element */
285 stacking_list
= g_list_append(stacking_list
, win
);
289 void stacking_add_nonintrusive(ObWindow
*win
)
292 ObClient
*parent
= NULL
;
293 GList
*it_before
= NULL
;
295 if (!WINDOW_IS_CLIENT(win
)) {
296 stacking_add(win
); /* no special rules for others */
300 client
= WINDOW_AS_CLIENT(win
);
302 /* insert above its highest parent */
303 if (client
->transient_for
) {
304 if (client
->transient_for
!= OB_TRAN_GROUP
) {
305 parent
= client
->transient_for
;
311 for (it
= stacking_list
; !parent
&& it
; it
= it
->next
) {
312 if ((sit
= g_slist_find(client
->group
->members
, it
->data
)))
313 for (sit
= client
->group
->members
; !parent
&& sit
;
315 ObClient
*c
= sit
->data
;
316 /* checking transient_for prevents infinate loops! */
317 if (sit
->data
== it
->data
&& !c
->transient_for
)
324 if (!(it_before
= g_list_find(stacking_list
, parent
))) {
325 /* no parent to put above, try find the focused client to go
327 if (focus_client
&& focus_client
->layer
== client
->layer
) {
328 if ((it_before
= g_list_find(stacking_list
, focus_client
)))
329 it_before
= it_before
->next
;
333 /* out of ideas, just add it normally... */
336 GList
*wins
= g_list_append(NULL
, win
);
337 do_restack(wins
, it_before
);
This page took 0.054307 seconds and 4 git commands to generate.