aboutsummaryrefslogtreecommitdiff
path: root/ui/input-linux.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2016-04-12 11:21:43 +0200
committerGerd Hoffmann <kraxel@redhat.com>2016-04-13 15:52:28 +0200
commitce47d3d4270e9c0f87cd9a3982f1a40a4514c6e3 (patch)
treebfb82396c4abae01f412002efeab96c4f8c9635c /ui/input-linux.c
parent0263b3a72fbd2ac9ba59ecc2449a9bc53ccf6fb3 (diff)
input-linux: refine mouse detection
Read absolute and relative axis information, only classify devices as mouse/tablet in case the x axis is present. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'ui/input-linux.c')
-rw-r--r--ui/input-linux.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/ui/input-linux.c b/ui/input-linux.c
index 9c921cc0ad..1d33b5c121 100644
--- a/ui/input-linux.c
+++ b/ui/input-linux.c
@@ -337,7 +337,7 @@ static void input_linux_event_mouse(void *opaque)
static void input_linux_complete(UserCreatable *uc, Error **errp)
{
InputLinux *il = INPUT_LINUX(uc);
- uint32_t evtmap;
+ uint32_t evtmap, relmap, absmap;
int rc, ver;
if (!il->evdev) {
@@ -359,16 +359,36 @@ static void input_linux_complete(UserCreatable *uc, Error **errp)
}
rc = ioctl(il->fd, EVIOCGBIT(0, sizeof(evtmap)), &evtmap);
+ if (rc < 0) {
+ error_setg(errp, "%s: failed to read event bits", il->evdev);
+ goto err_close;
+ }
if (evtmap & (1 << EV_REL)) {
- /* has relative axis -> assume mouse */
+ rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap);
+ if (rc < 0) {
+ relmap = 0;
+ }
+ }
+
+ if (evtmap & (1 << EV_ABS)) {
+ ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap);
+ if (rc < 0) {
+ absmap = 0;
+ }
+ }
+
+ if ((evtmap & (1 << EV_REL)) &&
+ (relmap & (1 << REL_X))) {
+ /* has relative x axis -> assume mouse */
qemu_set_fd_handler(il->fd, input_linux_event_mouse, NULL, il);
- } else if (evtmap & (1 << EV_ABS)) {
- /* has absolute axis -> not supported */
+ } else if ((evtmap & (1 << EV_ABS)) &&
+ (absmap & (1 << ABS_X))) {
+ /* has absolute x axis -> not supported */
error_setg(errp, "tablet/touchscreen not supported");
goto err_close;
} else if (evtmap & (1 << EV_KEY)) {
- /* has keys/buttons (and no axis) -> assume keyboard */
+ /* has keys/buttons (and no x axis) -> assume keyboard */
qemu_set_fd_handler(il->fd, input_linux_event_keyboard, NULL, il);
} else {
/* Huh? What is this? */