Lines 1-6
Link Here
|
1 |
--- src/input/evdev.c.orig 2023-09-24 06:11:13 UTC |
1 |
--- src/input/evdev.c.orig 2023-09-01 23:40:56 UTC |
2 |
+++ src/input/evdev.c |
2 |
+++ src/input/evdev.c |
3 |
@@ -38,10 +38,13 @@ |
3 |
@@ -38,10 +38,12 @@ |
4 |
#include <limits.h> |
4 |
#include <limits.h> |
5 |
#include <unistd.h> |
5 |
#include <unistd.h> |
6 |
#include <pthread.h> |
6 |
#include <pthread.h> |
Lines 9-22
Link Here
|
9 |
#include <math.h> |
9 |
#include <math.h> |
10 |
|
10 |
|
11 |
-#if __BYTE_ORDER == __LITTLE_ENDIAN |
11 |
-#if __BYTE_ORDER == __LITTLE_ENDIAN |
12 |
+void grab_keyboard(); |
|
|
13 |
+bool iskeyboardgrab = true; |
12 |
+bool iskeyboardgrab = true; |
14 |
+ |
13 |
+ |
15 |
+#if _BYTE_ORDER == _LITTLE_ENDIAN |
14 |
+#if _BYTE_ORDER == _LITTLE_ENDIAN |
16 |
#define int16_to_le(val) val |
15 |
#define int16_to_le(val) val |
17 |
#else |
16 |
#else |
18 |
#define int16_to_le(val) ((((val) >> 8) & 0x00FF) | (((val) << 8) & 0xFF00)) |
17 |
#define int16_to_le(val) ((((val) >> 8) & 0x00FF) | (((val) << 8) & 0xFF00)) |
19 |
@@ -66,8 +69,8 @@ struct input_device { |
18 |
@@ -66,8 +68,8 @@ struct input_device { |
20 |
int hats_state[3][2]; |
19 |
int hats_state[3][2]; |
21 |
int fd; |
20 |
int fd; |
22 |
char modifiers; |
21 |
char modifiers; |
Lines 27-52
Link Here
|
27 |
struct timeval touchDownTime; |
26 |
struct timeval touchDownTime; |
28 |
struct timeval btnDownTime; |
27 |
struct timeval btnDownTime; |
29 |
short controllerId; |
28 |
short controllerId; |
30 |
@@ -127,6 +130,7 @@ int evdev_gamepads = 0; |
29 |
@@ -343,7 +345,7 @@ static bool evdev_handle_event(struct input_event *ev, |
31 |
|
|
|
32 |
#define ACTION_MODIFIERS (MODIFIER_SHIFT|MODIFIER_ALT|MODIFIER_CTRL) |
33 |
#define QUIT_KEY KEY_Q |
34 |
+#define UNGRAB_KEY KEY_G |
35 |
#define QUIT_BUTTONS (PLAY_FLAG|BACK_FLAG|LB_FLAG|RB_FLAG) |
36 |
|
37 |
static bool (*handler) (struct input_event*, struct input_device*); |
38 |
@@ -247,8 +251,8 @@ void *HandleMouseEmulation(void* param) |
39 |
deltaY = pow((float)rawY / 32767.0f * MOUSE_EMULATION_MOTION_MULTIPLIER, 3); |
40 |
|
41 |
// Enforce deadzones |
42 |
- deltaX = fabs(deltaX) > MOUSE_EMULATION_DEADZONE ? deltaX - MOUSE_EMULATION_DEADZONE : 0; |
43 |
- deltaY = fabs(deltaY) > MOUSE_EMULATION_DEADZONE ? deltaY - MOUSE_EMULATION_DEADZONE : 0; |
44 |
+ deltaX = abs(deltaX) > MOUSE_EMULATION_DEADZONE ? deltaX - MOUSE_EMULATION_DEADZONE : 0; |
45 |
+ deltaY = abs(deltaY) > MOUSE_EMULATION_DEADZONE ? deltaY - MOUSE_EMULATION_DEADZONE : 0; |
46 |
|
47 |
if (deltaX != 0 || deltaY != 0) |
48 |
LiSendMouseMoveEvent(deltaX, -deltaY); |
49 |
@@ -343,7 +347,7 @@ static bool evdev_handle_event(struct input_event *ev, |
50 |
if (dev->mouseHScroll != 0) { |
30 |
if (dev->mouseHScroll != 0) { |
51 |
LiSendHScrollEvent(dev->mouseHScroll); |
31 |
LiSendHScrollEvent(dev->mouseHScroll); |
52 |
dev->mouseHScroll = 0; |
32 |
dev->mouseHScroll = 0; |
Lines 55-72
Link Here
|
55 |
if (dev->gamepadModified) { |
35 |
if (dev->gamepadModified) { |
56 |
if (dev->controllerId < 0) { |
36 |
if (dev->controllerId < 0) { |
57 |
for (int i = 0; i < MAX_GAMEPADS; i++) { |
37 |
for (int i = 0; i < MAX_GAMEPADS; i++) { |
58 |
@@ -404,6 +408,10 @@ static bool evdev_handle_event(struct input_event *ev, |
38 |
@@ -813,7 +815,7 @@ void evdev_create(const char* device, struct mapping* |
59 |
return true; |
|
|
60 |
} else if (waitingToExitOnModifiersUp && dev->modifiers == 0) |
61 |
return false; |
62 |
+ if ((dev->modifiers & ACTION_MODIFIERS) == ACTION_MODIFIERS && |
63 |
+ ev->code == UNGRAB_KEY && ev->value != 0) { |
64 |
+ grab_keyboard(); |
65 |
+ } |
66 |
|
67 |
short code = 0x80 << 8 | keyCodes[ev->code]; |
68 |
LiSendKeyboardEvent(code, ev->value?KEY_ACTION_DOWN:KEY_ACTION_UP, dev->modifiers); |
69 |
@@ -813,7 +821,7 @@ void evdev_create(const char* device, struct mapping* |
70 |
if (mappings == NULL && strstr(name, "Xbox 360 Wireless Receiver") != NULL) |
39 |
if (mappings == NULL && strstr(name, "Xbox 360 Wireless Receiver") != NULL) |
71 |
mappings = xwc_mapping; |
40 |
mappings = xwc_mapping; |
72 |
|
41 |
|
Lines 75-114
Link Here
|
75 |
bool is_mouse = libevdev_has_event_type(evdev, EV_REL) || libevdev_has_event_code(evdev, EV_KEY, BTN_LEFT); |
44 |
bool is_mouse = libevdev_has_event_type(evdev, EV_REL) || libevdev_has_event_code(evdev, EV_KEY, BTN_LEFT); |
76 |
bool is_touchscreen = libevdev_has_event_code(evdev, EV_KEY, BTN_TOUCH); |
45 |
bool is_touchscreen = libevdev_has_event_code(evdev, EV_KEY, BTN_TOUCH); |
77 |
|
46 |
|
78 |
@@ -1055,9 +1063,13 @@ void evdev_start() { |
47 |
@@ -1055,8 +1057,12 @@ void evdev_start() { |
79 |
// we're ready to take input events. Ctrl+C works up until |
48 |
// we're ready to take input events. Ctrl+C works up until |
80 |
// this point. |
49 |
// this point. |
81 |
for (int i = 0; i < numDevices; i++) { |
50 |
for (int i = 0; i < numDevices; i++) { |
82 |
- if ((devices[i].is_keyboard || devices[i].is_mouse || devices[i].is_touchscreen) && ioctl(devices[i].fd, EVIOCGRAB, 1) < 0) { |
51 |
- if ((devices[i].is_keyboard || devices[i].is_mouse || devices[i].is_touchscreen) && ioctl(devices[i].fd, EVIOCGRAB, 1) < 0) { |
83 |
+ if ((devices[i].is_mouse || devices[i].is_touchscreen) && ioctl(devices[i].fd, EVIOCGRAB, 1) < 0) { |
52 |
+ if ((devices[i].is_mouse || devices[i].is_touchscreen) && ioctl(devices[i].fd, EVIOCGRAB, 1) < 0) { |
84 |
fprintf(stderr, "EVIOCGRAB failed with error %d\n", errno); |
53 |
fprintf(stderr, "EVIOCGRAB failed with error %d\n", errno); |
85 |
} |
54 |
+ } |
86 |
+ if (devices[i].is_keyboard && libevdev_get_id_bustype(devices[i].dev) > 3) { |
55 |
+ if (devices[i].is_keyboard && libevdev_get_id_bustype(devices[i].dev) > 3) { |
87 |
+ if (ioctl(devices[i].fd, EVIOCGRAB, 1) < 0) |
56 |
+ if (ioctl(devices[i].fd, EVIOCGRAB, 1) < 0) |
88 |
+ fprintf(stderr, "EVIOCGRAB failed with error %d\n", errno); |
57 |
+ fprintf(stderr, "EVIOCGRAB failed with error %d\n", errno); |
89 |
+ } |
58 |
} |
90 |
} |
59 |
} |
91 |
|
60 |
|
92 |
// Any new input devices detected after this point will be grabbed immediately |
|
|
93 |
@@ -1111,4 +1123,21 @@ void evdev_rumble(unsigned short controller_id, unsign |
94 |
event.value = 1; |
95 |
write(device->fd, (const void*) &event, sizeof(event)); |
96 |
device->haptic_effect_id = effect.id; |
97 |
+} |
98 |
+ |
99 |
+void grab_keyboard() { |
100 |
+ int grabnum; |
101 |
+ if (iskeyboardgrab) { |
102 |
+ grabnum = 0; |
103 |
+ iskeyboardgrab = false; |
104 |
+ } else { |
105 |
+ grabnum = 1; |
106 |
+ iskeyboardgrab = true; |
107 |
+ } |
108 |
+ for (int i = 0; i < numDevices; i++) { |
109 |
+ if (devices[i].is_keyboard && libevdev_get_id_bustype(devices[i].dev) > 3) { |
110 |
+ if (ioctl(devices[i].fd, EVIOCGRAB, grabnum) < 0) |
111 |
+ fprintf(stderr, "EVIOCGRAB failed with error %d\n", errno); |
112 |
+ } |
113 |
+ } |
114 |
} |