- Added timeout to blocking XNextEvent for caret/input check

This commit is contained in:
Ben Reaves
2020-02-15 21:23:53 -06:00
parent 8f1795339e
commit dc016d9270
4 changed files with 40 additions and 2 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -22,9 +22,38 @@
#include <X11/Xlib.h> // `apt-get install libx11-dev`
#include <X11/Xmu/WinUtil.h> // `apt-get install libxmu-dev`
#include <json-c/json.h> // `apt install libjson-c-dev`
#include <sys/select.h>
#include <math.h>
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);

View File

@@ -1,3 +1,4 @@
#!/bin/bash
./caret_status.sh &
./kintox11