From cd7e0576e5aee07dc8ce2404cd960110179b05c1 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Thu, 12 Feb 2015 04:17:13 +0000 Subject: [PATCH] trying to remove devices from Xinput git-svn-id: svn+ssh://svn.code.sf.net/p/spacenav/code/trunk/spacenavd@187 ef983eb1-d774-4af8-acfd-baaf7b16a646 --- configure | 7 ++++++- src/dev.c | 3 +++ src/dev.h | 2 +- src/dev_usb_linux.c | 3 +++ src/proto_x11.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/proto_x11.h | 2 ++ 6 files changed, 59 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 2795a3c..ce6b1c4 100755 --- a/configure +++ b/configure @@ -28,7 +28,7 @@ test_kver() { check_header() { echo "#include <$1>" >.chkhdr.c if cpp .chkhdr.c >/dev/null 2>&1; then - echo "#define HAVE_`echo $1 | tr '[:lower:]' '[:upper:]' | sed 's/\./_/g'`" + echo "#define HAVE_`basename $1 | tr '[:lower:]' '[:upper:]' | sed 's/\./_/g'`" fi rm -f .chkhdr.c } @@ -39,6 +39,7 @@ OPT=yes DBG=yes X11=yes HOTPLUG=yes +XINPUT=yes VER=`head -1 README | sed 's/^.*- //'` if echo $VER | grep '$Rev' >/dev/null; then @@ -140,6 +141,9 @@ fi if [ "$X11" = 'yes' ]; then echo 'xlib = -L/usr/X11/lib -lX11' >>Makefile + if [ -n "`check_header X11/extensions/XInput2.h 2>&1`" ]; then + echo 'xlib += -lXi' >>Makefile + fi fi if [ -n "$add_cflags" ]; then @@ -170,6 +174,7 @@ echo >>src/config.h # check for alloca.h check_header alloca.h >>src/config.h +check_header X11/extensions/XInput2.h >>src/config.h echo >>src/config.h echo '#endif /* CONFIG_H_ */' >>src/config.h diff --git a/src/dev.c b/src/dev.c index 7fbfc02..8628b25 100644 --- a/src/dev.c +++ b/src/dev.c @@ -25,6 +25,7 @@ along with this program. If not, see . #include "dev_serial.h" #include "event.h" /* remove pending events upon device removal */ #include "spnavd.h" +#include "proto_x11.h" static struct device *add_device(void); static struct device *dev_path_in_use(char const * dev_path); @@ -86,6 +87,8 @@ int init_devices(void) fprintf(stderr, "failed to find any supported devices\n"); return -1; } + + drop_xinput(); return 0; } diff --git a/src/dev.h b/src/dev.h index f7ef691..8bf68b4 100644 --- a/src/dev.h +++ b/src/dev.h @@ -39,7 +39,7 @@ struct device { int (*read)(struct device*, struct dev_input*); void (*set_led)(struct device*, int); - struct device *next; + struct device *next; }; int init_devices(void); diff --git a/src/dev_usb_linux.c b/src/dev_usb_linux.c index 6d1dac3..ad1262a 100644 --- a/src/dev_usb_linux.c +++ b/src/dev_usb_linux.c @@ -229,6 +229,9 @@ static int read_evdev(struct device *dev, struct dev_input *inp) break; default: + if(verbose) { + printf("unexpected event: %d\n", iev.type); + } return -1; } } diff --git a/src/proto_x11.c b/src/proto_x11.c index a338ff8..86ebc6f 100644 --- a/src/proto_x11.c +++ b/src/proto_x11.c @@ -35,9 +35,15 @@ along with this program. If not, see . #include "proto_x11.h" #include "client.h" #include "spnavd.h" +#include "dev.h" #include "xdetect.h" #include "kbemu.h" +#ifdef HAVE_XINPUT2_H +#include +#include +#endif + enum cmd_msg { CMD_NONE, @@ -168,6 +174,8 @@ int init_x11(void) kbemu_set_display(dpy); xdet_stop(); /* stop X server detection if it was running */ + + drop_xinput(); return 0; } @@ -346,6 +354,42 @@ void remove_client_window(Window win) } } +void drop_xinput(void) +{ +#ifdef HAVE_XINPUT2_H + XIDeviceInfo *xidevs; + int i, num_devs; + static Atom atom_enabled; + + if(!dpy) return; + + if(!atom_enabled) { + atom_enabled = XInternAtom(dpy, "Device Enabled", False); + } + + if(!(xidevs = XIQueryDevice(dpy, XIAllDevices, &num_devs))) { + fprintf(stderr, "failed to query XInput2 devices\n"); + return; + } + + for(i=0; iname, xidevs[i].name) == 0 && xidevs[i].enabled) { + unsigned char zero = 0; + printf("Removing device \"%s\" from X server\n", dev->name); + + XIChangeProperty(dpy, xidevs[i].deviceid, atom_enabled, XA_INTEGER, 8, PropModeReplace, &zero, 1); + break; + } + dev = dev->next; + } + } + XIFreeDeviceInfo(xidevs); + +#endif /* HAVE_XINPUT2_H */ +} + /* X11 error handler */ static int xerr(Display *dpy, XErrorEvent *err) diff --git a/src/proto_x11.h b/src/proto_x11.h index 6b78361..49881e5 100644 --- a/src/proto_x11.h +++ b/src/proto_x11.h @@ -37,5 +37,7 @@ int handle_xevents(fd_set *rset); void set_client_window(Window win); void remove_client_window(Window win); +void drop_xinput(void); + #endif /* PROTO_X11_H_ */