Lines 1-6
Link Here
|
1 |
--- src/input/evdev.c.orig 2021-12-20 00:24:48 UTC |
1 |
--- src/input/evdev.c.orig 2023-09-22 13:23:15.263067000 +0800 |
2 |
+++ src/input/evdev.c |
2 |
+++ src/input/evdev.c 2023-09-22 13:23:26.674639000 +0800 |
3 |
@@ -38,10 +38,10 @@ |
3 |
@@ -38,10 +38,13 @@ |
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-26
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 |
+extern bool isNoSdl; |
13 |
+bool iskeyboardgrab = true; |
14 |
+ |
12 |
+#if _BYTE_ORDER == _LITTLE_ENDIAN |
15 |
+#if _BYTE_ORDER == _LITTLE_ENDIAN |
13 |
#define int16_to_le(val) val |
16 |
#define int16_to_le(val) val |
14 |
#else |
17 |
#else |
15 |
#define int16_to_le(val) ((((val) >> 8) & 0x00FF) | (((val) << 8) & 0xFF00)) |
18 |
#define int16_to_le(val) ((((val) >> 8) & 0x00FF) | (((val) << 8) & 0xFF00)) |
16 |
@@ -66,8 +66,8 @@ struct input_device { |
19 |
@@ -66,8 +69,8 @@ |
17 |
int hats_state[3][2]; |
20 |
int hats_state[3][2]; |
18 |
int fd; |
21 |
int fd; |
19 |
char modifiers; |
22 |
char modifiers; |
20 |
- __s32 mouseDeltaX, mouseDeltaY, mouseScroll; |
23 |
- __s32 mouseDeltaX, mouseDeltaY, mouseVScroll, mouseHScroll; |
21 |
- __s32 touchDownX, touchDownY, touchX, touchY; |
24 |
- __s32 touchDownX, touchDownY, touchX, touchY; |
22 |
+ int32_t mouseDeltaX, mouseDeltaY, mouseScroll; |
25 |
+ int32_t mouseDeltaX, mouseDeltaY, mouseVScroll, mouseHScroll; |
23 |
+ int32_t touchDownX, touchDownY, touchX, touchY; |
26 |
+ int32_t touchDownX, touchDownY, touchX, touchY; |
24 |
struct timeval touchDownTime; |
27 |
struct timeval touchDownTime; |
25 |
struct timeval btnDownTime; |
28 |
struct timeval btnDownTime; |
26 |
short controllerId; |
29 |
short controllerId; |
|
|
30 |
@@ -127,6 +130,7 @@ |
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 @@ |
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 @@ |
50 |
if (dev->mouseHScroll != 0) { |
51 |
LiSendHScrollEvent(dev->mouseHScroll); |
52 |
dev->mouseHScroll = 0; |
53 |
- } |
54 |
+ } |
55 |
if (dev->gamepadModified) { |
56 |
if (dev->controllerId < 0) { |
57 |
for (int i = 0; i < MAX_GAMEPADS; i++) { |
58 |
@@ -404,6 +408,10 @@ |
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 @@ |
70 |
if (mappings == NULL && strstr(name, "Xbox 360 Wireless Receiver") != NULL) |
71 |
mappings = xwc_mapping; |
72 |
|
73 |
- bool is_keyboard = libevdev_has_event_code(evdev, EV_KEY, KEY_Q); |
74 |
+ bool is_keyboard = libevdev_has_event_code(evdev, EV_KEY, KEY_Q) && libevdev_get_id_version(evdev) < 500; |
75 |
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); |
77 |
|
78 |
@@ -850,6 +858,12 @@ |
79 |
} |
80 |
|
81 |
if (is_gamepad) { |
82 |
+ // stop to using SDL,test if break is better |
83 |
+ if (!isNoSdl) { |
84 |
+ libevdev_free(evdev); |
85 |
+ close(fd); |
86 |
+ return; |
87 |
+ } |
88 |
evdev_gamepads++; |
89 |
|
90 |
if (mappings == NULL) { |
91 |
@@ -1055,9 +1069,13 @@ |
92 |
// we're ready to take input events. Ctrl+C works up until |
93 |
// this point. |
94 |
for (int i = 0; i < numDevices; i++) { |
95 |
- if ((devices[i].is_keyboard || devices[i].is_mouse || devices[i].is_touchscreen) && ioctl(devices[i].fd, EVIOCGRAB, 1) < 0) { |
96 |
+ if ((devices[i].is_mouse || devices[i].is_touchscreen) && ioctl(devices[i].fd, EVIOCGRAB, 1) < 0) { |
97 |
fprintf(stderr, "EVIOCGRAB failed with error %d\n", errno); |
98 |
} |
99 |
+ if (devices[i].is_keyboard && libevdev_get_id_bustype(devices[i].dev) > 3) { |
100 |
+ if (ioctl(devices[i].fd, EVIOCGRAB, 1) < 0) |
101 |
+ fprintf(stderr, "EVIOCGRAB failed with error %d\n", errno); |
102 |
+ } |
103 |
} |
104 |
|
105 |
// Any new input devices detected after this point will be grabbed immediately |
106 |
@@ -1111,4 +1129,21 @@ |
107 |
event.value = 1; |
108 |
write(device->fd, (const void*) &event, sizeof(event)); |
109 |
device->haptic_effect_id = effect.id; |
110 |
+} |
111 |
+ |
112 |
+void grab_keyboard() { |
113 |
+ int grabnum; |
114 |
+ if (iskeyboardgrab) { |
115 |
+ grabnum = 0; |
116 |
+ iskeyboardgrab = false; |
117 |
+ } else { |
118 |
+ grabnum = 1; |
119 |
+ iskeyboardgrab = true; |
120 |
+ } |
121 |
+ for (int i = 0; i < numDevices; i++) { |
122 |
+ if (devices[i].is_keyboard && libevdev_get_id_bustype(devices[i].dev) > 3) { |
123 |
+ if (ioctl(devices[i].fd, EVIOCGRAB, grabnum) < 0) |
124 |
+ fprintf(stderr, "EVIOCGRAB failed with error %d\n", errno); |
125 |
+ } |
126 |
+ } |
127 |
} |