Skip to content

Instantly share code, notes, and snippets.

@ThinkChaos
Created December 30, 2013 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThinkChaos/8188122 to your computer and use it in GitHub Desktop.
Save ThinkChaos/8188122 to your computer and use it in GitHub Desktop.
DWM Quick setup
/* See LICENSE file for copyright and license details. */
/* appearance */
static const char font[] = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
static const char normbordercolor[] = "#444444";
static const char normbgcolor[] = "#222222";
static const char normfgcolor[] = "#bbbbbb";
static const char selbordercolor[] = "#005577";
static const char selbgcolor[] = "#005577";
static const char selfgcolor[] = "#eeeeee";
static const unsigned int borderpx = 1; /* border pixel of windows */
static const unsigned int snap = 8; /* snap pixel */
static const Bool showbar = True; /* False means no bar */
static const Bool topbar = True; /* False means bottom bar */
static const Bool viewontag = True; /* Switch view on tag switch */
/* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
static const Rule rules[] = {
/* class instance title tags mask isfloating monitor */
{ NULL, NULL, NULL, 0, False, -1 },
};
/* layout(s) */
static const float mfact = 0.70; /* factor of master area size [0.05..0.95] */
static const int nmaster = 1; /* number of clients in master area */
static const Bool resizehints = False; /* True means respect size hints in tiled resizals */
#include "bstack.c"
static const Layout layouts[] = {
/* symbol arrange function */
{ "TTT", bstack },
{ "[M]", monocle },
};
/* key definitions */
#define MODKEY Mod4Mask
#define TAGKEYS(KEY,TAG) \
{ MODKEY, KEY, comboview, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
{ MODKEY|ShiftMask, KEY, combotag, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
/* applications */
static const char *dmenu[] = { "dmenu_run", "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
static const char *editor[] = { "sublime", NULL };
static const char *filebrowser[] = { "thunar", NULL };
static const char *procviewer[] = { "terminator", "-x", "htop", NULL };
static const char *terminal[] = { "terminator", NULL };
static const char *web[] = { "chromium", NULL };
static const char *webprivate[] = { "chromium", "--incognito", NULL };
/* audio mixer */
static const char *audiomute[] = { "amixer", "-q", "set", "Master", "toggle", NULL };
static const char *audiolower[] = { "amixer", "-q", "set", "Master", "5%-", "unmute", NULL };
static const char *audioraise[] = { "amixer", "-q", "set", "Master", "5%+", "unmute", NULL };
/* mpd */
static const char *mpdtoggle[] = { "mpc", "-q", "toggle", NULL };
static const char *mpdprevious[] = { "mpc", "-q", "prev", NULL };
static const char *mpdnext[] = { "mpc", "-q", "next", NULL };
static const char *mpdvollower[] = { "mpc", "-q", "volume", "-5", NULL };
static const char *mpdvolraise[] = { "mpc", "-q", "volume", "+5", NULL };
#include <X11/XF86keysym.h>
static Key keys[] = {
/* modifier key function argument */
{ MODKEY, XK_p, spawn, {.v = dmenu } },
{ MODKEY, XK_e, spawn, {.v = editor } },
{ MODKEY, XK_f, spawn, {.v = filebrowser } },
{ MODKEY, XK_t, spawn, {.v = terminal } },
{ MODKEY, XK_w, spawn, {.v = web } },
{ MODKEY|ShiftMask, XK_w, spawn, {.v = webprivate } },
{ 0, XF86XK_LaunchB, spawn, {.v = procviewer } },
{ 0, XF86XK_AudioMute, spawn, {.v = audiomute } },
{ 0, XF86XK_AudioLowerVolume, spawn, {.v = audiolower } },
{ 0, XF86XK_AudioRaiseVolume, spawn, {.v = audioraise } },
{ 0, XF86XK_AudioPlay, spawn, {.v = mpdtoggle } },
{ 0, XF86XK_AudioPrev, spawn, {.v = mpdprevious } },
{ 0, XF86XK_AudioNext, spawn, {.v = mpdnext } },
{ 0, XF86XK_Launch5, spawn, {.v = mpdvollower } },
{ 0, XF86XK_Launch6, spawn, {.v = mpdvolraise } },
{ 0, XF86XK_Launch8, spawn, SHCMD("notify-send \"$(mpc current)\"") },
{ MODKEY, XK_b, togglebar, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } },
{ MODKEY, XK_Tab, focusstack, {.i = +1 } },
{ MODKEY|ShiftMask, XK_Tab, focusstack, {.i = -1 } },
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
{ MODKEY, XK_Return, zoom, {0} },
{ MODKEY, XK_q, killclient, {0} },
{ MODKEY, XK_space, setlayout, {0} },
TAGKEYS( XK_ampersand, 0)
TAGKEYS( XK_eacute, 1)
TAGKEYS( XK_quotedbl, 2)
TAGKEYS( XK_apostrophe, 3)
TAGKEYS( XK_parenleft, 4)
TAGKEYS( XK_section, 5)
TAGKEYS( XK_egrave, 6)
TAGKEYS( XK_exclam, 7)
TAGKEYS( XK_ccedilla, 8)
{ MODKEY|ShiftMask, XK_q, quit, {0} },
/* arrows */
{ MODKEY, XK_Up, focusstack, {.i = +1 } },
{ MODKEY, XK_Down, focusstack, {.i = -1 } },
/* keypad */
{ MODKEY, XK_KP_Subtract, setmfact, {.f = -0.05} },
{ MODKEY, XK_KP_Add, setmfact, {.f = +0.05} },
{ MODKEY, XK_KP_Enter, zoom, {0} },
TAGKEYS( XK_KP_End, 0)
TAGKEYS( XK_KP_Down, 1)
TAGKEYS( XK_KP_Next, 2)
TAGKEYS( XK_KP_Left, 3)
TAGKEYS( XK_KP_Begin, 4)
TAGKEYS( XK_KP_Right, 5)
TAGKEYS( XK_KP_Home, 6)
TAGKEYS( XK_KP_Up, 7)
TAGKEYS( XK_KP_Prior, 8)
};
/* button definitions */
/* click can be ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
static Button buttons[] = {
/* click event mask button function argument */
{ ClkClientWin, MODKEY, Button1, zoom, {0} },
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
{ ClkTagBar, 0, Button1, view, {0} },
{ ClkTagBar, 0, Button3, toggleview, {0} },
{ ClkTagBar, MODKEY, Button1, tag, {0} },
{ ClkTagBar, MODKEY, Button3, toggletag, {0} },
};
Contents:
azertykey (with custom Mac fix):
http://dwm.suckless.org/patches/azertykey
bottom stack (without bstackhoriz):
http://dwm.suckless.org/patches/bottom_stack
combo:
http://dwm.suckless.org/patches/combo # BREAKS A BUNCH OF STUFF
hide unused tags:
https://gist.github.com/xfausto/3068337
xkblib_deprecated fix:
http://lists.suckless.org/dev/1212/13822.html
zoomswap:
http://dwm.suckless.org/patches/zoomswap
diff -rupN dwm-6.0_/bstack.c dwm-6.0/bstack.c
--- dwm-6.0_/bstack.c 1970-01-01 01:00:00.000000000 +0100
+++ dwm-6.0/bstack.c 2013-12-12 18:01:21.202358534 +0100
@@ -0,0 +1,33 @@
+static void
+bstack(Monitor *m) {
+ int w, h, mh, mx, tx, ty, tw;
+ unsigned int i, n;
+ Client *c;
+
+ for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
+ if(n == 0)
+ return;
+ if(n > m->nmaster) {
+ mh = m->nmaster ? m->mfact * m->wh : 0;
+ tw = m->ww / (n - m->nmaster);
+ ty = m->wy + mh;
+ }
+ else {
+ mh = m->wh;
+ tw = m->ww;
+ ty = m->wy;
+ }
+ for(i = mx = 0, tx = m->wx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
+ if(i < m->nmaster) {
+ w = (m->ww - mx) / (MIN(n, m->nmaster) - i);
+ resize(c, m->wx + mx, m->wy, w - (2 * c->bw), mh - (2 * c->bw), False);
+ mx += WIDTH(c);
+ }
+ else {
+ h = m->wh - mh;
+ resize(c, tx, ty, tw - (2 * c->bw), h - (2 * c->bw), False);
+ if(tw != m->ww)
+ tx += WIDTH(c);
+ }
+ }
+}
diff -rupN dwm-6.0_/config.def.h dwm-6.0/config.def.h
--- dwm-6.0_/config.def.h 2011-12-19 16:02:46.000000000 +0100
+++ dwm-6.0/config.def.h 2013-12-12 18:13:06.217477937 +0100
@@ -27,11 +27,13 @@ static const float mfact = 0.55; /*
static const int nmaster = 1; /* number of clients in master area */
static const Bool resizehints = True; /* True means respect size hints in tiled resizals */
+#include "bstack.c"
static const Layout layouts[] = {
/* symbol arrange function */
{ "[]=", tile }, /* first entry is default */
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
+ { "TTT", bstack },
};
/* key definitions */
@@ -68,21 +70,21 @@ static Key keys[] = {
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
{ MODKEY, XK_space, setlayout, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
- { MODKEY, XK_0, view, {.ui = ~0 } },
- { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
+ { MODKEY, XK_agrave, view, {.ui = ~0 } },
+ { MODKEY|ShiftMask, XK_agrave, tag, {.ui = ~0 } },
{ MODKEY, XK_comma, focusmon, {.i = -1 } },
- { MODKEY, XK_period, focusmon, {.i = +1 } },
+ { MODKEY, XK_semicolon, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
- { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
- TAGKEYS( XK_1, 0)
- TAGKEYS( XK_2, 1)
- TAGKEYS( XK_3, 2)
- TAGKEYS( XK_4, 3)
- TAGKEYS( XK_5, 4)
- TAGKEYS( XK_6, 5)
- TAGKEYS( XK_7, 6)
- TAGKEYS( XK_8, 7)
- TAGKEYS( XK_9, 8)
+ { MODKEY|ShiftMask, XK_semicolon, tagmon, {.i = +1 } },
+ TAGKEYS( XK_ampersand, 0)
+ TAGKEYS( XK_eacute, 1)
+ TAGKEYS( XK_quotedbl, 2)
+ TAGKEYS( XK_apostrophe, 3)
+ TAGKEYS( XK_parenleft, 4)
+ TAGKEYS( XK_section, 5)
+ TAGKEYS( XK_egrave, 6)
+ TAGKEYS( XK_exclam, 7)
+ TAGKEYS( XK_ccedilla, 8)
{ MODKEY|ShiftMask, XK_q, quit, {0} },
};
diff -rupN dwm-6.0_/dwm.c dwm-6.0/dwm.c
--- dwm-6.0_/dwm.c 2011-12-19 16:02:46.000000000 +0100
+++ dwm-6.0/dwm.c 2013-12-12 18:13:06.221477969 +0100
@@ -36,6 +36,7 @@
#include <X11/Xlib.h>
#include <X11/Xproto.h>
#include <X11/Xutil.h>
+#include <X11/XKBlib.h>
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
#endif /* XINERAMA */
@@ -252,7 +253,13 @@ static int xerrordummy(Display *dpy, XEr
static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg);
+static void keyrelease(XEvent *e);
+static void combotag(const Arg *arg);
+static void comboview(const Arg *arg);
+
+
/* variables */
+static Client *prevzoom = NULL;
static const char broken[] = "broken";
static char stext[256];
static int screen;
@@ -262,6 +269,7 @@ static int (*xerrorxlib)(Display *, XErr
static unsigned int numlockmask = 0;
static void (*handler[LASTEvent]) (XEvent *) = {
[ButtonPress] = buttonpress,
+ [ButtonRelease] = keyrelease,
[ClientMessage] = clientmessage,
[ConfigureRequest] = configurerequest,
[ConfigureNotify] = configurenotify,
@@ -269,6 +277,7 @@ static void (*handler[LASTEvent]) (XEven
[EnterNotify] = enternotify,
[Expose] = expose,
[FocusIn] = focusin,
+ [KeyRelease] = keyrelease,
[KeyPress] = keypress,
[MappingNotify] = mappingnotify,
[MapRequest] = maprequest,
@@ -291,6 +300,42 @@ static Window root;
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
/* function implementations */
+static int combo = 0;
+
+void
+keyrelease(XEvent *e) {
+ combo = 0;
+}
+
+void
+combotag(const Arg *arg) {
+ if(selmon->sel && arg->ui & TAGMASK) {
+ if (combo) {
+ selmon->sel->tags |= arg->ui & TAGMASK;
+ } else {
+ combo = 1;
+ selmon->sel->tags = arg->ui & TAGMASK;
+ }
+ focus(NULL);
+ arrange(selmon);
+ }
+}
+
+void
+comboview(const Arg *arg) {
+ unsigned newtags = arg->ui & TAGMASK;
+ if (combo) {
+ selmon->tagset[selmon->seltags] |= newtags;
+ } else {
+ selmon->seltags ^= 1; /*toggle tagset*/
+ combo = 1;
+ if (newtags)
+ selmon->tagset[selmon->seltags] = newtags;
+ }
+ focus(NULL);
+ arrange(selmon);
+}
+
void
applyrules(Client *c) {
const char *class, *instance;
@@ -425,7 +470,7 @@ attachstack(Client *c) {
void
buttonpress(XEvent *e) {
- unsigned int i, x, click;
+ unsigned int i, x, click, occ = 0;
Arg arg = {0};
Client *c;
Monitor *m;
@@ -439,10 +484,14 @@ buttonpress(XEvent *e) {
focus(NULL);
}
if(ev->window == selmon->barwin) {
+ for(c = m->clients; c; c = c->next) {
+ occ |= c->tags;
+ }
i = x = 0;
- do
+ do {
+ if (!(m->tagset[m->seltags] & 1 << i) && !(occ & 1 << i)) continue;
x += TEXTW(tags[i]);
- while(ev->x >= x && ++i < LENGTH(tags));
+ } while(ev->x >= x && ++i < LENGTH(tags));
if(i < LENGTH(tags)) {
click = ClkTagBar;
arg.ui = 1 << i;
@@ -729,11 +778,11 @@ drawbar(Monitor *m) {
}
dc.x = 0;
for(i = 0; i < LENGTH(tags); i++) {
+ if (!(m->tagset[m->seltags] & 1 << i) && !(occ & 1 << i)) continue;
dc.w = TEXTW(tags[i]);
col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm;
drawtext(tags[i], col, urg & 1 << i);
- drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
- occ & 1 << i, urg & 1 << i, col);
+ drawsquare(False, False, urg & 1 << i, col);
dc.x += dc.w;
}
dc.w = blw = TEXTW(m->ltsymbol);
@@ -1084,7 +1133,7 @@ keypress(XEvent *e) {
XKeyEvent *ev;
ev = &e->xkey;
- keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
+ keysym = XkbKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0, 0);
for(i = 0; i < LENGTH(keys); i++)
if(keysym == keys[i].keysym
&& CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
@@ -2116,14 +2165,36 @@ xerrorstart(Display *dpy, XErrorEvent *e
void
zoom(const Arg *arg) {
Client *c = selmon->sel;
+ Client *at, *tmp;
if(!selmon->lt[selmon->sellt]->arrange
|| (selmon->sel && selmon->sel->isfloating))
return;
- if(c == nexttiled(selmon->clients))
- if(!c || !(c = nexttiled(c->next)))
- return;
+ if(c == nexttiled(selmon->clients)) {
+ for(tmp = selmon->clients; tmp && tmp != prevzoom; tmp = tmp->next) ;
+ if(tmp != prevzoom)
+ prevzoom = NULL;
+ if(!c || !(c = nexttiled(prevzoom))) {
+ c = selmon->sel;
+ if(!c || !(c = nexttiled(c->next)))
+ return;
+ }
+ }
+ for(at = selmon->clients; at && at->next && at != c && at->next != c; at = nexttiled(at->next)) ;
pop(c);
+ /* swap windows instead of pushing the previous one down */
+ if(at && at != c) {
+ /* store c's next neighbor - this window needs to be moved away */
+ tmp = prevzoom = c->next;
+ if(c->next != at) {
+ /* detach c's neighbor from the list of windows */
+ c->next = tmp->next;
+ /* attach tmp after c's previous neighbor */
+ tmp->next = at->next;
+ at->next = tmp;
+ arrange(c->mon);
+ }
+ }
}
int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment