]>
Dogcows Code - chaz/openbox/blob - openbox/stacking.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 stacking.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003 Ben Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
29 GList
*stacking_list
= NULL
;
31 void stacking_set_list()
33 Window
*windows
= NULL
;
37 /* on shutdown, don't update the properties, so that we can read it back
38 in on startup and re-stack the windows as they were before we shut down
40 if (ob_state() == OB_STATE_EXITING
) return;
42 /* create an array of the window ids (from bottom to top,
45 windows
= g_new(Window
, g_list_length(stacking_list
));
46 for (it
= g_list_last(stacking_list
); it
; it
= g_list_previous(it
)) {
47 if (WINDOW_IS_CLIENT(it
->data
))
48 windows
[i
++] = WINDOW_AS_CLIENT(it
->data
)->window
;
52 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
53 net_client_list_stacking
, window
, (gulong
*)windows
, i
);
58 static void do_restack(GList
*wins
, GList
*before
)
66 /* pls only restack stuff in the same layer at a time */
67 for (it
= wins
; it
; it
= next
) {
68 next
= g_list_next(it
);
70 g_assert (window_layer(it
->data
) == window_layer(next
->data
));
73 g_assert(window_layer(it
->data
) >= window_layer(before
->data
));
76 win
= g_new(Window
, g_list_length(wins
) + 1);
78 if (before
== stacking_list
)
79 win
[0] = screen_support_win
;
81 win
[0] = window_top(g_list_last(stacking_list
)->data
);
83 win
[0] = window_top(g_list_previous(before
)->data
);
85 for (i
= 1, it
= wins
; it
; ++i
, it
= g_list_next(it
)) {
86 win
[i
] = window_top(it
->data
);
87 g_assert(win
[i
] != None
); /* better not call stacking shit before
88 setting your top level window value */
89 stacking_list
= g_list_insert_before(stacking_list
, before
, it
->data
);
93 /* some debug checking of the stacking list's order */
94 for (it
= stacking_list
; ; it
= next
) {
95 next
= g_list_next(it
);
97 g_assert(window_layer(it
->data
) >= window_layer(next
->data
));
101 XRestackWindows(ob_display
, win
, i
);
107 static void do_raise(GList
*wins
)
110 GList
*layer
[OB_NUM_STACKING_LAYERS
] = {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
= OB_NUM_STACKING_LAYERS
- 1; i
>= 0; --i
) {
123 for (; it
; it
= g_list_next(it
)) {
124 /* look for the top of the layer */
125 if (window_layer(it
->data
) <= (ObStackingLayer
) i
)
128 do_restack(layer
[i
], it
);
129 g_list_free(layer
[i
]);
134 static void do_lower(GList
*wins
)
137 GList
*layer
[OB_NUM_STACKING_LAYERS
] = {NULL
};
140 for (it
= wins
; it
; it
= g_list_next(it
)) {
143 l
= window_layer(it
->data
);
144 layer
[l
] = g_list_append(layer
[l
], it
->data
);
148 for (i
= OB_NUM_STACKING_LAYERS
- 1; i
>= 0; --i
) {
150 for (; it
; it
= g_list_next(it
)) {
151 /* look for the top of the next layer down */
152 if (window_layer(it
->data
) < (ObStackingLayer
) i
)
155 do_restack(layer
[i
], it
);
156 g_list_free(layer
[i
]);
161 static GList
*pick_windows(ObClient
*top
, ObClient
*selected
, gboolean raise
)
164 GList
*it
, *next
, *prev
;
167 GList
*modals
= NULL
;
169 GList
*modal_sel
= NULL
; /* the selected guys if modal */
170 GList
*trans_sel
= NULL
; /* the selected guys if not */
172 /* remove first so we can't run into ourself */
173 if ((it
= g_list_find(stacking_list
, top
)))
174 stacking_list
= g_list_delete_link(stacking_list
, it
);
179 n
= g_slist_length(top
->transients
);
180 for (it
= stacking_list
; i
< n
&& it
; it
= next
) {
181 prev
= g_list_previous(it
);
182 next
= g_list_next(it
);
184 if ((sit
= g_slist_find(top
->transients
, it
->data
))) {
185 ObClient
*c
= sit
->data
;
193 sel_child
= client_search_transient(c
, selected
) != NULL
;
197 trans
= g_list_concat(trans
,
198 pick_windows(c
, selected
, raise
));
200 trans_sel
= g_list_concat(trans_sel
,
201 pick_windows(c
, selected
,
206 modals
= g_list_concat(modals
,
207 pick_windows(c
, selected
, raise
));
209 modal_sel
= g_list_concat(modal_sel
,
210 pick_windows(c
, selected
,
214 /* if we dont have a prev then start back at the beginning,
215 otherwise skip back to the prev's next */
216 next
= prev
? g_list_next(prev
) : stacking_list
;
220 ret
= g_list_concat((raise
? modal_sel
: modals
),
221 (raise
? modals
: modal_sel
));
223 ret
= g_list_concat(ret
, (raise
? trans_sel
: trans
));
224 ret
= g_list_concat(ret
, (raise
? trans
: trans_sel
));
228 ret
= g_list_append(ret
, top
);
233 static GList
*pick_group_windows(ObClient
*top
, ObClient
*selected
,
234 gboolean raise
, gboolean normal
)
237 GList
*it
, *next
, *prev
;
241 /* add group members in their stacking order */
244 n
= g_slist_length(top
->group
->members
) - 1;
245 for (it
= stacking_list
; i
< n
&& it
; it
= next
) {
246 prev
= g_list_previous(it
);
247 next
= g_list_next(it
);
249 if ((sit
= g_slist_find(top
->group
->members
, it
->data
))) {
257 if ((c
->desktop
== selected
->desktop
||
258 c
->desktop
== DESKTOP_ALL
) &&
259 (t
== OB_CLIENT_TYPE_TOOLBAR
||
260 t
== OB_CLIENT_TYPE_MENU
||
261 t
== OB_CLIENT_TYPE_UTILITY
||
262 (normal
&& t
== OB_CLIENT_TYPE_NORMAL
)))
264 ret
= g_list_concat(ret
,
265 pick_windows(sit
->data
,
267 /* if we dont have a prev then start back at the beginning,
268 otherwise skip back to the prev's next */
269 next
= prev
? g_list_next(prev
) : stacking_list
;
277 void stacking_raise(ObWindow
*window
, gboolean group
)
281 if (WINDOW_IS_CLIENT(window
)) {
284 selected
= WINDOW_AS_CLIENT(window
);
285 c
= client_search_top_transient(selected
);
286 wins
= pick_windows(c
, selected
, TRUE
);
287 wins
= g_list_concat(wins
,
288 pick_group_windows(c
, selected
, TRUE
, group
));
290 wins
= g_list_append(NULL
, window
);
291 stacking_list
= g_list_remove(stacking_list
, window
);
297 void stacking_lower(ObWindow
*window
, gboolean group
)
301 if (WINDOW_IS_CLIENT(window
)) {
304 selected
= WINDOW_AS_CLIENT(window
);
305 c
= client_search_top_transient(selected
);
306 wins
= pick_windows(c
, selected
, FALSE
);
307 wins
= g_list_concat(pick_group_windows(c
, selected
, FALSE
, group
),
310 wins
= g_list_append(NULL
, window
);
311 stacking_list
= g_list_remove(stacking_list
, window
);
317 void stacking_below(ObWindow
*window
, ObWindow
*below
)
319 GList
*wins
, *before
;
321 if (window_layer(window
) != window_layer(below
))
324 wins
= g_list_append(NULL
, window
);
325 stacking_list
= g_list_remove(stacking_list
, window
);
326 before
= g_list_next(g_list_find(stacking_list
, below
));
327 do_restack(wins
, before
);
331 void stacking_add(ObWindow
*win
)
333 g_assert(screen_support_win
!= None
); /* make sure I dont break this in the
336 stacking_list
= g_list_append(stacking_list
, win
);
337 stacking_raise(win
, FALSE
);
340 void stacking_add_nonintrusive(ObWindow
*win
)
343 ObClient
*parent
= NULL
;
344 GList
*it_before
= NULL
;
346 if (!WINDOW_IS_CLIENT(win
)) {
347 stacking_add(win
); /* no special rules for others */
351 client
= WINDOW_AS_CLIENT(win
);
353 /* insert above its highest parent */
354 if (client
->transient_for
) {
355 if (client
->transient_for
!= OB_TRAN_GROUP
) {
356 parent
= client
->transient_for
;
362 for (it
= stacking_list
; !parent
&& it
; it
= g_list_next(it
)) {
363 if ((sit
= g_slist_find(client
->group
->members
, it
->data
)))
364 for (sit
= client
->group
->members
; !parent
&& sit
;
365 sit
= g_slist_next(sit
))
367 ObClient
*c
= sit
->data
;
368 /* checking transient_for prevents infinate loops! */
369 if (sit
->data
== it
->data
&& !c
->transient_for
)
376 if (!(it_before
= g_list_find(stacking_list
, parent
))) {
377 /* no parent to put above, try find the focused client to go
379 if (focus_client
&& focus_client
->layer
== client
->layer
) {
380 if ((it_before
= g_list_find(stacking_list
, focus_client
)))
381 it_before
= it_before
->next
;
385 /* out of ideas, just add it normally... */
388 GList
*wins
= g_list_append(NULL
, win
);
389 do_restack(wins
, it_before
);
This page took 0.052713 seconds and 4 git commands to generate.