tabbed-keyrelease-20191216-b5f9ec6.diff (2749B)
1 From 6c58b480b7b6ce6a28beafc60a096069fbd51532 Mon Sep 17 00:00:00 2001 2 From: LeelaPakanati <LeelaPakanati.gmail.com> 3 Date: Fri, 13 Dec 2019 16:56:42 -0500 4 Subject: [PATCH] Add function handling at keyrelease 5 6 --- 7 config.def.h | 6 ++++++ 8 tabbed.c | 30 +++++++++++++++++++++++++++++- 9 2 files changed, 35 insertions(+), 1 deletion(-) 10 11 diff --git a/config.def.h b/config.def.h 12 index defa426..7bfda30 100644 13 --- a/config.def.h 14 +++ b/config.def.h 15 @@ -64,3 +64,9 @@ static Key keys[] = { 16 17 { 0, XK_F11, fullscreen, { 0 } }, 18 }; 19 + 20 +static Key keyreleases[] = { 21 + /* modifier key function argument */ 22 + { 0, XK_Shift_L, NULL, { 0 } }, 23 + 24 +}; 25 diff --git a/tabbed.c b/tabbed.c 26 index ff3ada0..fe38b9d 100644 27 --- a/tabbed.c 28 +++ b/tabbed.c 29 @@ -113,6 +113,7 @@ static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); 30 static void initfont(const char *fontstr); 31 static Bool isprotodel(int c); 32 static void keypress(const XEvent *e); 33 +static void keyrelease(const XEvent *e); 34 static void killclient(const Arg *arg); 35 static void manage(Window win); 36 static void maprequest(const XEvent *e); 37 @@ -149,6 +150,7 @@ static void (*handler[LASTEvent]) (const XEvent *) = { 38 [Expose] = expose, 39 [FocusIn] = focusin, 40 [KeyPress] = keypress, 41 + [KeyRelease] = keyrelease, 42 [MapRequest] = maprequest, 43 [PropertyNotify] = propertynotify, 44 }; 45 @@ -664,6 +666,22 @@ keypress(const XEvent *e) 46 } 47 } 48 49 +void 50 +keyrelease(const XEvent *e) 51 +{ 52 + const XKeyEvent *ev = &e->xkey; 53 + unsigned int i; 54 + KeySym keysym; 55 + 56 + keysym = XkbKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0, 0); 57 + for (i = 0; i < LENGTH(keyreleases); i++) { 58 + if (keysym == keyreleases[i].keysym && 59 + CLEANMASK(keyreleases[i].mod) == CLEANMASK(ev->state) && 60 + keyreleases[i].func) 61 + keyreleases[i].func(&(keyreleases[i].arg)); 62 + } 63 +} 64 + 65 void 66 killclient(const Arg *arg) 67 { 68 @@ -714,6 +732,16 @@ manage(Window w) 69 } 70 } 71 72 + for (i = 0; i < LENGTH(keyreleases); i++) { 73 + if ((code = XKeysymToKeycode(dpy, keyreleases[i].keysym))) { 74 + for (j = 0; j < LENGTH(modifiers); j++) { 75 + XGrabKey(dpy, code, keyreleases[i].mod | 76 + modifiers[j], w, True, 77 + GrabModeAsync, GrabModeAsync); 78 + } 79 + } 80 + } 81 + 82 c = ecalloc(1, sizeof *c); 83 c->win = w; 84 85 @@ -1036,7 +1064,7 @@ setup(void) 86 XMapRaised(dpy, win); 87 XSelectInput(dpy, win, SubstructureNotifyMask | FocusChangeMask | 88 ButtonPressMask | ExposureMask | KeyPressMask | 89 - PropertyChangeMask | StructureNotifyMask | 90 + KeyReleaseMask | PropertyChangeMask | StructureNotifyMask | 91 SubstructureRedirectMask); 92 xerrorxlib = XSetErrorHandler(xerror); 93 94 -- 95 2.24.0 96