diff options
author | Your Name <you@example.com> | 2020-10-21 20:03:55 +0100 |
---|---|---|
committer | Your Name <you@example.com> | 2020-10-21 20:03:55 +0100 |
commit | 61fb8628182db20d974eb63cedf41dceb7abf14c (patch) | |
tree | 583539acf5622edc8f642bf881dd181f14b89ba3 | |
parent | Remove scripts (diff) | |
download | dwm-61fb8628182db20d974eb63cedf41dceb7abf14c.tar.gz dwm-61fb8628182db20d974eb63cedf41dceb7abf14c.tar.bz2 dwm-61fb8628182db20d974eb63cedf41dceb7abf14c.zip |
Removed keyhandling functionality
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | config.h | 91 | ||||
-rw-r--r-- | dwm.c | 86 | ||||
-rwxr-xr-x | dwmc | 40 |
4 files changed, 190 insertions, 29 deletions
diff --git a/Makefile b/Makefile index 77bcbc0..f837f5c 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ dist: clean install: all mkdir -p ${DESTDIR}${PREFIX}/bin - cp -f dwm ${DESTDIR}${PREFIX}/bin + cp -f dwm dwmc ${DESTDIR}${PREFIX}/bin chmod 755 ${DESTDIR}${PREFIX}/bin/dwm mkdir -p ${DESTDIR}${MANPREFIX}/man1 sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1 diff --git a/config.h b/config.h index 7cdf81d..dc270f9 100644 --- a/config.h +++ b/config.h @@ -39,14 +39,14 @@ static const unsigned int alphas[][3] = { /* tagging */ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; -static const Rule rules[] = { +/*static const Rule rules[] = { /* xprop(1): * WM_CLASS(STRING) = instance, class * WM_NAME(STRING) = title */ /* class instance title tags mask isfloating monitor */ - { NULL, NULL, NULL, 0, False, -1 }, -}; +/* { NULL, NULL, NULL, 0, False, -1 }, +};*/ /* layout(s) */ static const float mfact = 0.50; /* factor of master area size [0.05..0.95] */ @@ -78,12 +78,10 @@ static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, static const char *termcmd[] = { "st", NULL }; #include "movestack.c" -static Key keys[] = { +/*static Key keys[] = { /* modifier key function argument */ - /* - { MODKEY, XK_p, spawn, {.v = dmenucmd } }, + /*{ MODKEY, XK_p, spawn, {.v = dmenucmd } }, { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, - */ { MODKEY, XK_b, togglebar, {0} }, { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } }, @@ -98,11 +96,9 @@ static Key keys[] = { { NULL, XK_F11, togglefullscreen,{0}}, { MODKEY, XK_Tab, view, {0} }, { MODKEY, XK_q, killclient, {0} }, - /* { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, - */ { MODKEY|ControlMask, XK_comma, cyclelayout, {.i = -1 } }, { MODKEY|ControlMask, XK_period, cyclelayout, {.i = +1 } }, { MODKEY, XK_space, setlayout, {0} }, @@ -123,8 +119,7 @@ static Key keys[] = { TAGKEYS( XK_8, 7) TAGKEYS( XK_9, 8) { MODKEY|ShiftMask, XK_q, quit, {0} }, - -}; +};/* /* button definitions */ /* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ @@ -142,3 +137,77 @@ static Button buttons[] = { { ClkTagBar, MODKEY, Button1, tag, {0} }, { ClkTagBar, MODKEY, Button3, toggletag, {0} }, }; + +void +setlayoutex(const Arg *arg) +{ + setlayout(&((Arg) { .v = &layouts[arg->i] })); +} + +void +viewex(const Arg *arg) +{ + view(&((Arg) { .ui = 1 << (arg->ui - 1)})); +} + +void +viewall(const Arg *arg) +{ + view(&((Arg){.ui = ~0})); +} + +void +toggleviewex(const Arg *arg) +{ + toggleview(&((Arg) { .ui = 1 << (arg->ui - 1)})); +} + +void +tagex(const Arg *arg) +{ + tag(&((Arg) { .ui = 1 << (arg->ui - 1)})); +} + +void +toggletagex(const Arg *arg) +{ + toggletag(&((Arg) { .ui = 1 << (arg->ui - 1)})); +} + +void +tagall(const Arg *arg) +{ + tag(&((Arg){.ui = ~0})); +} + +/* signal definitions */ +/* signum must be greater than 0 */ +/* trigger signals using `xsetroot -name "fsignal:<signame> [<type> <value>]"` */ +static Signal signals[] = { + /* signum function */ + { "focusstack", focusstack }, + { "movestack", movestack }, + { "setmfact", setmfact }, + { "togglebar", togglebar }, + { "incnmaster", incnmaster }, + { "togglefloating", togglefloating }, + { "togglefullscreen", togglefullscreen }, + { "focusmon", focusmon }, + { "tagmon", tagmon }, + { "zoom", zoom }, + { "view", view }, + { "viewall", viewall }, + { "viewex", viewex }, + { "toggleview", view }, + { "toggleviewex", toggleviewex }, + { "tag", tag }, + { "tagall", tagall }, + { "tagex", tagex }, + { "toggletag", tag }, + { "toggletagex", toggletagex }, + { "killclient", killclient }, + { "quit", quit }, + { "setlayout", setlayout }, + { "setlayoutex", setlayoutex }, + { "cyclelayout", cyclelayout }, +}; diff --git a/dwm.c b/dwm.c index 2d10692..bf4f942 100644 --- a/dwm.c +++ b/dwm.c @@ -110,6 +110,11 @@ typedef struct { } Key; typedef struct { + const char * sig; + void (*func)(const Arg *); +} Signal; + +typedef struct { const char *symbol; void (*arrange)(Monitor *); } Layout; @@ -152,6 +157,7 @@ static void arrange(Monitor *m); static void arrangemon(Monitor *m); static void attach(Client *c); static void attachstack(Client *c); +static int fake_signal(void); static void buttonpress(XEvent *e); static void checkotherwm(void); static void cleanup(void); @@ -179,10 +185,10 @@ static int gettextprop(Window w, Atom atom, char *text, unsigned int size); static void grabbuttons(Client *c, int focused); static void grabkeys(void); static void incnmaster(const Arg *arg); -static void keypress(XEvent *e); +//static void keypress(XEvent *e); static void killclient(const Arg *arg); static void manage(Window w, XWindowAttributes *wa); -static void mappingnotify(XEvent *e); +//static void mappingnotify(XEvent *e); static void maprequest(XEvent *e); static void monocle(Monitor *m); static void movemouse(const Arg *arg); @@ -261,8 +267,8 @@ static void (*handler[LASTEvent]) (XEvent *) = { [DestroyNotify] = destroynotify, [Expose] = expose, [FocusIn] = focusin, - [KeyPress] = keypress, - [MappingNotify] = mappingnotify, + [KeyPress] = NULL, //keypress + [MappingNotify] = NULL,//mappingnotify, [MapRequest] = maprequest, [PropertyNotify] = propertynotify, [UnmapNotify] = unmapnotify @@ -290,20 +296,21 @@ struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; void applyrules(Client *c) { - const char *class, *instance; + //NO RULESS + /*const char *class, *instance; unsigned int i; const Rule *r; Monitor *m; - XClassHint ch = { NULL, NULL }; + XClassHint ch = { NULL, NULL };*/ /* rule matching */ c->isfloating = 0; c->tags = 0; - XGetClassHint(dpy, c->win, &ch); + /*XGetClassHint(dpy, c->win, &ch); class = ch.res_class ? ch.res_class : broken; instance = ch.res_name ? ch.res_name : broken; - for (i = 0; i < LENGTH(rules); i++) { + for (i = 0; i < LENGTH(rules); i++) { r = &rules[i]; if ((!r->title || strstr(c->name, r->title)) && (!r->class || strstr(class, r->class)) @@ -319,7 +326,7 @@ applyrules(Client *c) if (ch.res_class) XFree(ch.res_class); if (ch.res_name) - XFree(ch.res_name); + XFree(ch.res_name);*/ c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags]; } @@ -963,7 +970,7 @@ grabbuttons(Client *c, int focused) void grabkeys(void) { - updatenumlockmask(); +/* updatenumlockmask(); { unsigned int i, j; unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; @@ -975,7 +982,7 @@ grabkeys(void) for (j = 0; j < LENGTH(modifiers); j++) XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, True, GrabModeAsync, GrabModeAsync); - } + }*/ } void @@ -997,7 +1004,7 @@ isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) } #endif /* XINERAMA */ -void +/*void keypress(XEvent *e) { unsigned int i; @@ -1011,6 +1018,49 @@ keypress(XEvent *e) && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) && keys[i].func) keys[i].func(&(keys[i].arg)); +}**/ + +int +fake_signal(void) +{ + char fsignal[256]; + char indicator[9] = "dsignal:"; + char str_sig[50]; + char param[16]; + int i, len_str_sig, n, paramn; + size_t len_fsignal, len_indicator = strlen(indicator); + Arg arg; + + // Get root name property + if (gettextprop(root, XA_WM_NAME, fsignal, sizeof(fsignal))) { + len_fsignal = strlen(fsignal); + + // Check if this is indeed a fake signal + if (len_indicator > len_fsignal ? 0 : strncmp(indicator, fsignal, len_indicator) == 0) { + paramn = sscanf(fsignal + len_indicator, "%s%n%s%n", str_sig, &len_str_sig, param, &n); + + if (paramn == 1) arg = (Arg) {0}; + else if (paramn > 2) return 1; + else if (strncmp(param, "i", n - len_str_sig) == 0) + sscanf(fsignal + len_indicator + n, "%i", &(arg.i)); + else if (strncmp(param, "ui", n - len_str_sig) == 0) + sscanf(fsignal + len_indicator + n, "%u", &(arg.ui)); + else if (strncmp(param, "f", n - len_str_sig) == 0) + sscanf(fsignal + len_indicator + n, "%f", &(arg.f)); + else return 1; + + // Check if a signal was found, and if so handle it + for (i = 0; i < LENGTH(signals); i++) + if (strncmp(str_sig, signals[i].sig, len_str_sig) == 0 && signals[i].func) + signals[i].func(&(arg)); + + // A fake signal was sent + return 1; + } + } + + // No fake signal was sent, so proceed with update + return 0; } void @@ -1095,7 +1145,7 @@ manage(Window w, XWindowAttributes *wa) focus(NULL); } -void +/*void mappingnotify(XEvent *e) { XMappingEvent *ev = &e->xmapping; @@ -1103,7 +1153,7 @@ mappingnotify(XEvent *e) XRefreshKeyboardMapping(ev); if (ev->request == MappingKeyboard) grabkeys(); -} +}*/ void maprequest(XEvent *e) @@ -1217,9 +1267,11 @@ propertynotify(XEvent *e) Window trans; XPropertyEvent *ev = &e->xproperty; - if ((ev->window == root) && (ev->atom == XA_WM_NAME)) - updatestatus(); - else if (ev->state == PropertyDelete) + if ((ev->window == root) && (ev->atom == XA_WM_NAME)) { + if (!fake_signal()) + updatestatus(); + } + else if (ev->state == PropertyDelete) return; /* ignore */ else if ((c = wintoclient(ev->window))) { switch(ev->atom) { diff --git a/dwmc b/dwmc new file mode 100755 index 0000000..9deaec6 --- /dev/null +++ b/dwmc @@ -0,0 +1,40 @@ +#!/usr/bin/env sh + +signal() { + xsetroot -name "dsignal:$*" +} + +case $# in +1) + case $1 in + setlayout | view | viewall | tagall | togglebar | togglefloating | togglefullscreen | zoom | killclient | quit) + signal $1 + ;; + *) + echo "Unknown command or missing one argument." + exit 1 + ;; + esac + ;; +2) + case $1 in + view) + signal $1 ui $(expr $2 - 1) + ;; + viewex | toggleviewex | tagex | toggletagex | setlayoutex | focusstack | movestack | cyclelayout | incnmaster | focusmon | tagmon) + signal $1 i $2 + ;; + setmfact) + signal $1 f $2 + ;; + *) + echo "Unknown command or one too many arguments." + exit 1 + ;; + esac + ;; +*) + echo "Too many arguments." + exit 1 + ;; +esac |