]> Dogcows Code - chaz/openbox/blobdiff - openbox/stacking.c
rename the Client struct to ObClient
[chaz/openbox] / openbox / stacking.c
index 139f968f3efcf957d4ea7fe9b3ab25f7e0a20541..c2c61d2070210bd31bca88e494a0f33824fbaf9b 100644 (file)
@@ -11,34 +11,29 @@ GList  *stacking_list = NULL;
 
 void stacking_set_list()
 {
-    Window *windows, *win_it;
+    Window *windows = NULL;
     GList *it;
-    guint size = g_list_length(stacking_list);
+    guint i = 0;
 
     /* on shutdown, don't update the properties, so that we can read it back
        in on startup and re-stack the windows as they were before we shut down
     */
-    if (ob_state == State_Exiting) return;
+    if (ob_state == OB_STATE_EXITING) return;
 
     /* create an array of the window ids (from bottom to top,
        reverse order!) */
-    if (size > 0) {
-       windows = g_new(Window, size);
-       win_it = windows;
-       for (it = g_list_last(stacking_list); it != NULL;
-             it = it->prev)
-            if (WINDOW_IS_CLIENT(it->data)) {
-                *win_it = WINDOW_AS_CLIENT(it->data)->window;
-                ++win_it;
-            }
-    } else
-       windows = win_it = NULL;
+    if (stacking_list) {
+       windows = g_new(Window, g_list_length(stacking_list));
+        for (it = g_list_last(stacking_list); it; it = g_list_previous(it)) {
+            if (WINDOW_IS_CLIENT(it->data))
+                windows[i++] = WINDOW_AS_CLIENT(it->data)->window;
+        }
+    }
 
     PROP_SETA32(ob_root, net_client_list_stacking, window,
-                (guint32*)windows, win_it - windows);
+                (guint32*)windows, i);
 
-    if (windows)
-       g_free(windows);
+    g_free(windows);
 }
 
 static void do_restack(GList *wins, GList *before)
@@ -66,6 +61,8 @@ static void do_restack(GList *wins, GList *before)
 
     for (i = 1, it = wins; it; ++i, it = g_list_next(it)) {
         win[i] = window_top(it->data);
+        g_assert(win[i] != None); /* better not call stacking shit before
+                                     setting your top level window value */
         stacking_list = g_list_insert_before(stacking_list, before, it->data);
     }
 
@@ -78,9 +75,11 @@ static void do_restack(GList *wins, GList *before)
 
     XRestackWindows(ob_display, win, i);
     g_free(win);
+
+    stacking_set_list();
 }
 
-static void raise(GList *wins)
+static void do_raise(GList *wins)
 {
     GList *it;
     GList *layer[NUM_STACKLAYER] = {NULL};
@@ -107,7 +106,7 @@ static void raise(GList *wins)
     }
 }
 
-static void lower(GList *wins)
+static void do_lower(GList *wins)
 {
     GList *it;
     GList *layer[NUM_STACKLAYER] = {NULL};
@@ -134,111 +133,113 @@ static void lower(GList *wins)
     }
 }
 
-static GList *pick_windows(ObWindow *win)
+static GList *pick_windows(ObClient *top, ObClient *selected, gboolean raise)
 {
     GList *ret = NULL;
-    GList *it, *next;
+    GList *it, *next, *prev;
     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);
+    GList *modals = NULL;
+    GList *trans = NULL;
+    GList *modal_sel_it = NULL; /* the selected guy if modal */
+    GList *trans_sel_it = NULL; /* the selected guy if not */
 
     /* remove first so we can't run into ourself */
-    stacking_list = g_list_remove(stacking_list, win);
+    stacking_list = g_list_remove(stacking_list, top);
 
-    /* add transient children in their stacking order */
     i = 0;
-    n = g_slist_length(c->transients);
+    n = g_slist_length(top->transients);
     for (it = stacking_list; i < n && it; it = next) {
+        prev = g_list_previous(it);
         next = g_list_next(it);
-        if ((sit = g_slist_find(c->transients, it->data))) {
+
+        if ((sit = g_slist_find(top->transients, it->data))) {
+            ObClient *c = sit->data;
+
             ++i;
-            ret = g_list_concat(ret, pick_windows(sit->data));
-            it = stacking_list;
+
+            if (!c->modal) {
+                if (c != selected) {
+                    trans = g_list_concat(trans,
+                                           pick_windows(c, selected, raise));
+                } else {
+                    g_assert(modal_sel_it == NULL);
+                    g_assert(trans_sel_it == NULL);
+                    trans_sel_it = pick_windows(c, selected, raise);
+                }
+            } else {
+                if (c != selected) {
+                    modals = g_list_concat(modals,
+                                           pick_windows(c, selected, raise));
+                } else {
+                    g_assert(modal_sel_it == NULL);
+                    g_assert(trans_sel_it == NULL);
+                    modal_sel_it = pick_windows(c, selected, raise);
+                }
+            }
+            /* if we dont have a prev then start back at the beginning,
+               otherwise skip back to the prev's next */
+            next = prev ? g_list_next(prev) : stacking_list;
         }
     }
 
+    ret = g_list_concat((raise ? modal_sel_it : modals),
+                        (raise ? modals : modal_sel_it));
+
+    ret = g_list_concat(ret, (raise ? trans_sel_it : trans));
+    ret = g_list_concat(ret, (raise ? trans : trans_sel_it));
+
+
     /* add itself */
-    ret = g_list_append(ret, win);
+    ret = g_list_append(ret, top);
 
     return ret;
 }
 
