dwm-cfacts-6.1.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dwm-cfacts-6.1.diff (3142B)
       ---
            1 diff --git a/config.def.h b/config.def.h
            2 index 7054c06..9878dbf 100644
            3 --- a/config.def.h
            4 +++ b/config.def.h
            5 @@ -68,6 +68,9 @@ static Key keys[] = {
            6          { MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
            7          { MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
            8          { MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
            9 +        { MODKEY|ShiftMask,             XK_h,      setcfact,       {.f = +0.25} },
           10 +        { MODKEY|ShiftMask,             XK_l,      setcfact,       {.f = -0.25} },
           11 +        { MODKEY|ShiftMask,             XK_o,      setcfact,       {.f =  0.00} },
           12          { MODKEY,                       XK_Return, zoom,           {0} },
           13          { MODKEY,                       XK_Tab,    view,           {0} },
           14          { MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
           15 diff --git a/dwm.c b/dwm.c
           16 index 0362114..881afe6 100644
           17 --- a/dwm.c
           18 +++ b/dwm.c
           19 @@ -87,6 +87,7 @@ typedef struct Client Client;
           20  struct Client {
           21          char name[256];
           22          float mina, maxa;
           23 +        float cfact;
           24          int x, y, w, h;
           25          int oldx, oldy, oldw, oldh;
           26          int basew, baseh, incw, inch, maxw, maxh, minw, minh;
           27 @@ -201,6 +202,7 @@ static void setclientstate(Client *c, long state);
           28  static void setfocus(Client *c);
           29  static void setfullscreen(Client *c, int fullscreen);
           30  static void setlayout(const Arg *arg);
           31 +static void setcfact(const Arg *arg);
           32  static void setmfact(const Arg *arg);
           33  static void setup(void);
           34  static void showhide(Client *c);
           35 @@ -1052,6 +1054,7 @@ manage(Window w, XWindowAttributes *wa)
           36          c->w = c->oldw = wa->width;
           37          c->h = c->oldh = wa->height;
           38          c->oldbw = wa->border_width;
           39 +        c->cfact = 1.0;
           40  
           41          if (c->x + WIDTH(c) > c->mon->mx + c->mon->mw)
           42                  c->x = c->mon->mx + c->mon->mw - WIDTH(c);
           43 @@ -1528,6 +1531,23 @@ setlayout(const Arg *arg)
           44                  drawbar(selmon);
           45  }
           46  
           47 +void setcfact(const Arg *arg) {
           48 +        float f;
           49 +        Client *c;
           50 +
           51 +        c = selmon->sel;
           52 +
           53 +        if(!arg || !c || !selmon->lt[selmon->sellt]->arrange)
           54 +                return;
           55 +        f = arg->f + c->cfact;
           56 +        if(arg->f == 0.0)
           57 +                f = 1.0;
           58 +        else if(f < 0.25 || f > 4.0)
           59 +                return;
           60 +        c->cfact = f;
           61 +        arrange(selmon);
           62 +}
           63 +
           64  /* arg > 1.0 will set mfact absolutly */
           65  void
           66  setmfact(const Arg *arg)
           67 @@ -1667,9 +1687,15 @@ void
           68  tile(Monitor *m)
           69  {
           70          unsigned int i, n, h, mw, my, ty;
           71 +        float mfacts = 0, sfacts = 0;
           72          Client *c;
           73  
           74 -        for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
           75 +        for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
           76 +                if (n < m->nmaster)
           77 +                        mfacts += c->cfact;
           78 +                else
           79 +                        sfacts += c->cfact;
           80 +        }
           81          if (n == 0)
           82                  return;
           83  
           84 @@ -1679,13 +1705,15 @@ tile(Monitor *m)
           85                  mw = m->ww;
           86          for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
           87                  if (i < m->nmaster) {
           88 -                        h = (m->wh - my) / (MIN(n, m->nmaster) - i);
           89 +                        h = (m->wh - my) * (c->cfact / mfacts);
           90                          resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
           91                          my += HEIGHT(c);
           92 +                        mfacts -= c->cfact;
           93                  } else {
           94 -                        h = (m->wh - ty) / (n - i);
           95 +                        h = (m->wh - ty) * (c->cfact / sfacts);
           96                          resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
           97                          ty += HEIGHT(c);
           98 +                        sfacts -= c->cfact;
           99                  }
          100  }
          101