kopia lustrzana https://github.com/FreeSpacenav/spacenavd
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-baaf7b16a646pull/1/head
rodzic
0517f0e481
commit
cd7e0576e5
|
@ -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
|
||||
|
|
|
@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,9 +35,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "proto_x11.h"
|
||||
#include "client.h"
|
||||
#include "spnavd.h"
|
||||
#include "dev.h"
|
||||
#include "xdetect.h"
|
||||
#include "kbemu.h"
|
||||
|
||||
#ifdef HAVE_XINPUT2_H
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/extensions/XInput2.h>
|
||||
#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; i<num_devs; i++) {
|
||||
struct device *dev = get_devices();
|
||||
while(dev) {
|
||||
if(strcmp(dev->name, 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)
|
||||
|
|
|
@ -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_ */
|
||||
|
|
Ładowanie…
Reference in New Issue