[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", "doc", "srv", "alt", "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),
 126     TAG(XK_3, 3),  TAG(XK_4, 4),
 127     TAG(XK_5, 5),  TAG(XK_6, 6),
 128 
 129     { Mod4,  XK_0, view, { .ui = ~0 } },
 130     { Mod4a, XK_0, tag,  { .ui = ~0 } },
 131     { Mod4c, XK_F5, reloadxrdb, { 0 } },
 132 };
 133 
 134 __attribute__((constructor)) void _main(){
 135     xrdb();
 136     signal(SIGHUP, signals);
 137 }
 138 
 139 __attribute__((destructor)) void main_(){
 140     if (sighup) execlp("dwm", "dwm", NULL);
 141 }
 142 
 143 void xrdb(){ // {{{
 144     Display *dpy;
 145     char *res;  XrmDatabase db;
 146     char *type; XrmValue value;
 147 
 148     if (
 149         !(dpy = XOpenDisplay(NULL)) ||
 150         !(res = XResourceManagerString(dpy)) ||
 151         !(db  = XrmGetStringDatabase(res))
 152     ) return;
 153 
 154     if (XrmGetResource(db, "Dwm.background", NULL, &type, &value))
 155         strcpy(background, value.addr);
 156 
 157     if (XrmGetResource(db, "Dwm.foreground", NULL, &type, &value))
 158         strcpy(foreground, value.addr);
 159 
 160     XCloseDisplay(dpy);
 161 } // }}}
 162 void reloadxrdb(const Arg *arg){ // {{{
 163     xrdb();
 164 
 165     for (int i = 0; i < LENGTH(colors); i++)
 166         scheme[i] = drw_scm_create(drw, colors[i], 3);
 167 
 168     focus(NULL);
 169     arrange(NULL);
 170 } // }}}
 171 
 172 void signals(int sig){ // {{{
 173     sighup  = sig == SIGHUP;
 174     running = !sighup;
 175 } // }}}
 176 void togglefullscreen(const Arg *arg){ // {{{
 177     if (selmon->sel) setfullscreen(selmon->sel, !selmon->sel->isfullscreen);
 178 } // }}}
 179 void movestack(const Arg *arg){ // {{{
 180     Client *c = NULL, *p = NULL, *pc = NULL, *i;
 181 
 182     if (arg->i > 0){
 183         /* find the client after selmon->sel */
 184         for (c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
 185         if (!c) for (c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
 186     } else {
 187         /* find the client before selmon->sel */
 188         for (i = selmon->clients; i != selmon->sel; i = i->next){
 189             if (ISVISIBLE(i) && !i->isfloating)
 190                 c = i;
 191         }
 192 
 193         if (!c){
 194             for(; i; i = i->next)
 195                 if (ISVISIBLE(i) && !i->isfloating)
 196                     c = i;
 197         }
 198     }
 199 
 200     /* find the client before selmon->sel and c */
 201     for (i = selmon->clients; i && (!p || !pc); i = i->next){
 202         if (i->next == selmon->sel)
 203             p = i;
 204 
 205         if (i->next == c)
 206             pc = i;
 207     }
 208 
 209     /* swap c and selmon->sel selmon->clients in the selmon->clients list */
 210     if (c && c != selmon->sel){
 211         Client *temp = selmon->sel->next == c ? selmon->sel : selmon->sel->next;
 212         selmon->sel->next = c->next == selmon->sel ? c : c->next;
 213         c->next = temp;
 214 
 215         if (p && p != c)
 216             p->next = c;
 217 
 218         if (pc && pc != selmon->sel)
 219             pc->next = selmon->sel;
 220 
 221         if (selmon->sel == selmon->clients)
 222             selmon->clients = c;
 223         else if (c == selmon->clients)
 224             selmon->clients = selmon->sel;
 225 
 226         arrange(selmon);
 227     }
 228 } // }}}
 229 
 230 void vanitygaps(Monitor *m){ // {{{
 231     unsigned int i, n, h, r, oe = 1, ie = 1, mw, my, ty;
 232     Client *c;
 233 
 234     int gappih = 15;
 235     int gappiv = 15;
 236     int gappoh = (m->mh /  8.0);
 237     int gappov = (m->mw / 12.8);
 238 
 239     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
 240     if (n == 0) return;
 241     if (n == 1) gappov *= 2;
 242 
 243     if (n > m->nmaster)
 244         mw = m->nmaster ? (m->ww + gappiv*ie) * m->mfact : 0;
 245     else
 246         mw = m->ww - 2*gappov*oe + gappiv*ie;
 247 
 248     for (i = 0, my = ty = gappoh*oe, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
 249         if (i < m->nmaster){
 250             r = MIN(n, m->nmaster) - i;
 251             h = (m->wh - my - gappoh*oe - gappih*ie * (r - 1)) / r;
 252             resize(c, m->wx + gappov*oe, m->wy + my, mw - (2*c->bw) - gappiv*ie, h - (2*c->bw), 0);
 253             if (my + HEIGHT(c) + gappih*ie < m->wh) my += HEIGHT(c) + gappih*ie;
 254         } else {
 255             r = n - i;
 256             h = (m->wh - ty - gappoh*oe - gappih*ie * (r - 1)) / r;
 257             resize(c, m->wx + mw + gappov*oe, m->wy + ty, m->ww - mw - (2*c->bw) - 2*gappov*oe, h - (2*c->bw), 0);
 258             if (ty + HEIGHT(c) + gappih*ie < m->wh) ty += HEIGHT(c) + gappih*ie;
 259         }
 260 } // }}}
 261 void centeredmaster(Monitor *m){ // {{{
 262     unsigned int i, n, h, mw, mx, my, oty, ety, tw;
 263     Client *c;
 264 
 265     /* count number of clients in the selected monitor */
 266     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
 267     if (n == 0) return;
 268 
 269     /* initialize areas */
 270     mw = m->ww;
 271     mx = 0;
 272     my = 0;
 273     tw = mw;
 274 
 275     if (n > m->nmaster) {
 276         /* go mfact box in the center if more than nmaster clients */
 277         mw = m->nmaster ? m->ww * m->mfact : 0;
 278         tw = m->ww - mw;
 279 
 280         if (n - m->nmaster > 1) {
 281             /* only one client */
 282             mx = (m->ww - mw) / 2;
 283             tw = (m->ww - mw) / 2;
 284         }
 285     }
 286 
 287     oty = 0;
 288     ety = 0;
 289 
 290     for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
 291         if (i < m->nmaster){
 292             /* nmaster clients are stacked vertically, in the center
 293              * of the screen */
 294             h = (m->wh - my) / (MIN(n, m->nmaster) - i);
 295             resize(c, m->wx + mx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
 296             my += HEIGHT(c);
 297         } else {
 298             /* stack clients are stacked vertically */
 299             if ((i - m->nmaster) % 2 ){
 300                 h = (m->wh - ety) / ((1 + n - i) / 2);
 301                 resize(c, m->wx, m->wy + ety, tw - (2*c->bw), h - (2*c->bw), 0);
 302                 ety += HEIGHT(c);
 303             } else {
 304                 h = (m->wh - oty) / ((1 + n - i) / 2);
 305                 resize(c, m->wx + mx + mw, m->wy + oty, tw - (2*c->bw), h - (2*c->bw), 0);
 306                 oty += HEIGHT(c);
 307             }
 308         }
 309 } // }}}
 310 void gaplessgrid(Monitor *m){ // {{{
 311     unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
 312     Client *c;
 313 
 314     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
 315     if (n == 0) return;
 316 
 317     /* grid dimensions */
 318     for (cols = 0; cols <= n / 2; cols++)
 319         if (cols*cols >= n)
 320             break;
 321 
 322     if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
 323         cols = 2;
 324 
 325     rows = n/cols;
 326 
 327     /* window geometries */
 328     cw = cols ? m->ww / cols : m->ww;
 329     cn = 0; /* current column number */
 330     rn = 0; /* current row number */
 331 
 332     for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)){
 333         if (i / rows + 1 > cols - n % cols)
 334             rows = n / cols + 1;
 335 
 336         ch = rows ? m->wh / rows : m->wh;
 337         cx = m->wx + cn*cw;
 338         cy = m->wy + rn*ch;
 339         resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False);
 340         rn++;
 341 
 342         if (rn >= rows) {
 343             rn = 0;
 344             cn++;
 345         }
 346     }
 347 } // }}}
 348 void deck(Monitor *m){ // {{{
 349     unsigned int i, n, h, mw, my;
 350     Client *c;
 351 
 352     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
 353     if (n == 0) return;
 354 
 355     if (n > m->nmaster){
 356         mw = m->nmaster ? m->ww * m->mfact : 0;
 357         snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n - m->nmaster);
 358     } else {
 359         mw = m->ww;
 360     }
 361 
 362     for(i = my = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
 363         if (i < m->nmaster) {
 364             h = (m->wh - my) / (MIN(n, m->nmaster) - i);
 365             resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), False);
 366             my += HEIGHT(c);
 367         } else {
 368             resize(c, m->wx + mw, m->wy, m->ww - mw - (2*c->bw), m->wh - (2*c->bw), False);
 369         }
 370 } // }}}