From 828f4877b6e5e76b74230780e8230aec06220468 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 6 Sep 2014 16:25:09 -0700 Subject: [PATCH] Only bind to keyboards and mice that aren't gamepads --- .../binding/input/evdev/EvdevEvent.java | 4 ++++ .../binding/input/evdev/EvdevHandler.java | 9 ++++---- .../binding/input/evdev/EvdevReader.java | 22 +++++++++++++++++-- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/com/limelight/binding/input/evdev/EvdevEvent.java b/src/com/limelight/binding/input/evdev/EvdevEvent.java index ea51aa9f..cbe45005 100644 --- a/src/com/limelight/binding/input/evdev/EvdevEvent.java +++ b/src/com/limelight/binding/input/evdev/EvdevEvent.java @@ -24,6 +24,10 @@ public class EvdevEvent { public static final short BTN_FORWARD = 0x115; public static final short BTN_BACK = 0x116; public static final short BTN_TASK = 0x117; + public static final short BTN_GAMEPAD = 0x130; + + /* Keys */ + public static final short KEY_Q = 16; public short type; public short code; diff --git a/src/com/limelight/binding/input/evdev/EvdevHandler.java b/src/com/limelight/binding/input/evdev/EvdevHandler.java index 6e71d176..70ae2f08 100644 --- a/src/com/limelight/binding/input/evdev/EvdevHandler.java +++ b/src/com/limelight/binding/input/evdev/EvdevHandler.java @@ -26,9 +26,10 @@ public class EvdevHandler { } try { - // Check if it's a mouse - if (!EvdevReader.isMouse(fd)) { - // We only handle mice + // Check if it's a mouse or keyboard, but not a gamepad + if ((!EvdevReader.isMouse(fd) && !EvdevReader.isAlphaKeyboard(fd)) || + EvdevReader.isGamepad(fd)) { + // We only handle keyboards and mice return; } @@ -38,7 +39,7 @@ public class EvdevHandler { return; } - LimeLog.info("Grabbed device for raw mouse input: "+absolutePath); + LimeLog.info("Grabbed device for raw keyboard/mouse input: "+absolutePath); ByteBuffer buffer = ByteBuffer.allocate(EvdevEvent.EVDEV_MAX_EVENT_SIZE).order(ByteOrder.nativeOrder()); diff --git a/src/com/limelight/binding/input/evdev/EvdevReader.java b/src/com/limelight/binding/input/evdev/EvdevReader.java index c55212de..a2d7810c 100644 --- a/src/com/limelight/binding/input/evdev/EvdevReader.java +++ b/src/com/limelight/binding/input/evdev/EvdevReader.java @@ -43,8 +43,26 @@ public class EvdevReader { public static native boolean grab(int fd); public static native boolean ungrab(int fd); - // Returns true if the device is a mouse - public static native boolean isMouse(int fd); + // Used for checking device capabilities + public static native boolean hasRelAxis(int fd, short axis); + public static native boolean hasAbsAxis(int fd, short axis); + public static native boolean hasKey(int fd, short key); + + public static boolean isMouse(int fd) { + // This is the same check that Android does in EventHub.cpp + return hasRelAxis(fd, EvdevEvent.REL_X) && + hasRelAxis(fd, EvdevEvent.REL_Y) && + hasKey(fd, EvdevEvent.BTN_LEFT); + } + + public static boolean isAlphaKeyboard(int fd) { + // This is the same check that Android does in EventHub.cpp + return hasKey(fd, EvdevEvent.KEY_Q); + } + + public static boolean isGamepad(int fd) { + return hasKey(fd, EvdevEvent.BTN_GAMEPAD); + } // Returns the bytes read or -1 on error private static native int read(int fd, byte[] buffer);