dwm-centeredmaster-20160719-56a31dc.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dwm-centeredmaster-20160719-56a31dc.diff (4354B)
       ---
            1 diff --git a/config.def.h b/config.def.h
            2 index fd77a07..f025619 100644
            3 --- a/config.def.h
            4 +++ b/config.def.h
            5 @@ -41,6 +41,8 @@ static const Layout layouts[] = {
            6          { "[]=",      tile },    /* first entry is default */
            7          { "><>",      NULL },    /* no layout function means floating behavior */
            8          { "[M]",      monocle },
            9 +        { "|M|",      centeredmaster },
           10 +        { ">M>",      centeredfloatingmaster },
           11  };
           12  
           13  /* key definitions */
           14 @@ -76,6 +78,8 @@ static Key keys[] = {
           15          { MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
           16          { MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
           17          { MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
           18 +        { MODKEY,                       XK_u,      setlayout,      {.v = &layouts[3]} },
           19 +        { MODKEY,                       XK_o,      setlayout,      {.v = &layouts[4]} },
           20          { MODKEY,                       XK_space,  setlayout,      {0} },
           21          { MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
           22          { MODKEY,                       XK_0,      view,           {.ui = ~0 } },
           23 diff --git a/dwm.c b/dwm.c
           24 index b2bc9bd..9ecabae 100644
           25 --- a/dwm.c
           26 +++ b/dwm.c
           27 @@ -234,6 +234,8 @@ static int xerror(Display *dpy, XErrorEvent *ee);
           28  static int xerrordummy(Display *dpy, XErrorEvent *ee);
           29  static int xerrorstart(Display *dpy, XErrorEvent *ee);
           30  static void zoom(const Arg *arg);
           31 +static void centeredmaster(Monitor *m);
           32 +static void centeredfloatingmaster(Monitor *m);
           33  
           34  /* variables */
           35  static const char broken[] = "broken";
           36 @@ -2138,3 +2140,106 @@ main(int argc, char *argv[])
           37          XCloseDisplay(dpy);
           38          return EXIT_SUCCESS;
           39  }
           40 +
           41 +void
           42 +centeredmaster(Monitor *m)
           43 +{
           44 +        unsigned int i, n, h, mw, mx, my, oty, ety, tw;
           45 +        Client *c;
           46 +
           47 +        /* count number of clients in the selected monitor */
           48 +        for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
           49 +        if (n == 0)
           50 +                return;
           51 +
           52 +        /* initialize areas */
           53 +        mw = m->ww;
           54 +        mx = 0;
           55 +        my = 0;
           56 +        tw = mw;
           57 +
           58 +        if (n > m->nmaster) {
           59 +                /* go mfact box in the center if more than nmaster clients */
           60 +                mw = m->nmaster ? m->ww * m->mfact : 0;
           61 +                tw = m->ww - mw;
           62 +
           63 +                if (n - m->nmaster > 1) {
           64 +                        /* only one client */
           65 +                        mx = (m->ww - mw) / 2;
           66 +                        tw = (m->ww - mw) / 2;
           67 +                }
           68 +        }
           69 +
           70 +        oty = 0;
           71 +        ety = 0;
           72 +        for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
           73 +        if (i < m->nmaster) {
           74 +                /* nmaster clients are stacked vertically, in the center
           75 +                 * of the screen */
           76 +                h = (m->wh - my) / (MIN(n, m->nmaster) - i);
           77 +                resize(c, m->wx + mx, m->wy + my, mw - (2*c->bw),
           78 +                       h - (2*c->bw), 0);
           79 +                my += HEIGHT(c);
           80 +        } else {
           81 +                /* stack clients are stacked vertically */
           82 +                if ((i - m->nmaster) % 2 ) {
           83 +                        h = (m->wh - ety) / ( (1 + n - i) / 2);
           84 +                        resize(c, m->wx, m->wy + ety, tw - (2*c->bw),
           85 +                               h - (2*c->bw), 0);
           86 +                        ety += HEIGHT(c);
           87 +                } else {
           88 +                        h = (m->wh - oty) / ((1 + n - i) / 2);
           89 +                        resize(c, m->wx + mx + mw, m->wy + oty,
           90 +                               tw - (2*c->bw), h - (2*c->bw), 0);
           91 +                        oty += HEIGHT(c);
           92 +                }
           93 +        }
           94 +}
           95 +
           96 +void
           97 +centeredfloatingmaster(Monitor *m)
           98 +{
           99 +        unsigned int i, n, w, mh, mw, mx, mxo, my, myo, tx;
          100 +        Client *c;
          101 +
          102 +        /* count number of clients in the selected monitor */
          103 +        for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
          104 +        if (n == 0)
          105 +                return;
          106 +
          107 +        /* initialize nmaster area */
          108 +        if (n > m->nmaster) {
          109 +                /* go mfact box in the center if more than nmaster clients */
          110 +                if (m->ww > m->wh) {
          111 +                        mw = m->nmaster ? m->ww * m->mfact : 0;
          112 +                        mh = m->nmaster ? m->wh * 0.9 : 0;
          113 +                } else {
          114 +                        mh = m->nmaster ? m->wh * m->mfact : 0;
          115 +                        mw = m->nmaster ? m->ww * 0.9 : 0;
          116 +                }
          117 +                mx = mxo = (m->ww - mw) / 2;
          118 +                my = myo = (m->wh - mh) / 2;
          119 +        } else {
          120 +                /* go fullscreen if all clients are in the master area */
          121 +                mh = m->wh;
          122 +                mw = m->ww;
          123 +                mx = mxo = 0;
          124 +                my = myo = 0;
          125 +        }
          126 +
          127 +        for(i = tx = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
          128 +        if (i < m->nmaster) {
          129 +                /* nmaster clients are stacked horizontally, in the center
          130 +                 * of the screen */
          131 +                w = (mw + mxo - mx) / (MIN(n, m->nmaster) - i);
          132 +                resize(c, m->wx + mx, m->wy + my, w - (2*c->bw),
          133 +                       mh - (2*c->bw), 0);
          134 +                mx += WIDTH(c);
          135 +        } else {
          136 +                /* stack clients are stacked horizontally */
          137 +                w = (m->ww - tx) / (n - i);
          138 +                resize(c, m->wx + tx, m->wy, w - (2*c->bw),
          139 +                       m->wh - (2*c->bw), 0);
          140 +                tx += WIDTH(c);
          141 +        }
          142 +}