aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xchord.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/xchord.c b/xchord.c
index ff1c755..b8acc0f 100644
--- a/xchord.c
+++ b/xchord.c
@@ -37,7 +37,7 @@ Window rwin;
int
main(int argc, char *argv[])
{
- int p1;
+ int p;
unsigned char mask[(XI_LASTEVENT+7)/8];
XEvent ev;
XGenericEventCookie *cookie;
@@ -63,7 +63,7 @@ main(int argc, char *argv[])
XFlush(dpy);
cookie = &ev.xcookie;
- p1 = 0;
+ p = 0;
/* watch for events */
for (;;) {
@@ -79,17 +79,22 @@ main(int argc, char *argv[])
switch (cookie->evtype) {
case XI_RawButtonPress:
- /* button 1 pressed */
- if (rev->detail == 1) p1 = 1;
+ /* 1 pressed (first step) */
+ if (rev->detail == 1) p = 1;
+ /* 1 + 3 pressed (second step) */
+ if (p > 0 && rev->detail == 3) p = 2;
break;
case XI_RawButtonRelease:
- /* button 1 released */
- if (rev->detail == 1) p1 = 0;
- /* button 1 pressed + 3 released */
- if (p1 && rev->detail == 3 && vfork() == 0) {
- execlp("dwim", "dwim", NULL);
- err(1, "execlp");
+ /* 1 pressed + 3 pressed + 3 released (third step) */
+ if (p == 2 && rev->detail == 3) {
+ p = 3;
+ if (vfork() == 0) {
+ execlp("dwim", "dwim", NULL);
+ err(1, "execlp");
+ }
}
+ /* 1 released (reset) */
+ if (p == 3 && rev->detail == 1) p = 0;
break;
}