- g_assert(stacking_list != NULL); /* this would be bad */
-
- if (WINDOW_IS_CLIENT(window)) {
- Client *client = WINDOW_AS_CLIENT(window);
- /* move up the transient chain as far as possible first */
- while (client->transient_for) {
- if (client->transient_for != TRAN_GROUP) {
- stacking_lower(CLIENT_AS_WINDOW(client->transient_for));
- return;
- } else {
- GSList *it;
-
- /* the check for TRAN_GROUP is to prevent an infinate loop with
- 2 transients of the same group at the head of the group's
- members list */
- for (it = client->group->members; it; it = it->next) {
- Client *c = it->data;
-
- if (c != client && c->transient_for != TRAN_GROUP)
- stacking_lower(it->data);
- }
- if (it == NULL) return;
+ GList *ret = NULL;
+ GList *it, *next;
+ GSList *sit;
+ Client *c;
+ int i, n;
+
+ if (!WINDOW_IS_CLIENT(win)) {
+ ret = g_list_append(ret, win);
+ stacking_list = g_list_remove(stacking_list, win);
+ return ret;
+ }
+ c = WINDOW_AS_CLIENT(win);
+
+ /* add transient children in their stacking order */
+ i = 0;
+ n = g_slist_length(c->transients);
+ for (it = stacking_list; i < n && it; it = next) {
+ next = g_list_next(it);
+ if ((sit = g_slist_find(c->transients, it->data))) {
+ ++i;
+ ret = g_list_concat(ret, pick_windows(sit->data));
+ }
+ }
+
+ /* add itself */
+ if (g_list_find(stacking_list, win)) {
+ ret = g_list_append(ret, win);
+ stacking_list = g_list_remove(stacking_list, win);
+ }
+
+ /* add group members in their stacking order */
+ if (c->group) {
+ for (it = stacking_list; it; it = next) {
+ next = g_list_next(it);
+ if ((sit = g_slist_find(c->group->members, it->data))) {
+ ret = g_list_append(ret, sit->data);
+ stacking_list = g_list_remove(stacking_list, sit->data);