+ if (missing <= extra || j == 0) {
+ extra -= missing;
+ win_g.w += missing;
+ } else {
+ win_g.w -= remain;
+ extra += remain;
+ }
+ }
+
+ win_g.w = msize;
+ if (flip)
+ win_g.x += r_g.w - msize;
+ } else {
+ colno = winno;
+ split = 0;
+ }
+ hrh = r_g.h / colno;
+ extra = r_g.h - (colno * hrh);
+ win_g.h = hrh - 2;
+
+ i = j = 0;
+ TAILQ_FOREACH(win, &ws->winlist, entry) {
+ if (split && i == split) {
+ colno = winno - split;
+ hrh = (r_g.h / colno);
+ extra = r_g.h - (colno * hrh);
+ if (flip)
+ win_g.x = r_g.x;
+ else
+ win_g.x += msize + 2;
+ win_g.w = r_g.w - (msize + 2);
+ j = 0;
+ }
+ win_g.h = hrh - 2;
+ 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;
+
+ if (win->transient != 0 || win->floating != 0)
+ stack_floater(win, ws->r);
+ else {
+ bzero(&wc, sizeof wc);
+ wc.border_width = 1;
+ if (rot) {
+ 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 {
+ 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;
+ }
+ mask = CWX | CWY | CWWidth | CWHeight | CWBorderWidth;
+ XConfigureWindow(display, win->id, mask, &wc);
+ /*
+ fprintf(stderr, "vertical_stack: win %d x %d y %d w %d h %d bw %d\n", win->id, win->g.x, win->g.y, win->g.w , win->g.h, wc.border_width);
+ */
+ }
+
+ XMapRaised(display, win->id);
+ last_h = win_g.h;
+ i++;
+ j++;
+ }
+
+ if (winfocus)
+ focus_win(winfocus); /* has to be done outside of the loop */
+}
+
+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;
+ 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;
+ default:
+ return;
+ }
+}
+
+void
+vertical_stack(struct workspace *ws, struct swm_geometry *g)
+{
+ DNPRINTF(SWM_D_STACK, "vertical_stack: workspace: %d\n", ws->idx);
+
+ stack_master(ws, g, 0, 0);
+}
+
+void
+horizontal_config(struct workspace *ws, int id)
+{
+ DNPRINTF(SWM_D_STACK, "horizontal_config: workspace: %d\n", ws->idx);
+
+ switch (id) {
+ case SWM_ARG_ID_STACKRESET:
+ case SWM_ARG_ID_STACKINIT:
+ ws->l_state.horizontal_mwin = 1;
+ ws->l_state.horizontal_msize = SWM_H_SLICE / 2;
+ break;
+ case SWM_ARG_ID_MASTERSHRINK:
+ if (ws->l_state.horizontal_msize > 1)
+ ws->l_state.horizontal_msize--;
+ break;
+ case SWM_ARG_ID_MASTERGROW:
+ if (ws->l_state.horizontal_msize < SWM_H_SLICE - 1)
+ ws->l_state.horizontal_msize++;
+ break;
+ case SWM_ARG_ID_MASTERADD:
+ ws->l_state.horizontal_mwin++;
+ break;
+ case SWM_ARG_ID_MASTERDEL:
+ if (ws->l_state.horizontal_mwin > 0)
+ ws->l_state.horizontal_mwin--;
+ break;
+ default:
+ return;
+ }
+}
+
+void
+horizontal_stack(struct workspace *ws, struct swm_geometry *g)
+{
+ DNPRINTF(SWM_D_STACK, "vertical_stack: workspace: %d\n", ws->idx);
+
+ stack_master(ws, g, 1, 0);
+}
+
+/* fullscreen view */
+void
+max_stack(struct workspace *ws, struct swm_geometry *g) {
+ XWindowChanges wc;
+ struct swm_geometry gg = *g;
+ struct ws_win *win, *winfocus;
+ unsigned int mask;
+
+ DNPRINTF(SWM_D_STACK, "max_stack: workspace: %d\n", ws->idx);
+
+ if (count_win(ws, 0) == 0)
+ return;
+
+ if (ws->focus == NULL)
+ ws->focus = TAILQ_FIRST(&ws->winlist);
+ winfocus = cur_focus ? cur_focus : ws->focus;
+
+ TAILQ_FOREACH(win, &ws->winlist, entry) {
+ if (win->transient != 0 || win->floating != 0) {
+ if (win == ws->focus) {
+ /* XXX maximize? */
+ stack_floater(win, ws->r);
+ XMapRaised(display, win->id);
+ } else
+ XUnmapWindow(display, win->id);
+ } else {
+ bzero(&wc, sizeof wc);
+ wc.border_width = 1;
+ win->g.x = wc.x = gg.x;
+ win->g.y = wc.y = gg.y;
+ win->g.w = wc.width = gg.w;
+ win->g.h = wc.height = gg.h;
+ mask = CWX | CWY | CWWidth | CWHeight | CWBorderWidth;
+ XConfigureWindow(display, win->id, mask, &wc);
+
+ if (win == ws->focus) {
+ XMapRaised(display, win->id);
+ } else
+ XUnmapWindow(display, win->id);
+ }
+ }
+
+ if (winfocus)
+ focus_win(winfocus); /* has to be done outside of the loop */
+}
+
+void
+send_to_ws(struct swm_region *r, union arg *args)
+{
+ int wsid = args->id;
+ struct ws_win *win = cur_focus;
+ struct workspace *ws, *nws;
+ Atom ws_idx_atom = 0;
+ unsigned char ws_idx_str[SWM_PROPLEN];
+
+ if (win == NULL)
+ return;
+
+ DNPRINTF(SWM_D_MOVE, "send_to_ws: win: %lu\n", win->id);
+
+ ws = win->ws;
+ nws = &win->s->ws[wsid];
+
+ XUnmapWindow(display, win->id);
+
+ /* find a window to focus */
+ ws->focus = TAILQ_PREV(win, ws_win_list, entry);
+ if (ws->focus == NULL)
+ ws->focus = TAILQ_FIRST(&ws->winlist);
+ if (ws->focus == win)
+ ws->focus = NULL;
+
+ TAILQ_REMOVE(&ws->winlist, win, entry);
+
+ TAILQ_INSERT_TAIL(&nws->winlist, win, entry);
+ win->ws = nws;
+
+ /* Try to update the window's workspace property */
+ ws_idx_atom = XInternAtom(display, "_SWM_WS", False);
+ if (ws_idx_atom &&
+ snprintf(ws_idx_str, SWM_PROPLEN, "%d", nws->idx) < SWM_PROPLEN) {
+ DNPRINTF(SWM_D_PROP, "setting property _SWM_WS to %s\n",
+ ws_idx_str);
+ XChangeProperty(display, win->id, ws_idx_atom, XA_STRING, 8,
+ PropModeReplace, ws_idx_str, SWM_PROPLEN);
+ }
+
+ if (count_win(nws, 1) == 1)
+ nws->focus = win;
+ ws->restack = 1;
+ nws->restack = 1;