+ DNPRINTF(SWM_D_WS, "switchws screen[%d]:%dx%d+%d+%d: "
+ "%d -> %d\n", r->s->idx, WIDTH(r), HEIGHT(r), X(r), Y(r),
+ old_ws->idx, wsid);
+
+ if (new_ws == NULL || old_ws == NULL)
+ return;
+ if (new_ws == old_ws)
+ return;
+
+ other_r = new_ws->r;
+ if (other_r == NULL) {
+ /* the other workspace is hidden, hide this one */
+ old_ws->r = NULL;
+ unmap_old = 1;
+ } else {
+ /* the other ws is visible in another region, exchange them */
+ other_r->ws_prior = new_ws;
+ other_r->ws = old_ws;
+ old_ws->r = other_r;
+ }
+ this_r->ws_prior = old_ws;
+ this_r->ws = new_ws;
+ new_ws->r = this_r;
+
+ /* this is needed so that we can click on a window after a restart */
+ unfocus_all();
+
+ stack();
+ a.id = SWM_ARG_ID_FOCUSCUR;
+ focus(new_ws->r, &a);
+
+ bar_update();
+
+ /* unmap old windows */
+ if (unmap_old)
+ TAILQ_FOREACH(win, &old_ws->winlist, entry)
+ unmap_window(win);
+
+ if (focus_mode == SWM_FOCUS_DEFAULT)
+ drain_enter_notify();
+}
+
+void
+cyclews(struct swm_region *r, union arg *args)
+{
+ union arg a;
+ struct swm_screen *s = r->s;
+ int cycle_all = 0;
+
+ DNPRINTF(SWM_D_WS, "cyclews id %d "
+ "in screen[%d]:%dx%d+%d+%d ws %d\n", args->id,
+ r->s->idx, WIDTH(r), HEIGHT(r), X(r), Y(r), r->ws->idx);
+
+ a.id = r->ws->idx;
+ do {
+ switch (args->id) {
+ case SWM_ARG_ID_CYCLEWS_UP_ALL:
+ cycle_all = 1;
+ /* FALLTHROUGH */
+ case SWM_ARG_ID_CYCLEWS_UP:
+ if (a.id < SWM_WS_MAX - 1)
+ a.id++;
+ else
+ a.id = 0;
+ break;
+ case SWM_ARG_ID_CYCLEWS_DOWN_ALL:
+ cycle_all = 1;
+ /* FALLTHROUGH */
+ case SWM_ARG_ID_CYCLEWS_DOWN:
+ if (a.id > 0)
+ a.id--;
+ else
+ a.id = SWM_WS_MAX - 1;
+ break;
+ default:
+ return;
+ };
+
+ if (!cycle_all &&
+ (cycle_empty == 0 && TAILQ_EMPTY(&s->ws[a.id].winlist)))
+ continue;
+ if (cycle_visible == 0 && s->ws[a.id].r != NULL)
+ continue;
+
+ switchws(r, &a);
+ } while (a.id != r->ws->idx);
+}
+
+void
+priorws(struct swm_region *r, union arg *args)
+{
+ union arg a;
+
+ DNPRINTF(SWM_D_WS, "priorws id %d "
+ "in screen[%d]:%dx%d+%d+%d ws %d\n", args->id,
+ r->s->idx, WIDTH(r), HEIGHT(r), X(r), Y(r), r->ws->idx);
+
+ if (r->ws_prior == NULL)
+ return;
+
+ a.id = r->ws_prior->idx;
+ switchws(r, &a);
+}
+
+void
+cyclescr(struct swm_region *r, union arg *args)
+{
+ struct swm_region *rr = NULL;
+ union arg a;
+ int i, x, y;
+
+ /* do nothing if we don't have more than one screen */
+ if (!(ScreenCount(display) > 1 || outputs > 1))
+ return;
+
+ i = r->s->idx;
+ switch (args->id) {
+ case SWM_ARG_ID_CYCLESC_UP:
+ rr = TAILQ_NEXT(r, entry);
+ if (rr == NULL)
+ rr = TAILQ_FIRST(&screens[i].rl);
+ break;
+ case SWM_ARG_ID_CYCLESC_DOWN:
+ rr = TAILQ_PREV(r, swm_region_list, entry);
+ if (rr == NULL)
+ rr = TAILQ_LAST(&screens[i].rl, swm_region_list);
+ break;
+ default:
+ return;
+ };
+ if (rr == NULL)
+ return;
+
+ /* move mouse to region */
+ x = rr->g.x + 1;
+ y = rr->g.y + 1 + (bar_enabled ? bar_height : 0);
+ XWarpPointer(display, None, rr->s[i].root, 0, 0, 0, 0, x, y);
+
+ a.id = SWM_ARG_ID_FOCUSCUR;
+ focus(rr, &a);
+
+ if (rr->ws->focus) {
+ /* move to focus window */
+ x = rr->ws->focus->g.x + 1;
+ y = rr->ws->focus->g.y + 1;
+ XWarpPointer(display, None, rr->s[i].root, 0, 0, 0, 0, x, y);
+ }
+}
+
+void
+sort_windows(struct ws_win_list *wl)
+{
+ struct ws_win *win, *parent, *nxt;
+
+ if (wl == NULL)
+ return;
+
+ for (win = TAILQ_FIRST(wl); win != TAILQ_END(wl); win = nxt) {
+ nxt = TAILQ_NEXT(win, entry);
+ if (win->transient) {
+ parent = find_window(win->transient);
+ if (parent == NULL) {
+ fprintf(stderr, "not possible bug\n");
+ continue;
+ }
+ TAILQ_REMOVE(wl, win, entry);
+ TAILQ_INSERT_AFTER(wl, parent, win, entry);
+ }
+ }
+
+}
+
+void
+swapwin(struct swm_region *r, union arg *args)
+{
+ struct ws_win *target, *source;
+ struct ws_win *cur_focus;
+ struct ws_win_list *wl;
+
+
+ DNPRINTF(SWM_D_WS, "swapwin id %d "
+ "in screen %d region %dx%d+%d+%d ws %d\n", args->id,
+ r->s->idx, WIDTH(r), HEIGHT(r), X(r), Y(r), r->ws->idx);
+
+ cur_focus = r->ws->focus;
+ if (cur_focus == NULL)
+ return;
+
+ source = cur_focus;
+ wl = &source->ws->winlist;
+
+ switch (args->id) {
+ case SWM_ARG_ID_SWAPPREV:
+ if (source->transient)
+ source = find_window(source->transient);
+ target = TAILQ_PREV(source, ws_win_list, entry);
+ if (target && target->transient)
+ target = find_window(target->transient);
+ TAILQ_REMOVE(wl, source, entry);
+ if (target == NULL)
+ TAILQ_INSERT_TAIL(wl, source, entry);
+ else
+ TAILQ_INSERT_BEFORE(target, source, entry);
+ break;
+ case SWM_ARG_ID_SWAPNEXT:
+ target = TAILQ_NEXT(source, entry);
+ /* move the parent and let the sort handle the move */
+ if (source->transient)
+ source = find_window(source->transient);
+ TAILQ_REMOVE(wl, source, entry);
+ if (target == NULL)
+ TAILQ_INSERT_HEAD(wl, source, entry);
+ else
+ TAILQ_INSERT_AFTER(wl, target, source, entry);
+ break;
+ case SWM_ARG_ID_SWAPMAIN:
+ target = TAILQ_FIRST(wl);
+ if (target == source) {
+ if (source->ws->focus_prev != NULL &&
+ source->ws->focus_prev != target)
+
+ source = source->ws->focus_prev;
+ else
+ return;
+ }
+ if (target == NULL || source == NULL)
+ return;
+ source->ws->focus_prev = target;
+ TAILQ_REMOVE(wl, target, entry);
+ TAILQ_INSERT_BEFORE(source, target, entry);
+ TAILQ_REMOVE(wl, source, entry);
+ TAILQ_INSERT_HEAD(wl, source, entry);
+ break;
+ case SWM_ARG_ID_MOVELAST:
+ TAILQ_REMOVE(wl, source, entry);
+ TAILQ_INSERT_TAIL(wl, source, entry);
+ break;
+ default:
+ DNPRINTF(SWM_D_MOVE, "invalid id: %d\n", args->id);
+ return;
+ }
+
+ sort_windows(wl);
+
+ stack();
+}
+
+void
+focus_prev(struct ws_win *win)
+{
+ struct ws_win *winfocus = NULL, *winlostfocus = NULL;
+ struct ws_win *cur_focus = NULL;
+ struct ws_win_list *wl = NULL;
+ struct workspace *ws = NULL;
+
+ DNPRINTF(SWM_D_FOCUS, "focus_prev: id %lu\n", WINID(win));
+
+ if (!(win && win->ws))
+ return;
+
+ ws = win->ws;
+ wl = &ws->winlist;
+ cur_focus = ws->focus;
+ winlostfocus = cur_focus;
+
+ /* pickle, just focus on whatever */
+ if (cur_focus == NULL) {
+ /* use prev_focus if valid */
+ if (ws->focus_prev && ws->focus_prev != cur_focus &&
+ find_window(WINID(ws->focus_prev)))
+ winfocus = ws->focus_prev;
+ if (winfocus == NULL)
+ winfocus = TAILQ_FIRST(wl);
+ goto done;
+ }
+
+ /* if transient focus on parent */
+ if (cur_focus->transient) {
+ winfocus = find_window(cur_focus->transient);
+ goto done;
+ }
+
+ /* if in max_stack try harder */
+ if ((win->quirks & SWM_Q_FOCUSPREV) ||
+ (ws->cur_layout->flags & SWM_L_FOCUSPREV)) {
+ if (cur_focus != ws->focus_prev)
+ winfocus = ws->focus_prev;
+ else if (cur_focus != ws->focus)
+ winfocus = ws->focus;
+ else
+ winfocus = TAILQ_PREV(win, ws_win_list, entry);
+ if (winfocus)
+ goto done;
+ }
+
+ if (cur_focus == win)
+ winfocus = TAILQ_PREV(win, ws_win_list, entry);
+ if (winfocus == NULL)
+ winfocus = TAILQ_LAST(wl, ws_win_list);
+ if (winfocus == NULL || winfocus == win)
+ winfocus = TAILQ_NEXT(cur_focus, entry);
+done:
+ if (winfocus == winlostfocus || winfocus == NULL)
+ return;
+
+ focus_magic(winfocus);
+}
+
+void
+focus(struct swm_region *r, union arg *args)
+{
+ struct ws_win *winfocus = NULL, *winlostfocus = NULL, *head;
+ struct ws_win *cur_focus = NULL;
+ struct ws_win_list *wl = NULL;
+ struct workspace *ws = NULL;
+
+ if (!(r && r->ws))
+ return;
+
+ DNPRINTF(SWM_D_FOCUS, "focus: id %d\n", args->id);
+
+ /* treat FOCUS_CUR special */
+ if (args->id == SWM_ARG_ID_FOCUSCUR) {
+ if (r->ws->focus && r->ws->focus->iconic == 0)
+ winfocus = r->ws->focus;
+ else if (r->ws->focus_prev && r->ws->focus_prev->iconic == 0)
+ winfocus = r->ws->focus_prev;
+ else
+ TAILQ_FOREACH(winfocus, &r->ws->winlist, entry)
+ if (winfocus->iconic == 0)
+ break;
+
+ focus_magic(winfocus);
+ return;
+ }
+
+ if ((cur_focus = r->ws->focus) == NULL)
+ return;
+ ws = r->ws;
+ wl = &ws->winlist;
+
+ winlostfocus = cur_focus;
+
+ switch (args->id) {
+ case SWM_ARG_ID_FOCUSPREV:
+ head = TAILQ_PREV(cur_focus, ws_win_list, entry);
+ if (head == NULL)
+ head = TAILQ_LAST(wl, ws_win_list);
+ winfocus = head;
+ if (WINID(winfocus) == cur_focus->transient) {
+ head = TAILQ_PREV(winfocus, ws_win_list, entry);
+ if (head == NULL)
+ head = TAILQ_LAST(wl, ws_win_list);
+ winfocus = head;
+ }
+
+ /* skip iconics */
+ if (winfocus && winfocus->iconic) {
+ TAILQ_FOREACH_REVERSE(winfocus, wl, ws_win_list, entry)
+ if (winfocus->iconic == 0)
+ break;
+ }
+ break;
+
+ case SWM_ARG_ID_FOCUSNEXT:
+ head = TAILQ_NEXT(cur_focus, entry);
+ if (head == NULL)
+ head = TAILQ_FIRST(wl);
+ winfocus = head;
+
+ /* skip iconics */
+ if (winfocus && winfocus->iconic) {
+ TAILQ_FOREACH(winfocus, wl, entry)
+ if (winfocus->iconic == 0)
+ break;
+ }
+ break;
+
+ case SWM_ARG_ID_FOCUSMAIN:
+ winfocus = TAILQ_FIRST(wl);
+ if (winfocus == cur_focus)
+ winfocus = cur_focus->ws->focus_prev;
+ break;
+
+ default:
+ return;
+ }
+ if (winfocus == winlostfocus || winfocus == NULL)
+ return;
+
+ focus_magic(winfocus);
+}
+
+void
+cycle_layout(struct swm_region *r, union arg *args)
+{
+ struct workspace *ws = r->ws;
+ union arg a;
+
+ DNPRINTF(SWM_D_EVENT, "cycle_layout: workspace: %d\n", ws->idx);
+
+ ws->cur_layout++;
+ if (ws->cur_layout->l_stack == NULL)
+ ws->cur_layout = &layouts[0];
+
+ stack();
+ if (focus_mode == SWM_FOCUS_DEFAULT)
+ drain_enter_notify();
+ a.id = SWM_ARG_ID_FOCUSCUR;
+ focus(r, &a);
+ bar_update();
+}
+
+void
+stack_config(struct swm_region *r, union arg *args)
+{
+ struct workspace *ws = r->ws;
+
+ DNPRINTF(SWM_D_STACK, "stack_config for workspace %d (id %d\n",
+ args->id, ws->idx);
+
+ if (ws->cur_layout->l_config != NULL)
+ ws->cur_layout->l_config(ws, args->id);
+
+ if (args->id != SWM_ARG_ID_STACKINIT)
+ stack();
+ bar_update();
+}
+
+void
+stack(void) {
+ struct swm_geometry g;
+ struct swm_region *r;
+ int i, j;
+
+ DNPRINTF(SWM_D_STACK, "stack\n");
+
+ for (i = 0; i < ScreenCount(display); i++) {
+ j = 0;
+ TAILQ_FOREACH(r, &screens[i].rl, entry) {
+ DNPRINTF(SWM_D_STACK, "stacking workspace %d "
+ "(screen %d, region %d)\n", r->ws->idx, i, j++);
+
+ /* start with screen geometry, adjust for bar */
+ g = r->g;
+ g.w -= 2 * border_width;
+ g.h -= 2 * border_width;
+ if (bar_enabled) {
+ if (!bar_at_bottom)
+ g.y += bar_height;
+ g.h -= bar_height;
+ }
+ r->ws->cur_layout->l_stack(r->ws, &g);
+ r->ws->cur_layout->l_string(r->ws);
+ /* save r so we can track region changes */
+ r->ws->old_r = r;
+ }
+ }
+ if (font_adjusted)
+ font_adjusted--;
+
+ if (focus_mode == SWM_FOCUS_DEFAULT)
+ drain_enter_notify();
+}
+
+void
+store_float_geom(struct ws_win *win, struct swm_region *r)
+{
+ /* retain window geom and region geom */
+ win->g_float.x = win->g.x;
+ win->g_float.y = win->g.y;
+ win->g_float.w = win->g.w;
+ win->g_float.h = win->g.h;
+ win->rg_float.x = r->g.x;
+ win->rg_float.y = r->g.y;
+ win->rg_float.w = r->g.w;
+ win->rg_float.h = r->g.h;
+ win->g_floatvalid = 1;
+}
+
+void
+stack_floater(struct ws_win *win, struct swm_region *r)
+{
+ unsigned int mask;
+ XWindowChanges wc;
+
+ if (win == NULL)
+ return;
+
+ bzero(&wc, sizeof wc);
+ mask = CWX | CWY | CWBorderWidth | CWWidth | CWHeight;
+
+ /*
+ * to allow windows to change their size (e.g. mplayer fs) only retrieve
+ * geom on ws switches or return from max mode
+ */
+
+ if (win->floatmaxed || (r != r->ws->old_r && win->g_floatvalid
+ && !(win->ewmh_flags & EWMH_F_FULLSCREEN))) {
+ /*
+ * use stored g and rg to set relative position and size
+ * as in old region or before max stack mode
+ */
+ win->g.x = win->g_float.x - win->rg_float.x + r->g.x;
+ win->g.y = win->g_float.y - win->rg_float.y + r->g.y;
+ win->g.w = win->g_float.w;
+ win->g.h = win->g_float.h;
+ win->g_floatvalid = 0;
+ }
+
+ win->floatmaxed = 0;
+
+ if ((win->quirks & SWM_Q_FULLSCREEN) && (win->g.w >= WIDTH(r)) &&
+ (win->g.h >= HEIGHT(r)))
+ wc.border_width = 0;
+ else
+ wc.border_width = border_width;
+ if (win->transient && (win->quirks & SWM_Q_TRANSSZ)) {
+ win->g.w = (double)WIDTH(r) * dialog_ratio;
+ win->g.h = (double)HEIGHT(r) * dialog_ratio;
+ }
+
+ if (!win->manual) {
+ /*
+ * floaters and transients are auto-centred unless moved
+ * or resized
+ */
+ win->g.x = r->g.x + (WIDTH(r) - win->g.w) /
+ 2 - wc.border_width;
+ win->g.y = r->g.y + (HEIGHT(r) - win->g.h) /
+ 2 - wc.border_width;
+ }
+
+ /* win can be outside r if new r smaller than old r */
+ /* Ensure top left corner inside r (move probs otherwise) */
+ if (win->g.x < r->g.x - wc.border_width)
+ win->g.x = r->g.x - wc.border_width;
+ if (win->g.x > r->g.x + r->g.w - 1)
+ win->g.x = (win->g.w > r->g.w) ? r->g.x :
+ (r->g.x + r->g.w - win->g.w - 2 * wc.border_width);
+ if (win->g.y < r->g.y - wc.border_width)
+ win->g.y = r->g.y - wc.border_width;
+ if (win->g.y > r->g.y + r->g.h - 1)
+ win->g.y = (win->g.h > r->g.h) ? r->g.y :
+ (r->g.y + r->g.h - win->g.h - 2 * wc.border_width);
+
+ wc.x = win->g.x;
+ wc.y = win->g.y;
+ wc.width = win->g.w;
+ wc.height = win->g.h;
+
+ /*
+ * Retain floater and transient geometry for correct positioning
+ * when ws changes region
+ */
+ if (!(win->ewmh_flags & EWMH_F_FULLSCREEN))
+ store_float_geom(win, r);
+
+ DNPRINTF(SWM_D_MISC, "stack_floater: win %lu x %d y %d w %d h %d\n",
+ win->id, wc.x, wc.y, wc.width, wc.height);
+
+ XConfigureWindow(display, win->id, mask, &wc);
+}
+
+/*
+ * Send keystrokes to terminal to decrease/increase the font size as the
+ * window size changes.
+ */
+void
+adjust_font(struct ws_win *win)
+{
+ if (!(win->quirks & SWM_Q_XTERM_FONTADJ) ||
+ win->floating || win->transient)
+ return;
+
+ if (win->sh.width_inc && win->last_inc != win->sh.width_inc &&
+ win->g.w / win->sh.width_inc < term_width &&
+ win->font_steps < SWM_MAX_FONT_STEPS) {
+ win->font_size_boundary[win->font_steps] =
+ (win->sh.width_inc * term_width) + win->sh.base_width;
+ win->font_steps++;
+ font_adjusted++;
+ win->last_inc = win->sh.width_inc;
+ fake_keypress(win, XK_KP_Subtract, ShiftMask);
+ } else if (win->font_steps && win->last_inc != win->sh.width_inc &&
+ win->g.w > win->font_size_boundary[win->font_steps - 1]) {
+ win->font_steps--;
+ font_adjusted++;
+ win->last_inc = win->sh.width_inc;
+ fake_keypress(win, XK_KP_Add, ShiftMask);
+ }
+}
+
+#define SWAPXY(g) do { \
+ int tmp; \
+ tmp = (g)->y; (g)->y = (g)->x; (g)->x = tmp; \
+ tmp = (g)->h; (g)->h = (g)->w; (g)->w = tmp; \
+} while (0)
+void
+stack_master(struct workspace *ws, struct swm_geometry *g, int rot, int flip)
+{
+ XWindowChanges wc;
+ XWindowAttributes wa;
+ struct swm_geometry win_g, r_g = *g;
+ struct ws_win *win, *fs_win = 0;
+ int i, j, s, stacks;
+ int w_inc = 1, h_inc, w_base = 1, h_base;
+ int hrh, extra = 0, h_slice, last_h = 0;
+ int split, colno, winno, mwin, msize, mscale;
+ int remain, missing, v_slice, reconfigure;
+ unsigned int mask;
+
+ DNPRINTF(SWM_D_STACK, "stack_master: workspace: %d\n rot=%s flip=%s",
+ ws->idx, rot ? "yes" : "no", flip ? "yes" : "no");
+
+ winno = count_win(ws, 0);
+ if (winno == 0 && count_win(ws, 1) == 0)
+ return;
+
+ TAILQ_FOREACH(win, &ws->winlist, entry)
+ if (win->transient == 0 && win->floating == 0
+ && win->iconic == 0)
+ break;
+
+ if (win == NULL)
+ goto notiles;
+
+ if (rot) {
+ w_inc = win->sh.width_inc;
+ w_base = win->sh.base_width;
+ mwin = ws->l_state.horizontal_mwin;
+ mscale = ws->l_state.horizontal_msize;
+ stacks = ws->l_state.horizontal_stacks;
+ SWAPXY(&r_g);
+ } else {
+ w_inc = win->sh.height_inc;
+ w_base = win->sh.base_height;
+ mwin = ws->l_state.vertical_mwin;
+ mscale = ws->l_state.vertical_msize;
+ stacks = ws->l_state.vertical_stacks;
+ }
+ win_g = r_g;
+
+ if (stacks > winno - mwin)
+ stacks = winno - mwin;
+ if (stacks < 1)
+ stacks = 1;
+
+ h_slice = r_g.h / SWM_H_SLICE;
+ if (mwin && winno > mwin) {
+ v_slice = r_g.w / SWM_V_SLICE;
+
+ split = mwin;
+ colno = split;
+ win_g.w = v_slice * mscale;
+
+ if (w_inc > 1 && w_inc < v_slice) {
+ /* adjust for window's requested size increment */
+ remain = (win_g.w - w_base) % w_inc;
+ missing = w_inc - remain;
+ win_g.w -= remain;
+ extra += remain;
+ }
+
+ msize = win_g.w;
+ if (flip)
+ win_g.x += r_g.w - msize;
+ } else {
+ msize = -2;
+ colno = split = winno / stacks;
+ win_g.w = ((r_g.w - (stacks * 2 * border_width) +
+ 2 * border_width) / stacks);
+ }
+ hrh = r_g.h / colno;
+ extra = r_g.h - (colno * hrh);
+ win_g.h = hrh - 2 * border_width;
+
+ /* stack all the tiled windows */
+ i = j = 0, s = stacks;
+ TAILQ_FOREACH(win, &ws->winlist, entry) {
+ if (win->transient != 0 || win->floating != 0)
+ continue;
+ if (win->iconic != 0)
+ continue;
+
+ if (win->ewmh_flags & EWMH_F_FULLSCREEN) {
+ fs_win = win;
+ continue;
+ }
+
+ if (split && i == split) {
+ colno = (winno - mwin) / stacks;
+ if (s <= (winno - mwin) % stacks)
+ colno++;
+ split = split + colno;
+ hrh = (r_g.h / colno);
+ extra = r_g.h - (colno * hrh);
+ if (flip)
+ win_g.x = r_g.x;
+ else
+ win_g.x += win_g.w + 2 * border_width;
+ win_g.w = (r_g.w - msize -
+ (stacks * 2 * border_width)) / stacks;
+ if (s == 1)
+ win_g.w += (r_g.w - msize -
+ (stacks * 2 * border_width)) % stacks;
+ s--;
+ j = 0;
+ }
+ win_g.h = hrh - 2 * border_width;
+ if (rot) {
+ h_inc = win->sh.width_inc;
+ h_base = win->sh.base_width;
+ } else {
+ h_inc = win->sh.height_inc;
+ h_base = win->sh.base_height;
+ }
+ if (j == colno - 1) {
+ win_g.h = hrh + extra;
+ } else if (h_inc > 1 && h_inc < h_slice) {
+ /* adjust for window's requested size increment */
+ remain = (win_g.h - h_base) % h_inc;
+ missing = h_inc - remain;
+
+ if (missing <= extra || j == 0) {
+ extra -= missing;
+ win_g.h += missing;
+ } else {
+ win_g.h -= remain;
+ extra += remain;
+ }
+ }
+
+ if (j == 0)
+ win_g.y = r_g.y;
+ else
+ win_g.y += last_h + 2 * border_width;
+
+ bzero(&wc, sizeof wc);
+ if (disable_border && bar_enabled == 0 && winno == 1){
+ wc.border_width = 0;
+ win_g.w += 2 * border_width;
+ win_g.h += 2 * border_width;
+ } else
+ wc.border_width = border_width;
+ reconfigure = 0;
+ if (rot) {
+ if (win->g.x != win_g.y || win->g.y != win_g.x ||
+ win->g.w != win_g.h || win->g.h != win_g.w) {
+ reconfigure = 1;
+ win->g.x = wc.x = win_g.y;
+ win->g.y = wc.y = win_g.x;
+ win->g.w = wc.width = win_g.h;
+ win->g.h = wc.height = win_g.w;
+ }
+ } else {
+ if (win->g.x != win_g.x || win->g.y != win_g.y ||
+ win->g.w != win_g.w || win->g.h != win_g.h) {
+ reconfigure = 1;
+ win->g.x = wc.x = win_g.x;
+ win->g.y = wc.y = win_g.y;
+ win->g.w = wc.width = win_g.w;
+ win->g.h = wc.height = win_g.h;
+ }
+ }
+ if (reconfigure) {
+ adjust_font(win);
+ mask = CWX | CWY | CWWidth | CWHeight | CWBorderWidth;
+ XConfigureWindow(display, win->id, mask, &wc);
+ }
+
+ if (XGetWindowAttributes(display, win->id, &wa))
+ if (wa.map_state == IsUnmapped)
+ XMapRaised(display, win->id);
+
+ last_h = win_g.h;
+ i++;
+ j++;
+ }
+
+notiles:
+ /* now, stack all the floaters and transients */
+ TAILQ_FOREACH(win, &ws->winlist, entry) {
+ if (win->transient == 0 && win->floating == 0)
+ continue;
+ if (win->iconic == 1)
+ continue;
+ if (win->ewmh_flags & EWMH_F_FULLSCREEN) {
+ fs_win = win;
+ continue;
+ }
+
+ stack_floater(win, ws->r);
+ XMapRaised(display, win->id);
+ }
+
+ if (fs_win) {
+ stack_floater(fs_win, ws->r);
+ XMapRaised(display, fs_win->id);
+ }
+}
+
+void
+vertical_config(struct workspace *ws, int id)
+{
+ DNPRINTF(SWM_D_STACK, "vertical_resize: workspace: %d\n", ws->idx);
+
+ switch (id) {
+ case SWM_ARG_ID_STACKRESET:
+ case SWM_ARG_ID_STACKINIT:
+ ws->l_state.vertical_msize = SWM_V_SLICE / 2;
+ ws->l_state.vertical_mwin = 1;
+ ws->l_state.vertical_stacks = 1;
+ break;
+ case SWM_ARG_ID_MASTERSHRINK:
+ if (ws->l_state.vertical_msize > 1)
+ ws->l_state.vertical_msize--;
+ break;
+ case SWM_ARG_ID_MASTERGROW:
+ if (ws->l_state.vertical_msize < SWM_V_SLICE - 1)
+ ws->l_state.vertical_msize++;
+ break;
+ case SWM_ARG_ID_MASTERADD:
+ ws->l_state.vertical_mwin++;
+ break;
+ case SWM_ARG_ID_MASTERDEL:
+ if (ws->l_state.vertical_mwin > 0)
+ ws->l_state.vertical_mwin--;
+ break;
+ case SWM_ARG_ID_STACKINC:
+ ws->l_state.vertical_stacks++;
+ break;
+ case SWM_ARG_ID_STACKDEC:
+ if (ws->l_state.vertical_stacks > 1)
+ ws->l_state.vertical_stacks--;
+ break;
+ default:
+ return;
+ }
+}
+
+void
+vertical_stack(struct workspace *ws, struct swm_geometry *g)
+{
+ DNPRINTF(SWM_D_STACK, "vertical_stack: workspace: %d\n", ws->idx);