- it = g_list_last(stacking_list);
-
- if (client->modal && client->transient_for) {
- /* don't let a modal window lower below its transient_for */
- it = g_list_find(stacking_list, client->transient_for);
- g_assert(it != NULL);
-
- wins[0] = (it == stacking_list ? focus_backup :
- ((Client*)it->prev->data)->frame->window);
- wins[1] = client->frame->window;
- if (wins[0] == wins[1]) return; /* already right above the window */
-
- stacking_list = g_list_remove(stacking_list, client);
- stacking_list = g_list_insert_before(stacking_list, it, client);
- } else {
- while (it != stacking_list) {
- Client *c = it->data;
- if (client->layer >= c->layer)
- break;
- it = it->prev;
- }
- if (it->data == client) return; /* already the bottom, return */
-
- wins[0] = ((Client*)it->data)->frame->window;
- wins[1] = client->frame->window;
-
- stacking_list = g_list_remove(stacking_list, client);
- stacking_list = g_list_insert_before(stacking_list,
- it->next, client);
+ /* move up the transient chain as far as possible first */
+ while (client->transient_for) {
+ if (client->transient_for != TRAN_GROUP) {
+ client = client->transient_for;
+ } 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) {
+ client = it->data;
+ break;
+ }
+ }
+ if (it == NULL) break;
+ }