Krolyxon
Commit 9a85dd4

Branches

Refs →

nsxiv9a85dd4

Ignore button and key events while key-handler is running

Related to issue #253, which originally asked for a non-blocking key-handler.
Author
Bert Münnich
Date
2016-11-29 12:07 +0100
Committer
Bert Münnich · 2016-11-30 20:48 +0100
Parent
c1ba841
Commit
9a85dd41d8551f82a5d00c8e0dd0807e23bbdc6d

+10 −1

2 files changed

  1. M Makefile +1 −1
  2. M main.c +9 −0
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION := git-20161128
1+VERSION := git-20161129
22
33 PREFIX := /usr/local
44 MANPREFIX := $(PREFIX)/share/man
M main.c View
@@ -458,6 +458,11 @@ void clear_resize(void)
458458 resized = false;
459459 }
460460
461+Bool is_input_ev(Display *dpy, XEvent *ev, XPointer arg)
462+{
463+ return ev->type == ButtonPress || ev->type == KeyPress;
464+}
465+
461466 void run_key_handler(const char *key, unsigned int mask)
462467 {
463468 pid_t pid;
@@ -468,6 +473,7 @@ void run_key_handler(const char *key, unsigned int mask)
468473 int fcnt = marked ? markcnt : 1;
469474 char kstr[32];
470475 struct stat *oldst, st;
476+ XEvent dump;
471477
472478 if (keyhandler.f.err != 0) {
473479 if (!keyhandler.warned) {
@@ -538,6 +544,9 @@ void run_key_handler(const char *key, unsigned int mask)
538544 f++;
539545 }
540546 }
547+ /* drop user input events that occured while running the key handler */
548+ while (XCheckIfEvent(win.env.dpy, &dump, is_input_ev, NULL));
549+
541550 end:
542551 if (mode == MODE_IMAGE) {
543552 if (changed) {