+void stacking_add(ObWindow *win)
+{
+ StackLayer l;
+ GList *wins, *it;
+
+ l = window_layer(win);
+ wins = g_list_append(NULL, win); /* list of 1 element */
+
+ for (it = stacking_list; it; it = g_list_next(it))
+ if (window_layer(it->data) <= l)
+ break;
+ do_restack(wins, it);
+ g_list_free(wins);
+
+ stacking_raise(win);
+}
+
+void stacking_add_nonintrusive(ObWindow *win)
+{
+ Client *client;
+ Client *parent = NULL;
+ GList *it_before = NULL;
+
+ if (!WINDOW_IS_CLIENT(win)) {
+ stacking_add(win); /* no special rules for others */
+ return;
+ }
+
+ client = WINDOW_AS_CLIENT(win);
+
+ /* insert above its highest parent */
+ if (client->transient_for) {
+ if (client->transient_for != TRAN_GROUP) {
+ parent = client->transient_for;
+ } else {
+ GSList *sit;
+ GList *it;
+
+ if (client->group)
+ for (it = stacking_list; !parent && it; it = it->next) {
+ if ((sit = g_slist_find(client->group->members, it->data)))
+ for (sit = client->group->members; !parent && sit;
+ sit = sit->next) {
+ Client *c = sit->data;
+ /* checking transient_for prevents infinate loops! */
+ if (sit->data == it->data && !c->transient_for)
+ parent = it->data;
+ }
+ }
+ }
+ }
+
+ if (!(it_before = g_list_find(stacking_list, parent))) {
+ /* no parent to put above, try find the focused client to go
+ under */
+ if (focus_client && focus_client->layer == client->layer) {
+ if ((it_before = g_list_find(stacking_list, focus_client)))
+ it_before = it_before->next;
+ }
+ }
+ if (!it_before) {
+ /* out of ideas, just add it normally... */
+ stacking_add(win);
+ } else {
+ GList *wins = g_list_append(NULL, win);
+ do_restack(wins, it_before);
+ g_list_free(wins);
+ }
+}