[download]

local/src/dwm/config.h

   1 #include <X11/Xresource.h> // {{{
   2 
   3 void shifttag(const Arg*);
   4 void shiftview(const Arg*);
   5 void movestack(const Arg*);
   6 void reloadxrdb(const Arg*);
   7 void resetmfact(const Arg*);
   8 void cyclelayout(const Arg*);
   9 void togglefullscreen(const Arg*);
  10 
  11 void deck(Monitor*);
  12 void vanitygaps(Monitor*);
  13 void gaplessgrid(Monitor*);
  14 void centeredmaster(Monitor*);
  15 
  16 char dmenumon[] = "";
  17 char dmenucmd[] = "";
  18 
  19 // }}}
  20 
  21 const int topbar  = 1;
  22 const int showbar = 1;
  23 const char *fonts[] = { "Terminus-9", "Emoji-9", "Nerdfont-9" };
  24 const char *tags[]  = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
  25 const Layout layouts[] = { // {{{
  26     { "[]= ", tile           },
  27     { "[D] ", deck           },
  28     { "[M] ", monocle        },
  29     { "=C= ", centeredmaster },
  30     { "### ", gaplessgrid    },
  31     { "||= ", vanitygaps     },
  32     { "><> ", NULL           },
  33 }; // }}}
  34 
  35 const int snap = 32;
  36 const int nmaster  = 1;
  37 const int borderpx = 2;
  38 const float mfact  = 0.55;
  39 const int resizehints = 1;
  40 const int lockfullscreen = 1;
  41 const Rule rules[] = { // {{{
  42     { NULL,           NULL, "Dropdown", 0 << 0, True, -1 },
  43     { "explorer.exe", NULL, NULL,       0 << 0, True, -1 },
  44     { "Xfce4-settin", NULL, NULL,       0 << 0, True, -1 },
  45     { "Xfce4-appfin", NULL, NULL,       0 << 0, True, -1 },
  46 }; // }}}
  47 
  48 char background[] = "#000000";
  49 char foreground[] = "#ffffff";
  50 const char *colors[][3] = { // {{{
  51     [SchemeNorm] = { foreground, background, background },
  52     [SchemeSel]  = { background, foreground, foreground },
  53 }; // }}}
  54 
  55 #define Mod1  Mod1Mask
  56 #define Mod1s Mod1Mask|ShiftMask
  57 
  58 #define Mod4  Mod4Mask
  59 #define Mod4a Mod4Mask|Mod1Mask
  60 #define Mod4s Mod4Mask|ShiftMask
  61 #define Mod4c Mod4Mask|ControlMask
  62 
  63 #define TAG(key, n) \
  64     { Mod4,  key, view,       { .ui = 1 << (n - 1) } }, \
  65     { Mod4s, key, tag,        { .ui = 1 << (n - 1) } }, \
  66     { Mod4c, key, toggleview, { .ui = 1 << (n - 1) } }, \
  67     { Mod4a, key, toggletag,  { .ui = 1 << (n - 1) } }
  68 
  69 Button buttons[] = {
  70     { ClkTagBar, 0,    Button1, view,       { 0 } },
  71     { ClkTagBar, 0,    Button3, toggleview, { 0 } },
  72     { ClkTagBar, Mod4, Button1, tag,        { 0 } },
  73     { ClkTagBar, Mod4, Button3, toggletag,  { 0 } },
  74     { ClkTagBar, 0,    Button4, shiftview,  { .i = -1 } },
  75     { ClkTagBar, 0,    Button5, shiftview,  { .i = +1 } },
  76 
  77     { ClkLtSymbol, 0, Button1, setlayout,   { .v = &layouts[0] } },
  78     { ClkLtSymbol, 0, Button2, setlayout,   { .v = &layouts[6] } },
  79     { ClkLtSymbol, 0, Button3, setlayout,   { .v = &layouts[2] } },
  80     { ClkLtSymbol, 0, Button4, cyclelayout, { .i = -1 } },
  81     { ClkLtSymbol, 0, Button5, cyclelayout, { .i = +1 } },
  82 
  83 #if AWESOMEBAR
  84     { ClkWinTitle, 0, Button1, togglewin, { 0 } },
  85     { ClkWinTitle, 0, Button2, killwin,   { 0 } },
  86     { ClkWinTitle, 0, Button3, zoomwin,   { 0 } },
  87 #endif
  88     { ClkWinTitle, 0, Button4, focusstack, { .i = -1 } },
  89     { ClkWinTitle, 0, Button5, focusstack, { .i = +1 } },
  90 
  91     { ClkClientWin, Mod4, Button1, movemouse,   { 0 } },
  92     { ClkClientWin, Mod4, Button2, killclient,  { 0 } },
  93     { ClkClientWin, Mod4, Button3, resizemouse, { 0 } },
  94 };
  95 
  96 Key keys[] = {
  97     { Mod4,  XK_q,     killclient,       { 0 } },
  98     { Mod4,  XK_z,     zoom,             { 0 } },
  99     { Mod4s, XK_z,     togglefullscreen, { 0 } },
 100     { Mod4s, XK_space, togglefloating,   { 0 } },
 101 
 102     { Mod1,  XK_Tab, focusstack, { .i = +1 } },
 103     { Mod1s, XK_Tab, focusstack, { .i = -1 } },
 104 
 105     { Mod4, XK_Up,    focusstack, { .i = -1 } },
 106     { Mod4, XK_Down,  focusstack, { .i = +1 } },
 107     { Mod4, XK_Left,  shiftview,  { .i = -1 } },
 108     { Mod4, XK_Right, shiftview,  { .i = +1 } },
 109 
 110     { Mod4s, XK_Up,    movestack, { .i = -1 } },
 111     { Mod4s, XK_Down,  movestack, { .i = +1 } },
 112     { Mod4s, XK_Left,  shifttag,  { .i = -1 } },
 113     { Mod4s, XK_Right, shifttag,  { .i = +1 } },
 114 
 115     { Mod4c, XK_minus, incnmaster, { .i = -1 } },
 116     { Mod4c, XK_equal, incnmaster, { .i = +1 } },
 117 
 118     { Mod4s, XK_0,     resetmfact, { .f =  0.00 } },
 119     { Mod4s, XK_minus, setmfact,   { .f = -0.05 } },
 120     { Mod4s, XK_equal, setmfact,   { .f = +0.05 } },
 121 
 122 #if CFACT
 123     { Mod4, XK_0,     setcfact, { .f =  0.00 } },
 124     { Mod4, XK_minus, setcfact, { .f = -0.25 } },
 125     { Mod4, XK_equal, setcfact, { .f = +0.25 } },
 126 #endif
 127 
 128     { Mod4c, XK_t, setlayout, { .v = &layouts[0] } },
 129     { Mod4c, XK_d, setlayout, { .v = &layouts[1] } },
 130     { Mod4c, XK_z, setlayout, { .v = &layouts[2] } },
 131     { Mod4c, XK_c, setlayout, { .v = &layouts[3] } },
 132     { Mod4c, XK_g, setlayout, { .v = &layouts[4] } },
 133     { Mod4c, XK_v, setlayout, { .v = &layouts[5] } },
 134     { Mod4c, XK_f, setlayout, { .v = &layouts[6] } },
 135 
 136     { Mod4, XK_Tab, view, { 0 } },
 137     TAG(XK_1, 1), TAG(XK_2, 2), TAG(XK_3, 3),
 138     TAG(XK_4, 4), TAG(XK_5, 5), TAG(XK_6, 6),
 139     TAG(XK_7, 7), TAG(XK_8, 8), TAG(XK_9, 9),
 140 
 141     { Mod4c, XK_0, view, { .ui = ~0 } },
 142     { Mod4a, XK_0, tag,  { .ui = ~0 } },
 143 
 144     { Mod4c, XK_b,  togglebar,  { 0 } },
 145     { Mod4,  XK_F5, reloadxrdb, { 0 } },
 146 };
 147 
 148 int sighup = 0;
 149 void xrdb(){ // {{{
 150     Display *dpy = XOpenDisplay(NULL);
 151 
 152     if (!dpy) return;
 153 
 154     char *xrm = XResourceManagerString(dpy);
 155     void *xdb = XrmGetStringDatabase(xrm);
 156 
 157     char *type;
 158     XrmValue value;
 159 
 160     if (XrmGetResource(xdb, "Dwm.background", NULL, &type, &value))
 161         strcpy(background, value.addr);
 162 
 163     if (XrmGetResource(xdb, "Dwm.foreground", NULL, &type, &value))
 164         strcpy(foreground, value.addr);
 165 
 166     XrmDestroyDatabase(xdb);
 167     XCloseDisplay(dpy);
 168 } // }}}
 169 void signals(int sig){ // {{{
 170     sighup  = sig == SIGHUP;
 171     running = !sighup;
 172 } // }}}
 173 __attribute__((constructor)) void _main(){ // {{{
 174     XrmInitialize();
 175     xrdb();
 176     signal(SIGHUP, signals);
 177 }
 178 
 179 __attribute__((destructor)) void main_(){
 180     if (sighup) execlp("dwm", "dwm", NULL);
 181 } // }}}
 182 
 183 void shifttag(const Arg *arg){ // {{{
 184     Arg shifted;
 185 
 186     if (arg->i > 0)
 187         shifted.ui = (selmon->tagset[selmon->seltags] << arg->i) |
 188         (selmon->tagset[selmon->seltags] >> (LENGTH(tags) - arg->i));
 189     else
 190         shifted.ui = selmon->tagset[selmon->seltags] >> (- arg->i) |
 191         selmon->tagset[selmon->seltags] << (LENGTH(tags) + arg->i);
 192 
 193     tag(&shifted);
 194     view(&shifted);
 195 } // }}}
 196 void shiftview(const Arg *arg){ // {{{
 197     Arg shifted;
 198 
 199     if (arg->i > 0)
 200         shifted.ui = (selmon->tagset[selmon->seltags] << arg->i) |
 201         (selmon->tagset[selmon->seltags] >> (LENGTH(tags) - arg->i));
 202     else
 203         shifted.ui = selmon->tagset[selmon->seltags] >> (- arg->i) |
 204         selmon->tagset[selmon->seltags] << (LENGTH(tags) + arg->i);
 205 
 206     view(&shifted);
 207 } // }}}
 208 void movestack(const Arg *arg){ // {{{
 209     Client *c = NULL, *p = NULL, *pc = NULL, *i;
 210 
 211     if (arg->i > 0){
 212         /* find the client after selmon->sel */
 213         for (c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
 214         if (!c) for (c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
 215     } else {
 216         /* find the client before selmon->sel */
 217         for (i = selmon->clients; i != selmon->sel; i = i->next){
 218             if (ISVISIBLE(i) && !i->isfloating)
 219                 c = i;
 220         }
 221 
 222         if (!c){
 223             for(; i; i = i->next)
 224                 if (ISVISIBLE(i) && !i->isfloating)
 225                     c = i;
 226         }
 227     }
 228 
 229     /* find the client before selmon->sel and c */
 230     for (i = selmon->clients; i && (!p || !pc); i = i->next){
 231         if (i->next == selmon->sel)
 232             p = i;
 233 
 234         if (i->next == c)
 235             pc = i;
 236     }
 237 
 238     /* swap c and selmon->sel selmon->clients in the selmon->clients list */
 239     if (c && c != selmon->sel){
 240         Client *temp = selmon->sel->next == c ? selmon->sel : selmon->sel->next;
 241         selmon->sel->next = c->next == selmon->sel ? c : c->next;
 242         c->next = temp;
 243 
 244         if (p && p != c)
 245             p->next = c;
 246 
 247         if (pc && pc != selmon->sel)
 248             pc->next = selmon->sel;
 249 
 250         if (selmon->sel == selmon->clients)
 251             selmon->clients = c;
 252         else if (c == selmon->clients)
 253             selmon->clients = selmon->sel;
 254 
 255         arrange(selmon);
 256     }
 257 } // }}}
 258 void reloadxrdb(const Arg *arg){ // {{{
 259     xrdb();
 260 
 261     for (int i = 0; i < LENGTH(colors); i++)
 262         scheme[i] = drw_scm_create(drw, colors[i], 3);
 263 
 264     focus(NULL);
 265     arrange(NULL);
 266 } // }}}
 267 void resetmfact(const Arg *arg){ // {{{
 268     if (!selmon->lt[selmon->sellt]->arrange)
 269         return;
 270 
 271     selmon->mfact = mfact;
 272     arrange(selmon);
 273 } // }}}
 274 void cyclelayout(const Arg *arg){ // {{{
 275     Arg a;
 276     Layout *l;
 277 
 278     for (l = (Layout *)layouts; l != selmon->lt[selmon->sellt]; l++);
 279 
 280     if (arg->i > 0)
 281         a.v = (l->symbol    && (l + 1)->symbol) ? (l + 1) : layouts;
 282     else
 283         a.v = (l != layouts && (l - 1)->symbol) ? (l - 1) : &layouts[LENGTH(layouts) - 1];
 284 
 285     setlayout(&a);
 286 } // }}}
 287 void togglefullscreen(const Arg *arg){ // {{{
 288     if (selmon->sel) setfullscreen(selmon->sel, !selmon->sel->isfullscreen);
 289 } // }}}
 290 
 291 void vanitygaps(Monitor *m){ // {{{
 292     unsigned int i, n, h, r, oe = 1, ie = 1, mw, my, ty;
 293     Client *c;
 294 
 295     int gappih = 15;
 296     int gappiv = 15;
 297     int gappoh = (m->mh /  8.0);
 298     int gappov = (m->mw / 12.8);
 299 
 300     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
 301     if (n == 0) return;
 302     if (n == 1) gappov *= 2;
 303 
 304 #if CFACT
 305     float mfacts = 0, sfacts = 0;
 306 
 307     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++){
 308         if (n < m->nmaster)
 309             mfacts += c->cfact;
 310         else
 311             sfacts += c->cfact;
 312     }
 313 #endif
 314 
 315     if (n > m->nmaster)
 316         mw = m->nmaster ? (m->ww + gappiv*ie) * m->mfact : 0;
 317     else
 318         mw = m->ww - 2*gappov*oe + gappiv*ie;
 319 
 320     for (i = 0, my = ty = gappoh*oe, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
 321         if (i < m->nmaster){
 322             r = MIN(n, m->nmaster) - i;
 323             h = (m->wh - my);
 324 #if CFACT
 325             h = (m->wh - my) * (c->cfact / mfacts);
 326             mfacts -= c->cfact;
 327 #endif
 328             h -= (gappoh*oe - gappih*ie * (r - 1)) / r;
 329             resize(c, m->wx + gappov*oe, m->wy + my, mw - (2*c->bw) - gappiv*ie, h - (2*c->bw), 0);
 330             if (my + HEIGHT(c) + gappih*ie < m->wh)
 331                 my += HEIGHT(c) + gappih*ie;
 332         } else {
 333             r = n - i;
 334             h = (m->wh - ty);
 335 #if CFACT
 336             h = (m->wh - ty) * (c->cfact / sfacts);
 337             sfacts -= c->cfact;
 338 #endif
 339             h -= (gappoh*oe - gappih*ie * (r - 1)) / r;
 340             resize(c, m->wx + mw + gappov*oe, m->wy + ty, m->ww - mw - (2*c->bw) - 2*gappov*oe, h - (2*c->bw), 0);
 341             if (ty + HEIGHT(c) + gappih*ie < m->wh)
 342                 ty += HEIGHT(c) + gappih*ie;
 343         }
 344 } // }}}
 345 void centeredmaster(Monitor *m){ // {{{
 346     unsigned int i, n, h, mw, mx, my, oty, ety, tw;
 347     Client *c;
 348 
 349     /* count number of clients in the selected monitor */
 350     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
 351     if (n == 0) return;
 352 
 353 #if CFACT
 354     float mfacts = 0, lfacts = 0, rfacts = 0;
 355 
 356     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++){
 357         if (n < m->nmaster)
 358             mfacts += c->cfact;
 359         else if ((n - m->nmaster) % 2)
 360             lfacts += c->cfact;
 361         else
 362             rfacts += c->cfact;
 363     }
 364 #endif
 365 
 366     /* initialize areas */
 367     mw = m->ww;
 368     mx = 0;
 369     my = 0;
 370     tw = mw;
 371 
 372     if (n > m->nmaster){
 373         /* go mfact box in the center if more than nmaster clients */
 374         mw = m->nmaster ? m->ww * m->mfact : 0;
 375         tw = m->ww - mw;
 376 
 377         if (n - m->nmaster > 1){
 378             /* only one client */
 379             mx = (m->ww - mw) / 2;
 380             tw = (m->ww - mw) / 2;
 381         }
 382     }
 383 
 384     oty = 0;
 385     ety = 0;
 386 
 387     for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
 388         if (i < m->nmaster){
 389             /* nmaster clients are stacked vertically, in the center
 390              * of the screen */
 391             h = (m->wh - my) / (MIN(n, m->nmaster) - i);
 392 #if CFACT
 393             h = (m->wh - my) * (c->cfact / mfacts);
 394             mfacts -= c->cfact;
 395 #endif
 396             resize(c, m->wx + mx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
 397             if (my + HEIGHT(c) < m->mh)
 398                 my += HEIGHT(c);
 399         } else {
 400             /* stack clients are stacked vertically */
 401             if ((i - m->nmaster) % 2 ){
 402                 h = (m->wh - ety) / ((1 + n - i) / 2);
 403 #if CFACT
 404                 h = (m->wh - ety) * (c->cfact / lfacts);
 405                 lfacts -= c->cfact;
 406 #endif
 407                 resize(c, m->wx, m->wy + ety, tw - (2*c->bw), h - (2*c->bw), 0);
 408                 if (ety + HEIGHT(c) < m->mh)
 409                     ety += HEIGHT(c);
 410             } else {
 411                 h = (m->wh - oty) / ((1 + n - i) / 2);
 412 #if CFACT
 413                 h = (m->wh - oty) * (c->cfact / rfacts);
 414                 rfacts -= c->cfact;
 415 #endif
 416                 resize(c, m->wx + mx + mw, m->wy + oty, tw - (2*c->bw), h - (2*c->bw), 0);
 417                 if (oty + HEIGHT(c) < m->mh)
 418                     oty += HEIGHT(c);
 419             }
 420         }
 421 } // }}}
 422 void gaplessgrid(Monitor *m){ // {{{
 423     unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
 424     Client *c;
 425 
 426     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
 427     if (n == 0) return;
 428 
 429     /* grid dimensions */
 430     for (cols = 0; cols <= n / 2; cols++)
 431         if (cols * cols >= n)
 432             break;
 433 
 434     if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
 435         cols = 2;
 436 
 437     rows = n / cols;
 438 
 439     /* window geometries */
 440     cw = cols ? m->ww / cols : m->ww;
 441     cn = 0; /* current column number */
 442     rn = 0; /* current row number */
 443 
 444     for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)){
 445         if (i / rows + 1 > cols - n % cols)
 446             rows = n / cols + 1;
 447 
 448         ch = rows ? m->wh / rows : m->wh;
 449         cx = m->wx + cn * cw;
 450         cy = m->wy + rn * ch;
 451         resize(c, cx, cy, cw - (2*c->bw), ch - (2*c->bw), False);
 452         rn++;
 453 
 454         if (rn >= rows){
 455             rn = 0;
 456             cn++;
 457         }
 458     }
 459 } // }}}
 460 void deck(Monitor *m){ // {{{
 461     unsigned int i, n, h, mw, my;
 462     Client *c;
 463 
 464     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
 465     if (n == 0) return;
 466 
 467 #if CFACT
 468     float mfacts = 0;
 469 
 470     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++){
 471         if (n < m->nmaster)
 472             mfacts += c->cfact;
 473     }
 474 #endif
 475 
 476     if (n > m->nmaster){
 477         mw = m->nmaster ? m->ww * m->mfact : 0;
 478         snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n - m->nmaster);
 479     } else {
 480         mw = m->ww;
 481     }
 482 
 483     for(i = my = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
 484         if (i < m->nmaster){
 485             h = (m->wh - my) / (MIN(n, m->nmaster) - i);
 486 #if CFACT
 487             h = (m->wh - my) * (c->cfact / mfacts);
 488             mfacts -= c->cfact;
 489 #endif
 490             resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), False);
 491             if (my + HEIGHT(c) < m->wh)
 492                 my += HEIGHT(c);
 493         } else {
 494             resize(c, m->wx + mw, m->wy, m->ww - mw - (2*c->bw), m->wh - (2*c->bw), False);
 495         }
 496 } // }}}