From dc016d9270ab6f9893776ad8e45a004bbb877321 Mon Sep 17 00:00:00 2001 From: Ben Reaves Date: Sat, 15 Feb 2020 21:23:53 -0600 Subject: [PATCH] - Added timeout to blocking XNextEvent for caret/input check --- keyswap_service.sh | 1 + kintox11/src/Makefile | 2 +- kintox11/src/kintox11.c | 38 +++++++++++++++++++++++++++++++++++++- system-config/xactive.sh | 1 + 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/keyswap_service.sh b/keyswap_service.sh index efd2baf..419959d 100755 --- a/keyswap_service.sh +++ b/keyswap_service.sh @@ -11,6 +11,7 @@ cp ./system-config/keyswap.service ~/.config/systemd/user/keyswap.service cp ./system-config/kinto.desktop ~/.config/autostart/kinto.desktop cp ./kintox11/binary/kintox11 ~/.config/kinto/kintox11 cp ./system-config/xactive.sh ~/.config/kinto/xactive.sh +cp ./system-config/caret_Status.sh ~/.config/kinto/caret_Status.sh sed -i "s/{username}/`whoami`/g" ~/.config/systemd/user/keyswap.service sed -i "s/ExecStart=/ExecStart=${swapcmd}/g" ~/.config/systemd/user/keyswap.service systemctl --user daemon-reload diff --git a/kintox11/src/Makefile b/kintox11/src/Makefile index e78e368..b285328 100644 --- a/kintox11/src/Makefile +++ b/kintox11/src/Makefile @@ -2,4 +2,4 @@ CFLAGS=-g $(shell pkg-config --cflags json-c xmu) LDFLAGS=-g $(shell pkg-config --libs json-c xmu) all: - $(CC) kintox11.c $(CFLAGS) $(LDFLAGS) -o kintox11 + $(CC) kintox11.c $(CFLAGS) $(LDFLAGS) -lm -o kintox11 diff --git a/kintox11/src/kintox11.c b/kintox11/src/kintox11.c index c6c328c..78405d6 100644 --- a/kintox11/src/kintox11.c +++ b/kintox11/src/kintox11.c @@ -22,9 +22,38 @@ #include // `apt-get install libx11-dev` #include // `apt-get install libxmu-dev` #include // `apt install libjson-c-dev` +#include +#include + +static int wait_fd(int fd, double seconds) +{ + struct timeval tv; + fd_set in_fds; + FD_ZERO(&in_fds); + FD_SET(fd, &in_fds); + tv.tv_sec = trunc(seconds); + tv.tv_usec = (seconds - trunc(seconds))*1000000; + return select(fd+1, &in_fds, 0, 0, &tv); +} + +int XNextEventTimeout(Display *d, XEvent *e, double seconds) +{ + if (XPending(d) || wait_fd(ConnectionNumber(d),seconds)) { + XNextEvent(d, e); + return 0; + } else { + return 1; + } +} Bool xerror = False; +int check_caret() +{ + /*printf("caret\n");*/ + return 1; +} + int in_int(int a[],int size,int item) { int i,pos=-1; @@ -404,7 +433,14 @@ int main(void){ strcpy(prior_category,current_category); XEvent e; - XNextEvent(d, &e); + while(XNextEventTimeout(d, &e, 1.5)){ + check_caret(); + // Handle timeout "event" + // one option is to simulate an Expose event + e.type = Expose; + e.xexpose.count = 0; + } + // XNextEvent(d, &e); w = get_focus_window(d); w = get_top_window(d, w); w = get_named_window(d, w); diff --git a/system-config/xactive.sh b/system-config/xactive.sh index a8f2afd..dcc1a4d 100755 --- a/system-config/xactive.sh +++ b/system-config/xactive.sh @@ -1,3 +1,4 @@ #!/bin/bash +./caret_status.sh & ./kintox11 \ No newline at end of file