dwm

my heavily-patched and customized dwm build
git clone git://git.kocotian.pl/dwm.git
Log | Files | Refs | README | LICENSE

commit c04fc76c6118dd99bb058e6c9512c5ef5b051109
parent 77336af923ebea01a15bef2df4191e36bb6afaf8
Author: kocotian <kocotian@kocotian.pl>
Date:   Sun, 14 Mar 2021 19:34:19 +0100

Dired under WinShiftD, Normal Mode

Diffstat:
Mconfig.def.h | 27+++++++++++++++++++++------
Mconfig.mk | 3++-
Mdwm.c | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
3 files changed, 89 insertions(+), 17 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -180,6 +180,8 @@ static Key keys[] = { { MODKEY|ShiftMask, XK_y, spawn, SHCMD("ytdlclip") }, { MODKEY|ControlMask, XK_y, spawn, SHCMD("youtube-viewer") }, + { MODKEY, XK_i, spawn, SHCMD("") }, + { MODKEY, XK_o, incnmaster, {.i = +1 } }, { MODKEY|ShiftMask, XK_o, incnmaster, {.i = -1 } }, { MODKEY, XK_p, spawn, SHCMD("mpc toggle") }, @@ -193,7 +195,7 @@ static Key keys[] = { { MODKEY|ShiftMask, XK_a, gaptog, {1} }, { MODKEY|ControlMask, XK_a, sbtog, {0} }, { MODKEY, XK_d, spawn, {.v = dmenucmd } }, - { MODKEY|ShiftMask, XK_d, spawn, SHCMD("dmenize") }, + { MODKEY|ShiftMask, XK_d, spawn, SHCMD("st -e nvim -c DiredHere") }, { MODKEY, XK_f, togglefullscr, {0} }, /* bits: [hk/jl], [jk/hl], [withControl] */ @@ -207,11 +209,6 @@ static Key keys[] = { { MODKEY|ControlMask, XK_h, modmove, {.i = (1 + (1 << 1) + (0 << 2))} }, { MODKEY|ControlMask, XK_l, modmove, {.i = (1 + (1 << 1) + (1 << 2))} }, - { MODKEY|Mod1Mask|ControlMask, XK_j, spawn, SHCMD("xdotool key Down") }, - { MODKEY|Mod1Mask|ControlMask, XK_k, spawn, SHCMD("xdotool key Up") }, - { MODKEY|Mod1Mask|ControlMask, XK_h, spawn, SHCMD("xdotool key Left") }, - { MODKEY|Mod1Mask|ControlMask, XK_l, spawn, SHCMD("xdotool key Right") }, - { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } }, { MODKEY, XK_h, setmfact, {.f = -0.05} }, @@ -256,6 +253,9 @@ static Key keys[] = { { MODKEY, XK_Delete, spawn, SHCMD("dmenurecord kill") }, { MODKEY, XK_Scroll_Lock, spawn, SHCMD("killall screenkey || screenkey &") }, + { MODKEY, XK_Escape, vinormal, {.i = 1} }, + { MODKEY, XK_backslash, vinormal, {.i = 1} }, + { MODKEY, XK_0, view, {.ui = ~0 } }, { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, TAGKEYS( XK_1, 0) @@ -269,6 +269,21 @@ static Key keys[] = { TAGKEYS( XK_9, 8) }; +static Key vikeys[] = { + { 0, XK_i, vinormal, {.i = 0} }, + + { 0, XK_j, xkeypress, {.ui = XK_Down} }, + { 0, XK_k, xkeypress, {.ui = XK_Up} }, + { 0, XK_h, xkeypress, {.ui = XK_Left} }, + { 0, XK_l, xkeypress, {.ui = XK_Right} }, + + { 0, XK_o, delayspawn, SHCMD("xdotool key End Return") }, + { ShiftMask, XK_o, delayspawn, SHCMD("xdotool keyup Shift; xdotool key Home Return Up; xdotool keydown Shift") }, + + { 0, XK_p, delayspawn, SHCMD("xdotool keyup Shift; xdotool type i\"$(xclip -selection primary -o)\"; xdotool keydown Shift") }, + { ShiftMask, XK_p, delayspawn, SHCMD("xdotool keyup Shift; xdotool type i\"$(xclip -selection clipboard -o)\"; xdotool keydown Shift") }, +}; + /* button definitions */ /* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ static Button buttons[] = { diff --git a/config.mk b/config.mk @@ -24,7 +24,8 @@ FREETYPEINC = /usr/include/freetype2 # includes and libs INCS = -I${X11INC} -I${FREETYPEINC} -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lX11-xcb -lxcb -lxcb-res ${KVMLIB} +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lX11-xcb \ + -lxcb -lxcb-res ${KVMLIB} -lXtst # flags CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}${BUILDNAME}\" ${XINERAMAFLAGS} diff --git a/dwm.c b/dwm.c @@ -42,6 +42,7 @@ #include <X11/Xft/Xft.h> #include <X11/Xlib-xcb.h> #include <xcb/res.h> +#include <X11/extensions/XTest.h> #ifdef __OpenBSD__ #include <sys/sysctl.h> #include <kvm.h> @@ -63,6 +64,7 @@ #define HEIGHT(X) ((X)->h + 2 * (X)->bw) #define TAGMASK ((1 << LENGTH(tags)) - 1) #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) +#define DELAY 100000 /* enums */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ @@ -218,6 +220,7 @@ static void grabbuttons(Client *c, int focused); static void grabkeys(void); static void incnmaster(const Arg *arg); static void keypress(XEvent *e); +static void xkeypress(const Arg *arg); static void killclient(const Arg *arg); static void manage(Window w, XWindowAttributes *wa); static void mappingnotify(XEvent *e); @@ -262,6 +265,8 @@ static void sigdwmblocks(const Arg *arg); static void sighup(int unused); static void sigterm(int unused); static void spawn(const Arg *arg); +static void delayspawn(const Arg *arg); +static void redelayspawn(const Arg *arg); static void swaptags(const Arg *arg); static void tag(const Arg *arg); static void tagmon(const Arg *arg); @@ -286,6 +291,7 @@ static void updatetitle(Client *c); static void updatewindowtype(Client *c); static void updatewmhints(Client *c); static void view(const Arg *arg); +static void vinormal(const Arg *arg); static Client *wintoclient(Window w); static Monitor *wintomon(Window w); static int xerror(Display *dpy, XErrorEvent *ee); @@ -312,6 +318,7 @@ static int bh, blw = 0; /* bar geometry */ static int lrpad; /* sum of left and right padding for text */ static int (*xerrorxlib)(Display *, XErrorEvent *); static unsigned int numlockmask = 0; +static unsigned int vinormalmode = 0; static void (*handler[LASTEvent]) (XEvent *) = { [ButtonPress] = buttonpress, [ClientMessage] = clientmessage, @@ -1089,7 +1096,16 @@ drawbar(Monitor *m) if (c->isurgent) urg |= c->tags; } + x = 0; + if (vinormalmode) { + w = blw = TEXTW("--- NORMAL MODE ---"); + drw_setscheme(drw, scheme[SchemeTagLnSel]); + drw_rect(drw, x + 1, 0, w - 2, 2, 1, 1); + drw_setscheme(drw, scheme[SchemeTagsNorm]); + x = drw_text(drw, x, 2, w, dbh, lrpad / 2, "--- NORMAL MODE ---", 0); + } + for (i = 0; i < LENGTH(tags); i++) { w = TEXTW(tags[i]); drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeTagsSel : SchemeTagsNorm]); @@ -1417,11 +1433,19 @@ grabkeys(void) KeyCode code; XUngrabKey(dpy, AnyKey, AnyModifier, root); - for (i = 0; i < LENGTH(keys); i++) - if ((code = XKeysymToKeycode(dpy, keys[i].keysym))) - for (j = 0; j < LENGTH(modifiers); j++) - XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, - True, GrabModeAsync, GrabModeAsync); + if (vinormalmode) { + for (i = 0; i < LENGTH(vikeys); i++) + if ((code = XKeysymToKeycode(dpy, vikeys[i].keysym))) + for (j = 0; j < LENGTH(modifiers); j++) + XGrabKey(dpy, code, vikeys[i].mod | modifiers[j], root, + True, GrabModeAsync, GrabModeAsync); + } else { + for (i = 0; i < LENGTH(keys); i++) + if ((code = XKeysymToKeycode(dpy, keys[i].keysym))) + for (j = 0; j < LENGTH(modifiers); j++) + XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, + True, GrabModeAsync, GrabModeAsync); + } } } @@ -1453,11 +1477,29 @@ keypress(XEvent *e) ev = &e->xkey; keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); - for (i = 0; i < LENGTH(keys); i++) - if (keysym == keys[i].keysym - && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) - && keys[i].func) - keys[i].func(&(keys[i].arg)); + if (vinormalmode) { + for (i = 0; i < LENGTH(vikeys); i++) { + if (keysym == vikeys[i].keysym + && CLEANMASK(vikeys[i].mod) == CLEANMASK(ev->state) + && vikeys[i].func) + vikeys[i].func(&(vikeys[i].arg)); + } + } else { + for (i = 0; i < LENGTH(keys); i++) { + if (keysym == keys[i].keysym + && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) + && keys[i].func) + keys[i].func(&(keys[i].arg)); + } + } +} + +void +xkeypress(const Arg *arg) +{ + usleep(DELAY); + XTestFakeKeyEvent(dpy, XKeysymToKeycode(dpy, arg->ui), 1, CurrentTime); + XTestFakeKeyEvent(dpy, XKeysymToKeycode(dpy, arg->ui), 0, CurrentTime); } void @@ -2518,6 +2560,13 @@ spawn(const Arg *arg) } void +delayspawn(const Arg *arg) +{ + usleep(DELAY); + spawn(arg); +} + +void swaptags(const Arg *arg) { unsigned int newtag = arg->ui & TAGMASK; @@ -3096,6 +3145,13 @@ view(const Arg *arg) arrange(selmon); } +void +vinormal(const Arg *arg) +{ + vinormalmode = arg->i; + grabkeys(); +} + pid_t winpid(Window w) {