+ int i, n;
+ 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, top);
+
+ i = 0;
+ 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(top->transients, it->data))) {
+ Client *c = sit->data;
+
+ ++i;
+
+ 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;
+ }
+ }