Introduction
Introduction Statistics Contact Development Disclaimer Help
fixed the select() logic in run() to handle sigterm situations - svkbd - simple…
git clone git://git.suckless.org/svkbd
Log
Files
Refs
README
LICENSE
---
commit eae90f28d998af064ec163074a026a585ccb6417
parent 12fe4c89234fcd4172fceead572b1950815228af
Author: Maarten van Gompel <[email protected]>
Date: Sun, 2 Aug 2020 15:46:18 +0200
fixed the select() logic in run() to handle sigterm situations
Diffstat:
M svkbd.c | 40 ++++++++++++++---------------…
1 file changed, 18 insertions(+), 22 deletions(-)
---
diff --git a/svkbd.c b/svkbd.c
@@ -208,27 +208,6 @@ void
cleanup(void) {
int i;
- // E.g. Generally in scripts we call SIGTERM on svkbd in which case
- // if the user is holding for example the enter key (to execute
- // the kill or script that does the kill), that causes an issue
- // since then X doesn't know the keyup is never coming.. (since
- // process will be dead before finger lifts - in that case we
- // just trigger out fake up presses for all keys
- if (sigtermd) {
- //handle last pending events
- XEvent ev;
- while (XPending(dpy)) {
- XNextEvent(dpy, &ev);
- if(handler[ev.type]) {
- (handler[ev.type])(&ev); /* call handler */
- }
- }
- if (debug) { printf("Cleanup: simulating key release\n"); fflu…
- for (i = 0; i < numkeys; i++) {
- XTestFakeKeyEvent(dpy, XKeysymToKeycode(dpy, keys[i].k…
- }
- }
-
for (i = 0; i < SchemeLast; i++)
free(scheme[i]);
drw_sync(drw);
@@ -542,6 +521,7 @@ run(void) {
fd_set fds;
struct timeval tv;
double duration = 0.0;
+ int i, r;
xfd = ConnectionNumber(dpy);
@@ -556,7 +536,8 @@ run(void) {
usleep(100000L);
FD_ZERO(&fds);
FD_SET(xfd, &fds);
- if (select(xfd + 1, &fds, NULL, NULL, &tv)) {
+ r = select(xfd + 1, &fds, NULL, NULL, &tv);
+ if (r) {
while (XPending(dpy)) {
XNextEvent(dpy, &ev);
if(handler[ev.type]) {
@@ -564,6 +545,7 @@ run(void) {
}
}
} else {
+ //time-out expired without anything interesting happen…
if (ispressing && ispressingkeysym) {
duration = get_press_duration();
if (debug == 2) { printf("%f\n", duration); ff…
@@ -576,6 +558,20 @@ run(void) {
}
}
}
+ if (r == -1 || sigtermd) {
+ // an error occurred or we received a signal
+ // E.g. Generally in scripts we want to call SIGTERM on svkbd in w…
+ // if the user is holding for example the enter key (to execu…
+ // the kill or script that does the kill), that causes an iss…
+ // since then X doesn't know the keyup is never coming.. (sin…
+ // process will be dead before finger lifts - in that case we
+ // just trigger out fake up presses for all keys
+ if (debug) { printf("signal received, releasing all keys"); fflush…
+ for (i = 0; i < numkeys; i++) {
+ XTestFakeKeyEvent(dpy, XKeysymToKeycode(dpy, keys[i].keysym), …
+ }
+ running = False;
+ }
}
}
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.