9 GList
*stacking_list
= NULL
;
11 static Window top_window
= None
;
13 void stacking_startup()
15 XSetWindowAttributes attrib
;
16 attrib
.override_redirect
= TRUE
;
17 top_window
= XCreateWindow(ob_display
, ob_root
,
19 CopyFromParent
, InputOutput
, CopyFromParent
,
20 CWOverrideRedirect
, &attrib
);
21 XMapWindow(ob_display
, top_window
);
24 void stacking_shutdown()
26 XDestroyWindow(ob_display
, top_window
);
29 void stacking_set_list()
31 Window
*windows
, *win_it
;
33 guint size
= g_list_length(stacking_list
);
35 /* on shutdown, don't update the properties, so that we can read it back
36 in on startup and re-stack the windows as they were before we shut down
38 if (ob_state
== State_Exiting
) return;
40 /* create an array of the window ids (from bottom to top,
43 windows
= g_new(Window
, size
);
45 for (it
= g_list_last(stacking_list
); it
!= NULL
;
46 it
= it
->prev
, ++win_it
)
47 *win_it
= ((Client
*)it
->data
)->window
;
51 PROP_SETA32(ob_root
, net_client_list_stacking
, window
,
52 (guint32
*)windows
, size
);
58 static GList
*find_lowest_transient(Client
*c
)
63 for (it
= g_list_last(stacking_list
); it
; it
= it
->prev
)
64 for (sit
= c
->transients
; sit
; sit
= sit
->next
)
65 if (it
->data
== sit
->data
) /* found a transient */
70 static void raise_recursive(Client
*client
)
72 Window wins
[2]; /* only ever restack 2 windows. */
76 g_assert(stacking_list
!= NULL
); /* this would be bad */
78 /* remove the client before looking so we can't run into ourselves and our
79 transients can't either. */
80 stacking_list
= g_list_remove(stacking_list
, client
);
82 /* raise transients first */
83 for (sit
= client
->transients
; sit
; sit
= sit
->next
)
84 raise_recursive(sit
->data
);
86 /* find 'it' where it is the positiion in the stacking order where
87 'client' will be inserted *before* */
89 it
= find_lowest_transient(client
);
93 /* the stacking list is from highest to lowest */
94 for (it
= stacking_list
; it
; it
= it
->next
) {
95 if (client
->layer
>= ((Client
*)it
->data
)->layer
)
101 if our new position is the top, we want to stack under the focus_backup.
102 otherwise, we want to stack under the previous window in the stack.
104 if (it
== stacking_list
)
105 wins
[0] = focus_backup
;
107 wins
[0] = ((Client
*)it
->prev
->data
)->frame
->window
;
109 wins
[0] = ((Client
*)g_list_last(stacking_list
)->data
)->frame
->window
;
110 wins
[1] = client
->frame
->window
;
112 stacking_list
= g_list_insert_before(stacking_list
, it
, client
);
114 XRestackWindows(ob_display
, wins
, 2);
117 void stacking_raise(Client
*client
)
119 g_assert(stacking_list
!= NULL
); /* this would be bad */
121 /* move up the transient chain as far as possible first */
122 while (client
->transient_for
) {
123 if (client
->transient_for
!= TRAN_GROUP
) {
124 client
= client
->transient_for
;
128 /* the check for TRAN_GROUP is to prevent an infinate loop with
129 2 transients of the same group at the head of the group's
131 for (it
= client
->group
->members
; it
; it
= it
->next
) {
132 Client
*c
= it
->data
;
134 if (c
!= client
&& c
->transient_for
!= TRAN_GROUP
) {
139 if (it
== NULL
) break;
143 raise_recursive(client
);
148 static void lower_recursive(Client
*client
, Client
*above
)
150 Window wins
[2]; /* only ever restack 2 windows. */
154 /* find 'it' where 'it' is the position in the stacking_list where the
155 'client' will be placed *after* */
157 for (it
= g_list_last(stacking_list
); it
!= stacking_list
; it
= it
->prev
)
158 if (client
->layer
<= ((Client
*)it
->data
)->layer
&& it
->data
!= above
)
161 if (it
->data
!= client
) { /* not already the bottom */
162 wins
[0] = ((Client
*)it
->data
)->frame
->window
;
163 wins
[1] = client
->frame
->window
;
165 stacking_list
= g_list_remove(stacking_list
, client
);
166 stacking_list
= g_list_insert_before(stacking_list
, it
->next
, client
);
167 XRestackWindows(ob_display
, wins
, 2);
170 for (sit
= client
->transients
; sit
; sit
= sit
->next
)
171 lower_recursive(sit
->data
, client
);
174 void stacking_lower(Client
*client
)
176 g_assert(stacking_list
!= NULL
); /* this would be bad */
178 /* move up the transient chain as far as possible first */
179 while (client
->transient_for
) {
180 if (client
->transient_for
!= TRAN_GROUP
) {
181 client
= client
->transient_for
;
185 /* the check for TRAN_GROUP is to prevent an infinate loop with
186 2 transients of the same group at the head of the group's
188 for (it
= client
->group
->members
; it
; it
= it
->next
) {
189 Client
*c
= it
->data
;
191 if (c
!= client
&& c
->transient_for
!= TRAN_GROUP
) {
196 if (it
== NULL
) break;
200 lower_recursive(client
, NULL
);
205 void stacking_raise_internal(Window win
)
207 Window wins
[2]; /* only ever restack 2 windows. */
209 wins
[0] = top_window
;
212 XRestackWindows(ob_display
, wins
, 2);