+ if (win == NULL || (r = win->ws->r) == NULL)
+ return;
+ ws = win->ws;
+
+ DNPRINTF(SWM_D_EVENT, "reorder_window: win 0x%x, mode: %d\n",
+ win->id, mode);
+
+ switch (mode) {
+ case SWM_STACK_TOP:
+ /* Position above top-most sibling. */
+ TAILQ_FOREACH_REVERSE(w, &ws->winlist, ws_win_list, entry) {
+ if (w == win || w->iconic)
+ continue;
+ if ((win->ewmh_flags & EWMH_F_FULLSCREEN) !=
+ (w->ewmh_flags & EWMH_F_FULLSCREEN))
+ continue;
+ if (!win->maximized && w->maximized)
+ continue;
+ if (win->maximized) {
+ if (w->floating)
+ break;
+ continue;
+ }
+ if (win->floating == w->floating)
+ break;
+ }
+ break;
+ case SWM_STACK_ABOVE:
+ /* Stack above win directly prior. */
+ while ((w = TAILQ_PREV(w, ws_win_list, entry)) != NULL) {
+ if (w == win || w->iconic)
+ continue;
+ if ((win->ewmh_flags & EWMH_F_FULLSCREEN) !=
+ (w->ewmh_flags & EWMH_F_FULLSCREEN))
+ continue;
+ if (win->maximized != w->maximized)
+ continue;
+ if (win->floating == w->floating)
+ break;
+ }
+ break;
+ case SWM_STACK_BELOW:
+ /* Stack above win directly prior. */
+ while ((w = TAILQ_NEXT(w, entry)) != NULL) {
+ if (w == win || w->iconic)
+ continue;
+ if ((win->ewmh_flags & EWMH_F_FULLSCREEN) !=
+ (w->ewmh_flags & EWMH_F_FULLSCREEN))
+ continue;
+ if (win->maximized != w->maximized)
+ continue;
+ if (win->floating == w->floating)
+ break;
+ }
+ break;
+ case SWM_STACK_BOTTOM:
+ /* Position above top-most sibling. */
+ TAILQ_FOREACH(w, &ws->winlist, entry) {
+ if (w == win || w->iconic)
+ continue;
+ if ((win->ewmh_flags & EWMH_F_FULLSCREEN) !=
+ (w->ewmh_flags & EWMH_F_FULLSCREEN))
+ continue;
+ if (win->maximized != w->maximized)
+ continue;
+ if (win->floating == w->floating)
+ break;
+ }
+ break;
+ }
+
+ if (w == NULL) {
+ if (win->floating || (win->ewmh_flags & EWMH_F_FULLSCREEN)
+ || win->maximized)
+ val[0] = r->bar->id;
+ else
+ val[0] = r->id;
+ } else {
+ val[0] = w->id;