Created
April 8, 2020 16:31
-
-
Save luukvbaal/7d0249cde6c9e297143a8be8d7fdfa6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From b7e972c3dfeeb0b29ec7b95589187257c4804791 Mon Sep 17 00:00:00 2001 | |
From: Luuk van Baal <[email protected]> | |
Date: Wed, 8 Apr 2020 18:09:04 +0200 | |
Subject: [PATCH] limit keypresses | |
--- | |
dwm.c | 56 ++++++++++++++++++++++++++++++++++---------------------- | |
1 file changed, 34 insertions(+), 22 deletions(-) | |
diff --git a/dwm.c b/dwm.c | |
index 321a8c5..73b93f8 100644 | |
--- a/dwm.c | |
+++ b/dwm.c | |
@@ -516,10 +516,13 @@ void | |
buttonpress(XEvent *e) | |
{ | |
unsigned int i, x, click, occ = 0; | |
+ static Time lasttime = 0; | |
Arg arg = {0}; | |
Client *c; | |
Monitor *m; | |
XButtonPressedEvent *ev = &e->xbutton; | |
+ if (!lasttime) | |
+ lasttime = ev->time; | |
lastbutton = ev->button; | |
click = ClkRootWin; | |
@@ -545,22 +548,25 @@ buttonpress(XEvent *e) | |
} else if (ev->x < x + blw) | |
click = ClkLtSymbol; | |
else if (ev->x > (x = selmon->ww - TEXTW(stext) + lrpad - getsystraywidth())) { | |
- click = ClkStatusText; | |
- | |
- char *text = rawstext; | |
- int i = -1; | |
- char ch; | |
- statuscmdn = 0; | |
- while (text[++i]) { | |
- if ((unsigned char)text[i] < ' ') { | |
- ch = text[i]; | |
- text[i] = '\0'; | |
- x += TEXTW(text) - lrpad; | |
- text[i] = ch; | |
- text += i+1; | |
- i = -1; | |
- if (x >= ev->x) break; | |
- if (ch <= LENGTH(statuscmds)) statuscmdn = ch - 1; | |
+ if (ev->time - lasttime >= 150) { | |
+ lasttime = ev->time; | |
+ click = ClkStatusText; | |
+ | |
+ char *text = rawstext; | |
+ int i = -1; | |
+ char ch; | |
+ statuscmdn = 0; | |
+ while (text[++i]) { | |
+ if ((unsigned char)text[i] < ' ') { | |
+ ch = text[i]; | |
+ text[i] = '\0'; | |
+ x += TEXTW(text) - lrpad; | |
+ text[i] = ch; | |
+ text += i+1; | |
+ i = -1; | |
+ if (x >= ev->x) break; | |
+ if (ch <= LENGTH(statuscmds)) statuscmdn = ch - 1; | |
+ } | |
} | |
} | |
} else | |
@@ -1214,16 +1220,22 @@ void | |
keypress(XEvent *e) | |
{ | |
unsigned int i; | |
+ static Time lasttime = 0; | |
KeySym keysym; | |
XKeyEvent *ev; | |
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 (!lasttime) | |
+ lasttime = ev->time; | |
+ if (ev->time - lasttime >= 150) { | |
+ lasttime = ev->time; | |
+ 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)); | |
+ } | |
} | |
void |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment