summaryrefslogtreecommitdiffstats
path: root/platform/x11/joystick_linux.cpp
diff options
context:
space:
mode:
authorpunto- <ariel@godotengine.org>2016-02-02 19:32:03 -0300
committerpunto- <ariel@godotengine.org>2016-02-02 19:32:03 -0300
commita24fc3369c711d5ee5989c15eca5d525f0dcd728 (patch)
tree31803fd8fb5cb5ff666b04e176b4db4b45d0c45e /platform/x11/joystick_linux.cpp
parent9c4c6e4c4feac786be69c8f18425c5d3258cfcf4 (diff)
parentf7b1ab843c351a9aa43fed8bc20cc33c702eee86 (diff)
downloadredot-engine-a24fc3369c711d5ee5989c15eca5d525f0dcd728.tar.gz
Merge pull request #3559 from Hinsbart/device_fix
x11: fix non-gamepad devices being detected as joysticks
Diffstat (limited to 'platform/x11/joystick_linux.cpp')
-rw-r--r--platform/x11/joystick_linux.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/platform/x11/joystick_linux.cpp b/platform/x11/joystick_linux.cpp
index 208bb2a2b7..1a11876d5d 100644
--- a/platform/x11/joystick_linux.cpp
+++ b/platform/x11/joystick_linux.cpp
@@ -38,8 +38,9 @@
#include <fcntl.h>
#include <errno.h>
-#define test_bit(nr, addr) (((1UL << ((nr) % (sizeof(long) * 8))) & ((addr)[(nr) / (sizeof(long) * 8)])) != 0)
-#define NBITS(x) ((((x)-1)/(sizeof(long) * 8))+1)
+#define LONG_BITS (sizeof(long) * 8)
+#define test_bit(nr, addr) (((1UL << ((nr) % LONG_BITS)) & ((addr)[(nr) / LONG_BITS])) != 0)
+#define NBITS(x) ((((x)-1)/LONG_BITS)+1)
static const char* ignore_str = "/dev/input/js";
@@ -311,7 +312,7 @@ void joystick_linux::open_joystick(const char *p_path) {
//check if the device supports basic gamepad events, prevents certain keyboards from
//being detected as joysticks
if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) &&
- ((test_bit(ABS_X, absbit) || test_bit(ABS_Y, absbit)) ||
+ ((test_bit(ABS_X, absbit) || test_bit(ABS_Y, absbit) || test_bit(ABS_HAT0X, absbit)) &&
(test_bit(BTN_A, keybit) || test_bit(BTN_THUMBL, keybit))))) {
close(fd);
return;