-static GList *pick_group_windows(ObWindow *win)
+static GList *pick_group_windows(ObClient *top, ObClient *selected, gboolean raise)
 {
     GList *ret = NULL;
-    GList *it, *next;
+    GList *it, *next, *prev;
     GSList *sit;
-    Client *c;
     int i, n;
 
-    if (!WINDOW_IS_CLIENT(win))
-        return NULL;
-
-    c = WINDOW_AS_CLIENT(win);
-
     /* add group members in their stacking order */
-    if (c->group) {
+    if (top->group) {
         i = 0;
-        n = g_slist_length(c->group->members) - 1;
+        n = g_slist_length(top->group->members) - 1;
         for (it = stacking_list; i < n && it; it = next) {
+            prev = g_list_previous(it);
             next = g_list_next(it);
-            if ((sit = g_slist_find(c->group->members, it->data))) {
+
+            if ((sit = g_slist_find(top->group->members, it->data))) {
                 ++i;
-                ret = g_list_concat(ret, pick_windows(sit->data)); 
-                it = stacking_list;
+                ret = g_list_concat(ret,
+                                    pick_windows(sit->data, selected, raise)); 
+                /* if we dont have a prev then start back at the beginning,
+                   otherwise skip back to the prev's next */
+                next = prev ? g_list_next(prev) : stacking_list;
             }
         }
     }
     return ret;
 }
 
-static ObWindow *top_transient(ObWindow *window)
-{
-    Client *client;
-
-    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;
-}
-
 void stacking_raise(ObWindow *window)
 {
     GList *wins;
 
-    window = top_transient(window);
-    wins = pick_windows(window);
-    wins = g_list_concat(wins, pick_group_windows(window));
-    raise(wins);
+    if (WINDOW_IS_CLIENT(window)) {
+        ObClient *c;
+        ObClient *selected;
+        selected = WINDOW_AS_CLIENT(window);
+        c = client_search_top_transient(selected);
+        wins = pick_windows(c, selected, TRUE);
+        wins = g_list_concat(wins, pick_group_windows(c, selected, TRUE));
+    } else {
+        wins = g_list_append(NULL, window);
+        stacking_list = g_list_remove(stacking_list, window);
+    }
+    do_raise(wins);
     g_list_free(wins);
 }
 
@@ -246,34 +247,40 @@ void stacking_lower(ObWindow *window)
 {
     GList *wins;
 
-    window = top_transient(window);
-    wins = pick_windows(window);
-    wins = g_list_concat(wins, pick_group_windows(window));
-    lower(wins);
+    if (WINDOW_IS_CLIENT(window)) {
+        ObClient *c;
+        ObClient *selected;
+        selected = WINDOW_AS_CLIENT(window);
+        c = client_search_top_transient(selected);
+        wins = pick_windows(c, selected, FALSE);
+        wins = g_list_concat(pick_group_windows(c, selected, FALSE), wins);
+    } else {
+        wins = g_list_append(NULL, window);
+        stacking_list = g_list_remove(stacking_list, window);
+    }
+    do_lower(wins);
     g_list_free(wins);
 }
 
 void stacking_add(ObWindow *win)
 {
     StackLayer l;
-    GList *wins, *it;
+    GList *wins;
+
+    g_assert(focus_backup != None); /* make sure I dont break this in the
+                                       future */
 
     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_list = g_list_append(stacking_list, win);
     stacking_raise(win);
 }
 
 void stacking_add_nonintrusive(ObWindow *win)
 {
-    Client *client;
-    Client *parent = NULL;
+    ObClient *client;
+    ObClient *parent = NULL;
     GList *it_before = NULL;
 
     if (!WINDOW_IS_CLIENT(win)) {
@@ -296,7 +303,7 @@ void stacking_add_nonintrusive(ObWindow *win)
                     if ((sit = g_slist_find(client->group->members, it->data)))
                 for (sit = client->group->members; !parent && sit;
                      sit = sit->next) {
-                    Client *c = sit->data;
+                    ObClient *c = sit->data;
                     /* checking transient_for prevents infinate loops! */
                     if (sit->data == it->data && !c->transient_for)
                         parent = it->data;
This page took 0.028114 seconds and 4 git commands to generate.