+ if (!WINDOW_IS_CLIENT(window))
+ return window;
+
+ client = WINDOW_AS_CLIENT(window);
+
+ /* move up the transient chain as far as possible */
+ if (client->transient_for) {
+ if (client->transient_for != TRAN_GROUP) {
+ return top_transient(CLIENT_AS_WINDOW(client->transient_for));
+ } else {
+ GSList *it;
+
+ for (it = client->group->members; it; it = it->next) {
+ Client *c = it->data;
+
+ /* checking transient_for prevents infinate loops! */
+ if (c != client && !c->transient_for)
+ break;
+ }
+ if (it)
+ return it->data;
+ }
+ }
+
+ return window;