[download]

config/dwm/config.h

   1 #include <X11/Xresource.h>
   2 
   3 void signals(int);
   4 void movestack(const Arg*);
   5 void togglefullscreen(const Arg*);
   6 
   7 void vanitygaps(Monitor*);
   8 void gaplessgrid(Monitor*);
   9 void centeredmaster(Monitor*);
  10 
  11 const int topbar  = 1;
  12 const int showbar = 1;
  13 const char *fonts[] = { "Terminus-9", "Emoji-9" };
  14 const char *tags[]  = { "www", "dev", "vid", "etc" };
  15 const Layout layouts[] = {
  16     { "[]= ", tile           },
  17     { "><> ", NULL           },
  18     { "[M] ", monocle        },
  19     { "||= ", vanitygaps     },
  20     { "=C= ", centeredmaster },
  21     { "### ", gaplessgrid    },
  22 };
  23 
  24 const int snap = 32;
  25 const int nmaster  = 1;
  26 const int borderpx = 2;
  27 const float mfact  = 0.55;
  28 const int resizehints = 1;
  29 
  30 char background[] = "#000000";
  31 char foreground[] = "#ffffff";
  32 const char *colors[][3] = { // {{{
  33     [SchemeNorm] = { foreground, background, background },
  34     [SchemeSel]  = { background, foreground, foreground },
  35 }; // }}}
  36 
  37 const Rule rules[] = {
  38     { "Wine",         NULL, NULL,       0 << 0, True, -1 },
  39     { "explorer.exe", NULL, NULL,       0 << 0, True, -1 },
  40     { NULL,           NULL, "Dropdown", 0 << 0, True, -1 },
  41 };
  42 
  43 int  sighup = 0;
  44 char dmenumon[] = "";
  45 char dmenucmd[] = "";
  46 
  47 #define Mod1  Mod1Mask
  48 #define Mod1s Mod1Mask|ShiftMask
  49 
  50 #define Mod4  Mod4Mask
  51 #define Mod4a Mod4Mask|Mod1Mask
  52 #define Mod4s Mod4Mask|ShiftMask
  53 #define Mod4c Mod4Mask|ControlMask
  54 
  55 #define TAG(key, n) \
  56     { Mod4,  key, view,       {.ui = 1 << (n - 1)} }, \
  57     { Mod4s, key, tag,        {.ui = 1 << (n - 1)} }, \
  58     { Mod4c, key, toggleview, {.ui = 1 << (n - 1)} }, \
  59     { Mod4a, key, toggletag,  {.ui = 1 << (n - 1)} }
  60 
  61 Button buttons[] = {
  62     { ClkTagBar, 0, Button1, view,       {0} },
  63     { ClkTagBar, 0, Button3, toggleview, {0} },
  64 
  65     { ClkTagBar, Mod4, Button1, tag,       {0} },
  66     { ClkTagBar, Mod4, Button3, toggletag, {0} },
  67 
  68     { ClkLtSymbol, 0, Button1, setlayout, {.v = &layouts[0]} },
  69     { ClkLtSymbol, 0, Button2, setlayout, {.v = &layouts[1]} },
  70     { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
  71 
  72     { ClkWinTitle, 0, Button1, zoom,       {0} },
  73     { ClkWinTitle, 0, Button2, killclient, {0} },
  74 
  75     { ClkClientWin, Mod4, Button1, movemouse,   {0} },
  76     { ClkClientWin, Mod4, Button2, killclient,  {0} },
  77     { ClkClientWin, Mod4, Button3, resizemouse, {0} },
  78 };
  79 
  80 Key keys[] = {
  81     { Mod4,  XK_q,      killclient,       {0} },
  82     { Mod4,  XK_z,      zoom,             {0} },
  83     { Mod4s, XK_z,      togglefullscreen, {0} },
  84     { Mod4,  XK_Return, togglefloating,   {0} },
  85 
  86     { Mod1,  XK_Tab, focusstack, {.i = +1} },
  87     { Mod1s, XK_Tab, focusstack, {.i = -1} },
  88 
  89     { Mod4, XK_Up,    focusstack, {.i = -1} },
  90     { Mod4, XK_Down,  focusstack, {.i = +1} },
  91     { Mod4, XK_Left,  focusstack, {.i = -1} },
  92     { Mod4, XK_Right, focusstack, {.i = +1} },
  93 
  94     { Mod4s, XK_Up,    movestack, {.i = -1} },
  95     { Mod4s, XK_Down,  movestack, {.i = +1} },
  96     { Mod4s, XK_Left,  movestack, {.i = -1} },
  97     { Mod4s, XK_Right, movestack, {.i = +1} },
  98 
  99     { Mod4c, XK_Left,  setmfact, {.f = -0.05} },
 100     { Mod4c, XK_Right, setmfact, {.f = +0.05} },
 101 
 102     { Mod4c, XK_i, incnmaster, {.i = +1} },
 103     { Mod4c, XK_o, incnmaster, {.i = -1} },
 104 
 105     { Mod4c, XK_t, setlayout, {.v = &layouts[0]} },
 106     { Mod4c, XK_f, setlayout, {.v = &layouts[1]} },
 107     { Mod4c, XK_z, setlayout, {.v = &layouts[2]} },
 108     { Mod4c, XK_v, setlayout, {.v = &layouts[3]} },
 109     { Mod4c, XK_c, setlayout, {.v = &layouts[4]} },
 110     { Mod4c, XK_g, setlayout, {.v = &layouts[5]} },
 111 
 112     { Mod4, XK_Tab, view, {0} },
 113     TAG(XK_1, 1),  TAG(XK_2, 2),
 114     TAG(XK_3, 3),  TAG(XK_4, 4),
 115 };
 116 
 117 __attribute__((constructor)) void _main(){ // {{{
 118     void *xres, *xrdb;
 119     char *type; XrmValue value;
 120 
 121     signal(SIGHUP, signals);
 122 
 123     if (
 124         !(dpy  = XOpenDisplay(NULL)) ||
 125         !(xres = XResourceManagerString(dpy)) ||
 126         !(xrdb = XrmGetStringDatabase(xres))
 127     ) return;
 128 
 129     if (XrmGetResource(xrdb, "Dwm.background", NULL, &type, &value))
 130         strcpy(background, value.addr);
 131 
 132     if (XrmGetResource(xrdb, "Dwm.foreground", NULL, &type, &value))
 133         strcpy(foreground, value.addr);
 134 
 135     XCloseDisplay(dpy);
 136 } // }}}
 137 __attribute__((destructor)) void main_(){ // {{{
 138     if (sighup) execlp("dwm", "dwm", NULL);
 139 } // }}}
 140 
 141 void signals(int sig){ // {{{
 142     sighup  = sig == SIGHUP;
 143     running = !sighup;
 144 } // }}}
 145 void togglefullscreen(const Arg *arg){ // {{{
 146     if (selmon->sel) setfullscreen(selmon->sel, !selmon->sel->isfloating);
 147 } // }}}
 148 void movestack(const Arg *arg){ // https://dwm.suckless.org/patches/movestack/ {{{
 149     Client *c = NULL, *p = NULL, *pc = NULL, *i;
 150 
 151     if (arg->i > 0){
 152         /* find the client after selmon->sel */
 153         for (c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
 154         if (!c) for (c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
 155     } else {
 156         /* find the client before selmon->sel */
 157         for (i = selmon->clients; i != selmon->sel; i = i->next){
 158             if (ISVISIBLE(i) && !i->isfloating)
 159                 c = i;
 160         }
 161 
 162         if (!c){
 163             for(; i; i = i->next)
 164                 if (ISVISIBLE(i) && !i->isfloating)
 165                     c = i;
 166         }
 167     }
 168 
 169     /* find the client before selmon->sel and c */
 170     for (i = selmon->clients; i && (!p || !pc); i = i->next){
 171         if (i->next == selmon->sel)
 172             p = i;
 173 
 174         if (i->next == c)
 175             pc = i;
 176     }
 177 
 178     /* swap c and selmon->sel selmon->clients in the selmon->clients list */
 179     if (c && c != selmon->sel){
 180         Client *temp = selmon->sel->next == c ? selmon->sel : selmon->sel->next;
 181         selmon->sel->next = c->next == selmon->sel ? c : c->next;
 182         c->next = temp;
 183 
 184         if (p && p != c)
 185             p->next = c;
 186 
 187         if (pc && pc != selmon->sel)
 188             pc->next = selmon->sel;
 189 
 190         if (selmon->sel == selmon->clients)
 191             selmon->clients = c;
 192         else if (c == selmon->clients)
 193             selmon->clients = selmon->sel;
 194 
 195         arrange(selmon);
 196     }
 197 } // }}}
 198 
 199 void vanitygaps(Monitor *m){ // https://dwm.suckless.org/patches/vanitygaps/ {{{
 200     int gappih = 15;
 201     int gappiv = 15;
 202     int gappoh = (m->mw / 12.8);
 203     int gappov = (m->mw / 12.8);
 204 
 205     unsigned int i, n, h, r, oe = 1, ie = 1, mw, my, ty;
 206     Client *c;
 207 
 208     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
 209     if (n == 0) return;
 210     else if (n == 1) gappov = (m->mw / 6.4);
 211 
 212     if (n > m->nmaster)
 213         mw = m->nmaster ? (m->ww + gappiv*ie) * m->mfact : 0;
 214     else
 215         mw = m->ww - 2*gappov*oe + gappiv*ie;
 216 
 217     for (i = 0, my = ty = gappoh*oe, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
 218         if (i < m->nmaster){
 219             r = MIN(n, m->nmaster) - i;
 220             h = (m->wh - my - gappoh*oe - gappih*ie * (r - 1)) / r;
 221             resize(c, m->wx + gappov*oe, m->wy + my, mw - (2*c->bw) - gappiv*ie, h - (2*c->bw), 0);
 222             if (my + HEIGHT(c) + gappih*ie < m->wh) my += HEIGHT(c) + gappih*ie;
 223         } else {
 224             r = n - i;
 225             h = (m->wh - ty - gappoh*oe - gappih*ie * (r - 1)) / r;
 226             resize(c, m->wx + mw + gappov*oe, m->wy + ty, m->ww - mw - (2*c->bw) - 2*gappov*oe, h - (2*c->bw), 0);
 227             if (ty + HEIGHT(c) + gappih*ie < m->wh) ty += HEIGHT(c) + gappih*ie;
 228         }
 229 } // }}}
 230 void centeredmaster(Monitor *m){ // https://dwm.suckless.org/patches/centeredmaster/ {{{
 231     unsigned int i, n, h, mw, mx, my, oty, ety, tw;
 232     Client *c;
 233 
 234     /* count number of clients in the selected monitor */
 235     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
 236     if (n == 0) return;
 237 
 238     /* initialize areas */
 239     mw = m->ww;
 240     mx = 0;
 241     my = 0;
 242     tw = mw;
 243 
 244     if (n > m->nmaster) {
 245         /* go mfact box in the center if more than nmaster clients */
 246         mw = m->nmaster ? m->ww * m->mfact : 0;
 247         tw = m->ww - mw;
 248 
 249         if (n - m->nmaster > 1) {
 250             /* only one client */
 251             mx = (m->ww - mw) / 2;
 252             tw = (m->ww - mw) / 2;
 253         }
 254     }
 255 
 256     oty = 0;
 257     ety = 0;
 258 
 259     for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
 260         if (i < m->nmaster){
 261             /* nmaster clients are stacked vertically, in the center
 262              * of the screen */
 263             h = (m->wh - my) / (MIN(n, m->nmaster) - i);
 264             resize(c, m->wx + mx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
 265             my += HEIGHT(c);
 266         } else {
 267             /* stack clients are stacked vertically */
 268             if ((i - m->nmaster) % 2 ){
 269                 h = (m->wh - ety) / ((1 + n - i) / 2);
 270                 resize(c, m->wx, m->wy + ety, tw - (2*c->bw), h - (2*c->bw), 0);
 271                 ety += HEIGHT(c);
 272             } else {
 273                 h = (m->wh - oty) / ((1 + n - i) / 2);
 274                 resize(c, m->wx + mx + mw, m->wy + oty, tw - (2*c->bw), h - (2*c->bw), 0);
 275                 oty += HEIGHT(c);
 276             }
 277         }
 278 } // }}}
 279 void gaplessgrid(Monitor *m){ // https://dwm.suckless.org/patches/gaplessgrid/ {{{
 280     unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
 281     Client *c;
 282 
 283     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
 284     if (n == 0) return;
 285 
 286     /* grid dimensions */
 287     for (cols = 0; cols <= n / 2; cols++)
 288         if (cols*cols >= n)
 289             break;
 290 
 291     if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
 292         cols = 2;
 293 
 294     rows = n/cols;
 295 
 296     /* window geometries */
 297     cw = cols ? m->ww / cols : m->ww;
 298     cn = 0; /* current column number */
 299     rn = 0; /* current row number */
 300 
 301     for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)){
 302         if (i / rows + 1 > cols - n % cols)
 303             rows = n / cols + 1;
 304 
 305         ch = rows ? m->wh / rows : m->wh;
 306         cx = m->wx + cn*cw;
 307         cy = m->wy + rn*ch;
 308         resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False);
 309         rn++;
 310 
 311         if (rn >= rows) {
 312             rn = 0;
 313             cn++;
 314         }
 315     }
 316 } // }}}