[download]

local/src/dwm/config.h

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