+void stacking_raise(ObWindow *window)
+{
+ if (WINDOW_IS_CLIENT(window)) {
+ ObClient *selected;
+ selected = WINDOW_AS_CLIENT(window);
+ restack_windows(selected, TRUE);
+ } else {
+ GList *wins;
+ wins = g_list_append(NULL, window);
+ stacking_list = g_list_remove(stacking_list, window);
+ do_raise(wins);
+ g_list_free(wins);
+ }
+}
+
+void stacking_lower(ObWindow *window)
+{
+ if (WINDOW_IS_CLIENT(window)) {
+ ObClient *selected;
+ selected = WINDOW_AS_CLIENT(window);
+ restack_windows(selected, FALSE);
+ } else {
+ GList *wins;
+ wins = g_list_append(NULL, window);
+ stacking_list = g_list_remove(stacking_list, window);
+ do_lower(wins);
+ g_list_free(wins);
+ }
+}
+
+void stacking_below(ObWindow *window, ObWindow *below)
+{
+ GList *wins, *before;
+
+ if (window_layer(window) != window_layer(below))
+ return;
+
+ wins = g_list_append(NULL, window);
+ stacking_list = g_list_remove(stacking_list, window);
+ before = g_list_next(g_list_find(stacking_list, below));
+ do_restack(wins, before);
+ g_list_free(wins);
+}
+
+void stacking_add(ObWindow *win)
+{
+ g_assert(screen_support_win != None); /* make sure I dont break this in the
+ future */
+
+ stacking_list = g_list_append(stacking_list, win);
+ stacking_raise(win);
+}
+
+void stacking_add_nonintrusive(ObWindow *win)
+{
+ ObClient *client;
+ ObClient *parent = NULL;
+ GList *it_below = 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 != OB_TRAN_GROUP) {
+ parent = client->transient_for;
+ } else {
+ GSList *sit;
+ GList *it;
+
+ if (client->group)
+ for (it = stacking_list; !parent && it; it = g_list_next(it)) {
+ if ((sit = g_slist_find(client->group->members, it->data)))
+ for (sit = client->group->members; !parent && sit;
+ sit = g_slist_next(sit))
+ {
+ ObClient *c = sit->data;
+ /* checking transient_for prevents infinate loops! */
+ if (sit->data == it->data && !c->transient_for)
+ parent = it->data;
+ }
+ }
+ }
+ }
+
+ if (!(it_below = 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_below = g_list_find(stacking_list, focus_client)))
+ it_below = it_below->next;
+ }
+ }
+ if (!it_below) {
+ /* out of ideas, just add it normally... */
+ stacking_add(win);
+ } else {
+ /* make sure it's not in the wrong layer though ! */
+ for (; it_below; it_below = g_list_next(it_below))
+ {
+ /* stop when the window is not in a higher layer than the window
+ it is going above (it_below) */
+ if (client->layer >= window_layer(it_below->data))
+ break;
+ }
+ for (; it_below != stacking_list;
+ it_below = g_list_previous(it_below))
+ {
+ /* stop when the window is not in a lower layer than the
+ window it is going under (it_above) */
+ GList *it_above = g_list_previous(it_below);
+ if (client->layer <= window_layer(it_above->data))
+ break;
+ }
+
+ GList *wins = g_list_append(NULL, win);
+ do_restack(wins, it_below);
+ g_list_free(wins);
+ }
+}