mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-10-25 13:30:42 +00:00
Fix handling of buttons outside the normal joystick range
See https://github.com/libsdl-org/SDL/commit/aa03b9d7afedefddda4e7f1575d87865ee5f3d93 Fixes #788 Fixes #696 Fixes #675 Fixes #693 Fixes #642
This commit is contained in:
1 parent
d45567b5ee
commit
4b41692fd8
1 file changed
+13
-7
+13
-7
@@ -61,8 +61,8 @@ struct input_device {
|
|||||||
bool is_touchscreen;
|
bool is_touchscreen;
|
||||||
int rotate;
|
int rotate;
|
||||||
struct mapping* map;
|
struct mapping* map;
|
||||||
int key_map[KEY_MAX];
|
int key_map[KEY_CNT];
|
||||||
int abs_map[ABS_MAX];
|
int abs_map[ABS_CNT];
|
||||||
int hats_state[3][2];
|
int hats_state[3][2];
|
||||||
int fd;
|
int fd;
|
||||||
char modifiers;
|
char modifiers;
|
||||||
@@ -295,6 +295,8 @@ static bool evdev_handle_event(struct input_event *ev, struct input_device *dev)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EV_KEY:
|
case EV_KEY:
|
||||||
|
if (ev->code > KEY_MAX)
|
||||||
|
return true;
|
||||||
if (ev->code < sizeof(keyCodes)/sizeof(keyCodes[0])) {
|
if (ev->code < sizeof(keyCodes)/sizeof(keyCodes[0])) {
|
||||||
char modifier = 0;
|
char modifier = 0;
|
||||||
switch (ev->code) {
|
switch (ev->code) {
|
||||||
@@ -335,7 +337,7 @@ static bool evdev_handle_event(struct input_event *ev, struct input_device *dev)
|
|||||||
} else {
|
} else {
|
||||||
int mouseCode = 0;
|
int mouseCode = 0;
|
||||||
short gamepadCode = 0;
|
short gamepadCode = 0;
|
||||||
int index = ev->code > BTN_MISC && ev->code < (BTN_MISC + KEY_MAX) ? dev->key_map[ev->code - BTN_MISC] : -1;
|
int index = dev->key_map[ev->code];
|
||||||
|
|
||||||
switch (ev->code) {
|
switch (ev->code) {
|
||||||
case BTN_LEFT:
|
case BTN_LEFT:
|
||||||
@@ -484,6 +486,8 @@ static bool evdev_handle_event(struct input_event *ev, struct input_device *dev)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EV_ABS:
|
case EV_ABS:
|
||||||
|
if (ev->code > ABS_MAX)
|
||||||
|
return true;
|
||||||
if (dev->is_touchscreen) {
|
if (dev->is_touchscreen) {
|
||||||
switch (ev->code) {
|
switch (ev->code) {
|
||||||
case ABS_X:
|
case ABS_X:
|
||||||
@@ -605,7 +609,7 @@ static bool evdev_handle_mapping_event(struct input_event *ev, struct input_devi
|
|||||||
int index, hat_index;
|
int index, hat_index;
|
||||||
switch (ev->type) {
|
switch (ev->type) {
|
||||||
case EV_KEY:
|
case EV_KEY:
|
||||||
index = ev->code > BTN_MISC && ev->code < (BTN_MISC + KEY_MAX) ? dev->key_map[ev->code - BTN_MISC] : -1;
|
index = dev->key_map[ev->code];
|
||||||
if (currentKey != NULL) {
|
if (currentKey != NULL) {
|
||||||
if (ev->value)
|
if (ev->value)
|
||||||
*currentKey = index;
|
*currentKey = index;
|
||||||
@@ -788,6 +792,7 @@ void evdev_create(const char* device, struct mapping* mappings, bool verbose, in
|
|||||||
devices[dev].fd = fd;
|
devices[dev].fd = fd;
|
||||||
devices[dev].dev = evdev;
|
devices[dev].dev = evdev;
|
||||||
devices[dev].map = mappings;
|
devices[dev].map = mappings;
|
||||||
|
/* Set unused evdev indices to -2 to avoid aliasing with the default -1 in our mappings */
|
||||||
memset(&devices[dev].key_map, -2, sizeof(devices[dev].key_map));
|
memset(&devices[dev].key_map, -2, sizeof(devices[dev].key_map));
|
||||||
memset(&devices[dev].abs_map, -2, sizeof(devices[dev].abs_map));
|
memset(&devices[dev].abs_map, -2, sizeof(devices[dev].abs_map));
|
||||||
devices[dev].is_keyboard = is_keyboard;
|
devices[dev].is_keyboard = is_keyboard;
|
||||||
@@ -798,13 +803,14 @@ void evdev_create(const char* device, struct mapping* mappings, bool verbose, in
|
|||||||
devices[dev].touchDownY = TOUCH_UP;
|
devices[dev].touchDownY = TOUCH_UP;
|
||||||
|
|
||||||
int nbuttons = 0;
|
int nbuttons = 0;
|
||||||
|
/* Count joystick buttons first like SDL does */
|
||||||
for (int i = BTN_JOYSTICK; i < KEY_MAX; ++i) {
|
for (int i = BTN_JOYSTICK; i < KEY_MAX; ++i) {
|
||||||
if (libevdev_has_event_code(devices[dev].dev, EV_KEY, i))
|
if (libevdev_has_event_code(devices[dev].dev, EV_KEY, i))
|
||||||
devices[dev].key_map[i - BTN_MISC] = nbuttons++;
|
devices[dev].key_map[i] = nbuttons++;
|
||||||
}
|
}
|
||||||
for (int i = BTN_MISC; i < BTN_JOYSTICK; ++i) {
|
for (int i = 0; i < BTN_JOYSTICK; ++i) {
|
||||||
if (libevdev_has_event_code(devices[dev].dev, EV_KEY, i))
|
if (libevdev_has_event_code(devices[dev].dev, EV_KEY, i))
|
||||||
devices[dev].key_map[i - BTN_MISC] = nbuttons++;
|
devices[dev].key_map[i] = nbuttons++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int naxes = 0;
|
int naxes = 0;
|
||||||
|
|||||||
Reference in new issue
Block a user