dwm

my fork of dwm
Index Commits Files Refs README LICENSE
patches/dwm-fullgaps-toggle-20200830.diff (4965B)
   1 diff --git a/config.def.h b/config.def.h
   2 index 1c0b587..b172f63 100644
   3 --- a/config.def.h
   4 +++ b/config.def.h
   5 @@ -2,6 +2,7 @@
   6  
   7  /* appearance */
   8  static const unsigned int borderpx  = 1;        /* border pixel of windows */
   9 +static const Gap default_gap        = {.isgap = 1, .realgap = 10, .gappx = 10};
  10  static const unsigned int snap      = 32;       /* snap pixel */
  11  static const int showbar            = 1;        /* 0 means no bar */
  12  static const int topbar             = 1;        /* 0 means bottom bar */
  13 @@ -84,6 +85,10 @@ static Key keys[] = {
  14      { MODKEY,                       XK_period, focusmon,       {.i = +1 } },
  15      { MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
  16      { MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
  17 +    { MODKEY,                       XK_minus,  setgaps,        {.i = -5 } },
  18 +    { MODKEY,                       XK_equal,  setgaps,        {.i = +5 } },
  19 +    { MODKEY|ShiftMask,             XK_minus,  setgaps,        {.i = GAP_RESET } },
  20 +    { MODKEY|ShiftMask,             XK_equal,  setgaps,        {.i = GAP_TOGGLE} },
  21      TAGKEYS(                        XK_1,                      0)
  22      TAGKEYS(                        XK_2,                      1)
  23      TAGKEYS(                        XK_3,                      2)
  24 diff --git a/dwm.c b/dwm.c
  25 index 664c527..25bc9b7 100644
  26 --- a/dwm.c
  27 +++ b/dwm.c
  28 @@ -57,6 +57,9 @@
  29  #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
  30  #define TEXTW(X)                (drw_fontset_getwidth(drw, (X)) + lrpad)
  31  
  32 +#define GAP_TOGGLE 100
  33 +#define GAP_RESET  0
  34 +
  35  /* enums */
  36  enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
  37  enum { SchemeNorm, SchemeSel }; /* color schemes */
  38 @@ -111,6 +114,12 @@ typedef struct {
  39      void (*arrange)(Monitor *);
  40  } Layout;
  41  
  42 +typedef struct {
  43 +    int isgap;
  44 +    int realgap;
  45 +    int gappx;
  46 +} Gap;
  47 +
  48  struct Monitor {
  49      char ltsymbol[16];
  50      float mfact;
  51 @@ -119,6 +128,7 @@ struct Monitor {
  52      int by;               /* bar geometry */
  53      int mx, my, mw, mh;   /* screen size */
  54      int wx, wy, ww, wh;   /* window area  */
  55 +    Gap *gap;
  56      unsigned int seltags;
  57      unsigned int sellt;
  58      unsigned int tagset[2];
  59 @@ -169,6 +179,7 @@ static void focus(Client *c);
  60  static void focusin(XEvent *e);
  61  static void focusmon(const Arg *arg);
  62  static void focusstack(const Arg *arg);
  63 +static void gap_copy(Gap *to, const Gap *from);
  64  static Atom getatomprop(Client *c, Atom prop);
  65  static int getrootptr(int *x, int *y);
  66  static long getstate(Window w);
  67 @@ -200,6 +211,7 @@ static void sendmon(Client *c, Monitor *m);
  68  static void setclientstate(Client *c, long state);
  69  static void setfocus(Client *c);
  70  static void setfullscreen(Client *c, int fullscreen);
  71 +static void setgaps(const Arg *arg);
  72  static void setlayout(const Arg *arg);
  73  static void setmfact(const Arg *arg);
  74  static void setup(void);
  75 @@ -639,6 +651,8 @@ createmon(void)
  76      m->nmaster = nmaster;
  77      m->showbar = showbar;
  78      m->topbar = topbar;
  79 +    m->gap = malloc(sizeof(Gap));
  80 +    gap_copy(m->gap, &default_gap);
  81      m->lt[0] = &layouts[0];
  82      m->lt[1] = &layouts[1 % LENGTH(layouts)];
  83      strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
  84 @@ -1498,6 +1512,35 @@ setfullscreen(Client *c, int fullscreen)
  85      }
  86  }
  87  
  88 +void
  89 +gap_copy(Gap *to, const Gap *from)
  90 +{
  91 +    to->isgap   = from->isgap;
  92 +    to->realgap = from->realgap;
  93 +    to->gappx   = from->gappx;
  94 +}
  95 +
  96 +void
  97 +setgaps(const Arg *arg)
  98 +{
  99 +    Gap *p = selmon->gap;
 100 +    switch(arg->i)
 101 +    {
 102 +        case GAP_TOGGLE:
 103 +            p->isgap = 1 - p->isgap;
 104 +            break;
 105 +        case GAP_RESET:
 106 +            gap_copy(p, &default_gap);
 107 +            break;
 108 +        default:
 109 +            p->realgap += arg->i;
 110 +            p->isgap = 1;
 111 +    }
 112 +    p->realgap = MAX(p->realgap, 0);
 113 +    p->gappx = p->realgap * p->isgap;
 114 +    arrange(selmon);
 115 +}
 116 +
 117  void
 118  setlayout(const Arg *arg)
 119  {
 120 @@ -1684,18 +1727,18 @@ tile(Monitor *m)
 121      if (n > m->nmaster)
 122          mw = m->nmaster ? m->ww * m->mfact : 0;
 123      else
 124 -        mw = m->ww;
 125 -    for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
 126 +        mw = m->ww - m->gap->gappx;
 127 +    for (i = 0, my = ty = m->gap->gappx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
 128          if (i < m->nmaster) {
 129 -            h = (m->wh - my) / (MIN(n, m->nmaster) - i);
 130 -            resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
 131 -            if (my + HEIGHT(c) < m->wh)
 132 -                my += HEIGHT(c);
 133 +            h = (m->wh - my) / (MIN(n, m->nmaster) - i) - m->gap->gappx;
 134 +            resize(c, m->wx + m->gap->gappx, m->wy + my, mw - (2*c->bw) - m->gap->gappx, h - (2*c->bw), 0);
 135 +            if (my + HEIGHT(c) + m->gap->gappx < m->wh)
 136 +                my += HEIGHT(c) + m->gap->gappx;
 137          } else {
 138 -            h = (m->wh - ty) / (n - i);
 139 -            resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
 140 -            if (ty + HEIGHT(c) < m->wh)
 141 -                ty += HEIGHT(c);
 142 +            h = (m->wh - ty) / (n - i) - m->gap->gappx;
 143 +            resize(c, m->wx + mw + m->gap->gappx, m->wy + ty, m->ww - mw - (2*c->bw) - 2*m->gap->gappx, h - (2*c->bw), 0);
 144 +            if (ty + HEIGHT(c) + m->gap->gappx < m->wh)
 145 +                ty += HEIGHT(c) + m->gap->gappx;
 146          }
 147  }
 148