dwm-xtile-gaps-6.2.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dwm-xtile-gaps-6.2.diff (6257B)
       ---
            1 From 09e6db7a154c2dc3f6c5533ba3e33f460a8e21e1 Mon Sep 17 00:00:00 2001
            2 From: MLquest8 <miskuzius@gmail.com>
            3 Date: Mon, 15 Jun 2020 21:32:22 +0400
            4 Subject: [PATCH] gaps for xtile. Fully independent outer and inner gaps
            5  adjustable at runtime. Also includes a setting to disable gaps when only one
            6  window is open. For version 6.2
            7 
            8 ---
            9  config.def.h |  9 +++++++++
           10  dwm.c        | 55 ++++++++++++++++++++++++++++++++++++++++------------
           11  2 files changed, 52 insertions(+), 12 deletions(-)
           12 
           13 diff --git a/config.def.h b/config.def.h
           14 index 254e51c..91871de 100644
           15 --- a/config.def.h
           16 +++ b/config.def.h
           17 @@ -2,6 +2,9 @@
           18  
           19  /* appearance */
           20  static const unsigned int borderpx  = 1;        /* border pixel of windows */
           21 +static const unsigned int igappx    = 5;        /* size of inner gaps */
           22 +static const unsigned int ogappx    = 5;        /* size of outer gaps */
           23 +static const int gapsforone            = 0;        /* 1 enable gaps when only one window is open */
           24  static const unsigned int snap      = 32;       /* snap pixel */
           25  static const int showbar            = 1;        /* 0 means no bar */
           26  static const int topbar             = 1;        /* 0 means bottom bar */
           27 @@ -76,6 +79,12 @@ static Key keys[] = {
           28          { MODKEY,                       XK_Return, zoom,           {0} },
           29          { MODKEY,                       XK_Tab,    view,           {0} },
           30          { MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
           31 +        { MODKEY|ShiftMask,             XK_i,      setigaps,       {.i = +2 } },
           32 +        { MODKEY|ControlMask,           XK_i,      setigaps,       {.i = -2 } },
           33 +        { MODKEY|ShiftMask|ControlMask, XK_i,      setigaps,       {.i = 0  } },
           34 +        { MODKEY|ShiftMask,             XK_o,      setogaps,       {.i = +2 } },
           35 +        { MODKEY|ControlMask,           XK_o,      setogaps,       {.i = -2 } },
           36 +        { MODKEY|ShiftMask|ControlMask, XK_o,      setogaps,       {.i = 0  } },
           37          { MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
           38          { MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
           39          { MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
           40 diff --git a/dwm.c b/dwm.c
           41 index e43fbad..570739e 100644
           42 --- a/dwm.c
           43 +++ b/dwm.c
           44 @@ -130,6 +130,7 @@ struct Monitor {
           45          int by;               /* bar geometry */
           46          int mx, my, mw, mh;   /* screen size */
           47          int wx, wy, ww, wh;   /* window area  */
           48 +        int igappx, ogappx;   /* inner and outer gaps */
           49          unsigned int seltags;
           50          unsigned int sellt;
           51          unsigned int tagset[2];
           52 @@ -214,6 +215,8 @@ static void setdirs(const Arg *arg);
           53  static void setfacts(const Arg *arg);
           54  static void setfocus(Client *c);
           55  static void setfullscreen(Client *c, int fullscreen);
           56 +static void setigaps(const Arg *arg);
           57 +static void setogaps(const Arg *arg);
           58  static void setlayout(const Arg *arg);
           59  static void setup(void);
           60  static void seturgent(Client *c, int urg);
           61 @@ -666,6 +669,8 @@ createmon(void)
           62          m->nmaster = nmaster;
           63          m->showbar = showbar;
           64          m->topbar = topbar;
           65 +        m->igappx = igappx;
           66 +        m->ogappx = ogappx;
           67          m->lt[0] = &layouts[0];
           68          m->lt[1] = &layouts[1 % LENGTH(layouts)];
           69          strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
           70 @@ -1569,6 +1574,26 @@ setfullscreen(Client *c, int fullscreen)
           71          }
           72  }
           73  
           74 +void
           75 +setigaps(const Arg *arg)
           76 +{
           77 +        if ((arg->i == 0) || (selmon->igappx + arg->i < 0))
           78 +                selmon->igappx = 0;
           79 +        else
           80 +                selmon->igappx += arg->i;
           81 +        arrange(selmon);
           82 +}
           83 +
           84 +void
           85 +setogaps(const Arg *arg)
           86 +{
           87 +        if ((arg->i == 0) || (selmon->ogappx + arg->i < 0))
           88 +                selmon->ogappx = 0;
           89 +        else
           90 +                selmon->ogappx += arg->i;
           91 +        arrange(selmon);
           92 +}
           93 +
           94  void
           95  setlayout(const Arg *arg)
           96  {
           97 @@ -1733,7 +1758,7 @@ tile(Monitor *m)
           98          Client *c;
           99  
          100          Area *ga = m->pertag->areas[m->pertag->curtag], *ma = ga + 1, *sa = ga + 2, *a;
          101 -        unsigned int n, i, w, h, ms, ss;
          102 +        unsigned int n, i, w, h, g, ms, ss;
          103          float f;
          104   
          105          /* print layout symbols */
          106 @@ -1746,27 +1771,33 @@ tile(Monitor *m)
          107          for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
          108          if (n == 0)
          109                  return;
          110 +        if(n == 1 && gapsforone == 0){
          111 +                c = nexttiled(m->clients);
          112 +                resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
          113 +                return;
          114 +        }
          115  
          116          ma->n = MIN(n, m->nmaster), sa->n = n - ma->n;
          117          /* calculate area rectangles */
          118          f = ma->n == 0 ? 0 : (sa->n == 0 ? 1 : ga->fact / 2);
          119 +        g = ma->n == 0 || sa->n == 0 ? 0 : m->igappx;
          120          if(ga->dir == DirHor || ga->dir == DirRotHor)
          121 -                ms = f * m->ww, ss = m->ww - ms,
          122 -                ma->x = ga->dir == DirHor ? 0 : ss, ma->y = 0, ma->fx = ma->x + ms, ma->fy = m->wh,
          123 -                sa->x = ga->dir == DirHor ? ms : 0, sa->y = 0, sa->fx = sa->x + ss, sa->fy = m->wh;
          124 +                ms = f * (m->ww - g), ss = m->ww - ms - g,
          125 +                ma->x = ga->dir == DirHor ? 0 + m->ogappx : ss + g + m->ogappx, ma->y = 0 + m->ogappx, ma->fx = ma->x + ms - 2*m->ogappx, ma->fy = m->wh - m->ogappx,
          126 +                sa->x = ga->dir == DirHor ? ms + g - m->ogappx : 0 + m->ogappx, sa->y = 0 + m->ogappx, sa->fx = sa->x + ss, sa->fy = m->wh - m->ogappx;
          127          else
          128 -                ms = f * m->wh, ss = m->wh - ms,
          129 -                ma->x = 0, ma->y = ga->dir == DirVer ? 0 : ss, ma->fx = m->ww, ma->fy = ma->y + ms,
          130 -                sa->x = 0, sa->y = ga->dir == DirVer ? ms : 0, sa->fx = m->ww, sa->fy = sa->y + ss;
          131 +                ms = f * (m->wh - g), ss = m->wh - ms - g,
          132 +                ma->x = 0 + m->ogappx, ma->y = ga->dir == DirVer ? 0 + m->ogappx : ss + g + m->ogappx, ma->fx = m->ww - m->ogappx, ma->fy = ma->y + ms - 2*m->ogappx,
          133 +                sa->x = 0 + m->ogappx, sa->y = ga->dir == DirVer ? ms + g - m->ogappx : 0 + m->ogappx, sa->fx = m->ww - m->ogappx, sa->fy = sa->y + ss;
          134          /* tile clients */
          135          for(c = nexttiled(m->clients), i = 0; i < n; c = nexttiled(c->next), i++) {
          136                  a = ma->n > 0 ? ma : sa;
          137                  f = i == 0 || ma->n == 0 ? a->fact : 1, f /= --a->n + f;
          138 -                w = (a->dir == DirVer ? 1 : f) * (a->fx - a->x);
          139 -                h = (a->dir == DirHor ? 1 : f) * (a->fy - a->y);
          140 -                resize(c, m->wx + a->x, m->wy + a->y, w - 2 * c->bw, h - 2 * c->bw, False);
          141 -                a->x += a->dir == DirHor ? w : 0;
          142 -                a->y += a->dir == DirVer ? h : 0;
          143 +                w = a->dir == DirVer ? a->fx - a->x : f * (a->fx - a->x - a->n * m->igappx);
          144 +                h = a->dir == DirHor ? a->fy - a->y : f * (a->fy - a->y - a->n * m->igappx);;
          145 +                resize(c, m->wx + a->x, m->wy + a->y, w - 2 * c->bw, h - 2 * c->bw, 0);
          146 +                a->x += a->dir == DirHor ? w + m->igappx : 0;
          147 +                a->y += a->dir == DirVer ? h + m->igappx : 0;
          148          }
          149  }
          150  
          151 -- 
          152 2.26.2
          153