From 6c58b480b7b6ce6a28beafc60a096069fbd51532 Mon Sep 17 00:00:00 2001 From: LeelaPakanati Date: Fri, 13 Dec 2019 16:56:42 -0500 Subject: [PATCH] Add function handling at keyrelease --- config.def.h | 6 ++++++ tabbed.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index defa426..7bfda30 100644 --- a/config.def.h +++ b/config.def.h @@ -64,3 +64,9 @@ static Key keys[] = { { 0, XK_F11, fullscreen, { 0 } }, }; + +static Key keyreleases[] = { + /* modifier key function argument */ + { 0, XK_Shift_L, NULL, { 0 } }, + +}; diff --git a/tabbed.c b/tabbed.c index ff3ada0..fe38b9d 100644 --- a/tabbed.c +++ b/tabbed.c @@ -113,6 +113,7 @@ static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); static void initfont(const char *fontstr); static Bool isprotodel(int c); static void keypress(const XEvent *e); +static void keyrelease(const XEvent *e); static void killclient(const Arg *arg); static void manage(Window win); static void maprequest(const XEvent *e); @@ -149,6 +150,7 @@ static void (*handler[LASTEvent]) (const XEvent *) = { [Expose] = expose, [FocusIn] = focusin, [KeyPress] = keypress, + [KeyRelease] = keyrelease, [MapRequest] = maprequest, [PropertyNotify] = propertynotify, }; @@ -664,6 +666,22 @@ keypress(const XEvent *e) } } +void +keyrelease(const XEvent *e) +{ + const XKeyEvent *ev = &e->xkey; + unsigned int i; + KeySym keysym; + + keysym = XkbKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0, 0); + for (i = 0; i < LENGTH(keyreleases); i++) { + if (keysym == keyreleases[i].keysym && + CLEANMASK(keyreleases[i].mod) == CLEANMASK(ev->state) && + keyreleases[i].func) + keyreleases[i].func(&(keyreleases[i].arg)); + } +} + void killclient(const Arg *arg) { @@ -714,6 +732,16 @@ manage(Window w) } } + for (i = 0; i < LENGTH(keyreleases); i++) { + if ((code = XKeysymToKeycode(dpy, keyreleases[i].keysym))) { + for (j = 0; j < LENGTH(modifiers); j++) { + XGrabKey(dpy, code, keyreleases[i].mod | + modifiers[j], w, True, + GrabModeAsync, GrabModeAsync); + } + } + } + c = ecalloc(1, sizeof *c); c->win = w; @@ -1036,7 +1064,7 @@ setup(void) XMapRaised(dpy, win); XSelectInput(dpy, win, SubstructureNotifyMask | FocusChangeMask | ButtonPressMask | ExposureMask | KeyPressMask | - PropertyChangeMask | StructureNotifyMask | + KeyReleaseMask | PropertyChangeMask | StructureNotifyMask | SubstructureRedirectMask); xerrorxlib = XSetErrorHandler(xerror); -- 2.24.0