]>
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) 2003 Ben Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
28 GList
*stacking_list
= NULL
;
30 void stacking_set_list()
32 Window
*windows
= NULL
;
36 /* on shutdown, don't update the properties, so that we can read it back
37 in on startup and re-stack the windows as they were before we shut down
39 if (ob_state() == OB_STATE_EXITING
) return;
41 /* create an array of the window ids (from bottom to top,
44 windows
= g_new(Window
, g_list_length(stacking_list
));
45 for (it
= g_list_last(stacking_list
); it
; it
= g_list_previous(it
)) {
46 if (WINDOW_IS_CLIENT(it
->data
))
47 windows
[i
++] = WINDOW_AS_CLIENT(it
->data
)->window
;
51 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
52 net_client_list_stacking
, window
, (gulong
*)windows
, i
);
57 static void do_restack(GList
*wins
, GList
*before
)
64 /* pls only restack stuff in the same layer at a time */
65 for (it
= wins
; it
; it
= next
) {
66 next
= g_list_next(it
);
68 g_assert (window_layer(it
->data
) == window_layer(next
->data
));
71 g_assert(window_layer(it
->data
) >= window_layer(before
->data
));
74 win
= g_new(Window
, g_list_length(wins
) + 1);
76 if (before
== stacking_list
)
77 win
[0] = screen_support_win
;
79 win
[0] = window_top(g_list_last(stacking_list
)->data
);
81 win
[0] = window_top(g_list_previous(before
)->data
);
83 for (i
= 1, it
= wins
; it
; ++i
, it
= g_list_next(it
)) {
84 win
[i
] = window_top(it
->data
);
85 g_assert(win
[i
] != None
); /* better not call stacking shit before
86 setting your top level window value */
87 stacking_list
= g_list_insert_before(stacking_list
, before
, it
->data
);
91 /* some debug checking of the stacking list's order */
92 for (it
= stacking_list
; ; it
= next
) {
93 next
= g_list_next(it
);
95 g_assert(window_layer(it
->data
) >= window_layer(next
->data
));
99 XRestackWindows(ob_display
, win
, i
);
105 static void do_raise(GList
*wins
)
108 GList
*layer
[OB_NUM_STACKING_LAYERS
] = {NULL
};
111 for (it
= wins
; it
; it
= g_list_next(it
)) {
114 l
= window_layer(it
->data
);
115 layer
[l
] = g_list_append(layer
[l
], it
->data
);
119 for (i
= OB_NUM_STACKING_LAYERS
- 1; i
>= 0; --i
) {
121 for (; it
; it
= g_list_next(it
)) {
122 /* look for the top of the layer */
123 if (window_layer(it
->data
) <= (ObStackingLayer
) i
)
126 do_restack(layer
[i
], it
);
127 g_list_free(layer
[i
]);
132 static void do_lower(GList
*wins
)
135 GList
*layer
[OB_NUM_STACKING_LAYERS
] = {NULL
};
138 for (it
= wins
; it
; it
= g_list_next(it
)) {
141 l
= window_layer(it
->data
);
142 layer
[l
] = g_list_append(layer
[l
], it
->data
);
146 for (i
= OB_NUM_STACKING_LAYERS
- 1; i
>= 0; --i
) {
148 for (; it
; it
= g_list_next(it
)) {
149 /* look for the top of the next layer down */
150 if (window_layer(it
->data
) < (ObStackingLayer
) i
)
153 do_restack(layer
[i
], it
);
154 g_list_free(layer
[i
]);
159 static GList
*pick_windows(ObClient
*top
, ObClient
*selected
, gboolean raise
)
162 GList
*it
, *next
, *prev
;
165 GList
*modals
= NULL
;
167 GList
*modal_sel
= NULL
; /* the selected guys if modal */
168 GList
*trans_sel
= NULL
; /* the selected guys if not */
170 /* remove first so we can't run into ourself */
171 if ((it
= g_list_find(stacking_list
, top
)))
172 stacking_list
= g_list_delete_link(stacking_list
, it
);
177 n
= g_slist_length(top
->transients
);
178 for (it
= stacking_list
; i
< n
&& it
; it
= next
) {
179 prev
= g_list_previous(it
);
180 next
= g_list_next(it
);
182 if ((sit
= g_slist_find(top
->transients
, it
->data
))) {
183 ObClient
*c
= sit
->data
;
191 sel_child
= client_search_transient(c
, selected
) != NULL
;
195 trans
= g_list_concat(trans
,
196 pick_windows(c
, selected
, raise
));
198 trans_sel
= g_list_concat(trans_sel
,
199 pick_windows(c
, selected
,
204 modals
= g_list_concat(modals
,
205 pick_windows(c
, selected
, raise
));
207 modal_sel
= g_list_concat(modal_sel
,
208 pick_windows(c
, selected
,
212 /* if we dont have a prev then start back at the beginning,
213 otherwise skip back to the prev's next */
214 next
= prev
? g_list_next(prev
) : stacking_list
;
218 ret
= g_list_concat((raise
? modal_sel
: modals
),
219 (raise
? modals
: modal_sel
));
221 ret
= g_list_concat(ret
, (raise
? trans_sel
: trans
));
222 ret
= g_list_concat(ret
, (raise
? trans
: trans_sel
));
226 ret
= g_list_append(ret
, top
);
231 static GList
*pick_group_windows(ObClient
*top
, ObClient
*selected
,
232 gboolean raise
, gboolean normal
)
235 GList
*it
, *next
, *prev
;
239 /* add group members in their stacking order */
242 n
= g_slist_length(top
->group
->members
) - 1;
243 for (it
= stacking_list
; i
< n
&& it
; it
= next
) {
244 prev
= g_list_previous(it
);
245 next
= g_list_next(it
);
247 if ((sit
= g_slist_find(top
->group
->members
, it
->data
))) {
255 if ((c
->desktop
== selected
->desktop
||
256 c
->desktop
== DESKTOP_ALL
) &&
257 (t
== OB_CLIENT_TYPE_TOOLBAR
||
258 t
== OB_CLIENT_TYPE_MENU
||
259 t
== OB_CLIENT_TYPE_UTILITY
||
260 (normal
&& t
== OB_CLIENT_TYPE_NORMAL
)))
262 ret
= g_list_concat(ret
,
263 pick_windows(sit
->data
,
265 /* if we dont have a prev then start back at the beginning,
266 otherwise skip back to the prev's next */
267 next
= prev
? g_list_next(prev
) : stacking_list
;
275 void stacking_raise(ObWindow
*window
, gboolean group
)
279 if (WINDOW_IS_CLIENT(window
)) {
282 selected
= WINDOW_AS_CLIENT(window
);
283 c
= client_search_top_transient(selected
);
284 wins
= pick_windows(c
, selected
, TRUE
);
285 wins
= g_list_concat(wins
, pick_group_windows(c
, selected
, TRUE
, group
));
287 wins
= g_list_append(NULL
, window
);
288 stacking_list
= g_list_remove(stacking_list
, window
);
294 void stacking_lower(ObWindow
*window
, gboolean group
)
298 if (WINDOW_IS_CLIENT(window
)) {
301 selected
= WINDOW_AS_CLIENT(window
);
302 c
= client_search_top_transient(selected
);
303 wins
= pick_windows(c
, selected
, FALSE
);
304 wins
= g_list_concat(pick_group_windows(c
, selected
, FALSE
, group
), wins
);
306 wins
= g_list_append(NULL
, window
);
307 stacking_list
= g_list_remove(stacking_list
, window
);
313 void stacking_below(ObWindow
*window
, ObWindow
*below
)
315 GList
*wins
, *before
;
317 if (window_layer(window
) != window_layer(below
))
320 wins
= g_list_append(NULL
, window
);
321 stacking_list
= g_list_remove(stacking_list
, window
);
322 before
= g_list_next(g_list_find(stacking_list
, below
));
323 do_restack(wins
, before
);
327 void stacking_add(ObWindow
*win
)
332 g_assert(screen_support_win
!= None
); /* make sure I dont break this in the
335 l
= window_layer(win
);
336 wins
= g_list_append(NULL
, win
); /* list of 1 element */
338 stacking_list
= g_list_append(stacking_list
, win
);
339 stacking_raise(win
, FALSE
);
342 void stacking_add_nonintrusive(ObWindow
*win
)
345 ObClient
*parent
= NULL
;
346 GList
*it_before
= NULL
;
348 if (!WINDOW_IS_CLIENT(win
)) {
349 stacking_add(win
); /* no special rules for others */
353 client
= WINDOW_AS_CLIENT(win
);
355 /* insert above its highest parent */
356 if (client
->transient_for
) {
357 if (client
->transient_for
!= OB_TRAN_GROUP
) {
358 parent
= client
->transient_for
;
364 for (it
= stacking_list
; !parent
&& it
; it
= g_list_next(it
)) {
365 if ((sit
= g_slist_find(client
->group
->members
, it
->data
)))
366 for (sit
= client
->group
->members
; !parent
&& sit
;
367 sit
= g_slist_next(sit
))
369 ObClient
*c
= sit
->data
;
370 /* checking transient_for prevents infinate loops! */
371 if (sit
->data
== it
->data
&& !c
->transient_for
)
378 if (!(it_before
= g_list_find(stacking_list
, parent
))) {
379 /* no parent to put above, try find the focused client to go
381 if (focus_client
&& focus_client
->layer
== client
->layer
) {
382 if ((it_before
= g_list_find(stacking_list
, focus_client
)))
383 it_before
= it_before
->next
;
387 /* out of ideas, just add it normally... */
390 GList
*wins
= g_list_append(NULL
, win
);
391 do_restack(wins
, it_before
);
This page took 0.056572 seconds and 4 git commands to generate.