[raw] [dotfiles.tar.gz]
   1 #include <X11/Xresource.h>
   2 
   3 const int borderpx = 2;
   4 const char *fonts[] = { "Terminus:size=9" };
   5 
   6 const int topbar  = 1;
   7 const int showbar = 1;
   8 const int barheight = 26;
   9 const char *tags[] = { " www ", " dev ", " etc ", " tmp " };
  10 
  11 const int snap = 32;
  12 const int nmaster = 1;
  13 const float mfact = 0.55;
  14 const int resizehints = 1;
  15 
  16 int enablegaps = 1;
  17 const int padding = 300;
  18 const int gapsinner = 15;
  19 const int gapsouter = 30;
  20 
  21 const Rule rules[] = {
  22     { "Wine", NULL, NULL, 0, 1, -1 },
  23 };
  24 
  25 void vanitygaps(Monitor *m);
  26 void togglegaps(const Arg *arg);
  27 
  28 // Colors {{{
  29 
  30 char n_bgcolor[] = "#222222";
  31 char n_fgcolor[] = "#bbbbbb";
  32 char n_bordercolor[] = "#444444";
  33 
  34 char s_bgcolor[] = "#005577";
  35 char s_fgcolor[] = "#eeeeee";
  36 char s_bordercolor[] = "#005577";
  37 
  38 const char *colors[][3] = {
  39     [SchemeNorm] = { n_fgcolor, n_bgcolor, n_bordercolor },
  40     [SchemeSel]  = { s_fgcolor, s_bgcolor, s_bordercolor },
  41 };
  42 
  43 // }}}
  44 // Layouts {{{
  45 
  46 void ptile(Monitor *m){ // {{{
  47     int n;
  48     Client *c;
  49 
  50     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
  51     for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
  52         c->bw = (n > 1 ? borderpx : 0);
  53 
  54     // tile(m);
  55     vanitygaps(m);
  56 } // }}}
  57 void bmono(Monitor *m){ // {{{
  58     for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next))
  59         c->bw = 0;
  60 
  61     monocle(m);
  62 } // }}}
  63 
  64 const Layout layouts[] = {
  65     { "[]=", ptile },
  66     { "><>", NULL  },
  67     { "[M]", bmono },
  68 };
  69 
  70 // }}}
  71 // Keys {{{
  72 
  73 #define Mod1 Mod1Mask
  74 #define Mod1Shft Mod1Mask|ShiftMask
  75 
  76 #define Mod4 Mod4Mask
  77 #define Mod4Shft Mod4Mask|ShiftMask
  78 #define Mod4Ctrl Mod4Mask|ControlMask
  79 
  80 #define TAG(key, n) \
  81     { Mod4,     key, view,       {.ui = 1 << n} }, \
  82     { Mod4Shft, key, tag,        {.ui = 1 << n} }, \
  83     { Mod4Ctrl, key, toggleview, {.ui = 1 << n} }
  84 
  85 Button buttons[] = {
  86     { ClkTagBar, 0, Button1, view,       {0} },
  87     { ClkTagBar, 0, Button3, toggleview, {0} },
  88 
  89     { ClkTagBar, Mod4, Button1, tag,       {0} },
  90     { ClkTagBar, Mod4, Button3, toggletag, {0} },
  91 
  92     { ClkLtSymbol, 0, Button1, setlayout, {.v = &layouts[0]} },
  93     { ClkLtSymbol, 0, Button2, setlayout, {.v = &layouts[1]} },
  94     { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
  95 
  96     { ClkClientWin, Mod4, Button1, movemouse,   {0} },
  97     { ClkClientWin, Mod4, Button3, resizemouse, {0} },
  98 };
  99 
 100 Key keys[] = {
 101     { Mod4,     XK_q,      killclient,     {0} },
 102     { Mod4,     XK_Return, zoom,           {0} },
 103     { Mod4Ctrl, XK_f,      togglefloating, {0} },
 104 
 105     { Mod1,     XK_Tab, focusstack, {.i = +1 } },
 106     { Mod1Shft, XK_Tab, focusstack, {.i = -1 } },
 107 
 108     { Mod4, XK_Up,    focusstack, {.i = -1 } },
 109     { Mod4, XK_Down,  focusstack, {.i = +1 } },
 110     { Mod4, XK_Left,  focusstack, {.i = -1 } },
 111     { Mod4, XK_Right, focusstack, {.i = +1 } },
 112 
 113     { Mod4Ctrl, XK_Left,  setmfact, {.f = -0.05} },
 114     { Mod4Ctrl, XK_Right, setmfact, {.f = +0.05} },
 115 
 116     { Mod4Ctrl, XK_i, incnmaster, {.i = +1 } },
 117     { Mod4Ctrl, XK_d, incnmaster, {.i = -1 } },
 118 
 119     { Mod4Ctrl, XK_t, setlayout,  {.v = &layouts[0]} },
 120     { Mod4Ctrl, XK_m, setlayout,  {.v = &layouts[2]} },
 121     { Mod4Ctrl, XK_g, togglegaps, {0} },
 122 
 123     { Mod4, XK_Tab, view, {0} },
 124     TAG(XK_1, 0),  TAG(XK_2, 1),
 125     TAG(XK_3, 2),  TAG(XK_4, 3),
 126 };
 127 
 128 // }}}
 129 // Signals {{{
 130 
 131 int sighup = 0;
 132 
 133 void xrdb(){ // {{{
 134     void *xres, *xrdb;
 135     char *type; XrmValue value;
 136 
 137     if (
 138         (xres = XResourceManagerString(dpy)) == NULL ||
 139         (xrdb = XrmGetStringDatabase(xres)) == NULL
 140     )
 141         return;
 142 
 143     if (XrmGetResource(xrdb, "background", NULL, &type, &value) == True){
 144         strcpy(s_fgcolor, value.addr);
 145         strcpy(n_bgcolor, value.addr);
 146         strcpy(n_bordercolor, value.addr);
 147     }
 148 
 149     if (XrmGetResource(xrdb, "foreground", NULL, &type, &value) == True){
 150         strcpy(n_fgcolor, value.addr);
 151         strcpy(s_bgcolor, value.addr);
 152         strcpy(s_bordercolor, value.addr);
 153     }
 154 
 155 } // }}}
 156 void signals(int sig){ // {{{
 157     sighup  = sig == SIGHUP;
 158     running = !sighup;
 159 } // }}}
 160 
 161 __attribute__((constructor)) void _main(){
 162     dpy = XOpenDisplay(NULL);
 163 
 164     xrdb();
 165     signal(SIGHUP, signals);
 166 
 167     memset(stext, ' ', 180);
 168     XStoreName(dpy, DefaultRootWindow(dpy), stext);
 169 
 170     XCloseDisplay(dpy);
 171 }
 172 
 173 __attribute__((destructor)) void main_(){
 174     if (!sighup)
 175         return;
 176 
 177     char *argv[] = { "dwm", NULL };
 178     execvp(argv[0], argv);
 179 }
 180 
 181 // }}}
 182 // Vanitygaps {{{
 183 // https://dwm.suckless.org/patches/vanitygaps/
 184 
 185 void vanitygaps(Monitor *m){
 186     unsigned int i, n, h, r, oe = enablegaps, ie = enablegaps, mw, my, ty;
 187     Client *c;
 188 
 189     int gappih, gappiv, gappoh, gappov;
 190     gappih = gappiv = gapsinner;
 191     gappoh = gappov = gapsouter;
 192 
 193     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
 194     if (n == 0)
 195         return;
 196     else if (n == 1)
 197         gappov = padding;
 198 
 199     if (n > m->nmaster)
 200         mw = m->nmaster ? (m->ww + gappiv*ie) * m->mfact : 0;
 201     else
 202         mw = m->ww - 2*gappov*oe + gappiv*ie;
 203     for (i = 0, my = ty = gappoh*oe, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
 204         if (i < m->nmaster) {
 205             r = MIN(n, m->nmaster) - i;
 206             h = (m->wh - my - gappoh*oe - gappih*ie * (r - 1)) / r;
 207             resize(c, m->wx + gappov*oe, m->wy + my, mw - (2*c->bw) - gappiv*ie, h - (2*c->bw), 0);
 208             my += HEIGHT(c) + gappih*ie;
 209         } else {
 210             r = n - i;
 211             h = (m->wh - ty - gappoh*oe - gappih*ie * (r - 1)) / r;
 212             resize(c, m->wx + mw + gappov*oe, m->wy + ty, m->ww - mw - (2*c->bw) - 2*gappov*oe, h - (2*c->bw), 0);
 213             ty += HEIGHT(c) + gappih*ie;
 214         }
 215 }
 216 
 217 void togglegaps(const Arg *arg){
 218     enablegaps = !enablegaps;
 219     arrange(selmon);
 220 }
 221 
 222 // }}}
 223 
 224 char dmenumon[2] = "0";
 225 const char *dmenucmd[] = { "dmenu_run", NULL };