mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2025-07-01 23:35:47 +00:00
Merge remote-tracking branch 'tomblind/touchscreen'
This commit is contained in:
commit
4711129d14
@ -57,7 +57,11 @@ struct input_device {
|
||||
struct libevdev *dev;
|
||||
bool is_keyboard;
|
||||
bool is_mouse;
|
||||
<<<<<<< HEAD
|
||||
int rotate;
|
||||
=======
|
||||
bool is_touchscreen;
|
||||
>>>>>>> tomblind/touchscreen
|
||||
struct mapping* map;
|
||||
int key_map[KEY_MAX];
|
||||
int abs_map[ABS_MAX];
|
||||
@ -65,6 +69,8 @@ struct input_device {
|
||||
int fd;
|
||||
char modifiers;
|
||||
__s32 mouseDeltaX, mouseDeltaY, mouseScroll;
|
||||
__s32 touchDownX, touchDownY, touchX, touchY;
|
||||
struct timeval touchDownTime;
|
||||
short controllerId;
|
||||
int haptic_effect_id;
|
||||
int buttonFlags;
|
||||
@ -83,6 +89,11 @@ static const int hat_constants[3][3] = {{HAT_UP | HAT_LEFT, HAT_UP, HAT_UP | HAT
|
||||
|
||||
#define set_hat(flags, flag, hat, hat_flag) flags = (hat & hat_flag) == hat_flag ? flags | flag : flags & ~flag
|
||||
|
||||
#define TOUCH_UP -1
|
||||
#define TOUCH_CLICK_RADIUS 10
|
||||
#define TOUCH_CLICK_DELAY 100000 // microseconds
|
||||
#define TOUCH_RCLICK_TIME 750 // milliseconds
|
||||
|
||||
static struct input_device* devices = NULL;
|
||||
static int numDevices = 0;
|
||||
static int assignedControllerIds = 0;
|
||||
@ -273,6 +284,27 @@ static bool evdev_handle_event(struct input_event *ev, struct input_device *dev)
|
||||
case BTN_EXTRA:
|
||||
mouseCode = BUTTON_X2;
|
||||
break;
|
||||
case BTN_TOUCH:
|
||||
if (ev->value == 1) {
|
||||
dev->touchDownTime = ev->time;
|
||||
} else {
|
||||
if (dev->touchDownX != TOUCH_UP && dev->touchDownY != TOUCH_UP) {
|
||||
int deltaX = dev->touchX - dev->touchDownX;
|
||||
int deltaY = dev->touchY - dev->touchDownY;
|
||||
if (deltaX * deltaX + deltaY * deltaY < TOUCH_CLICK_RADIUS * TOUCH_CLICK_RADIUS) {
|
||||
struct timeval elapsedTime;
|
||||
timersub(&ev->time, &dev->touchDownTime, &elapsedTime);
|
||||
int holdTimeMs = elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000;
|
||||
int button = holdTimeMs >= TOUCH_RCLICK_TIME ? BUTTON_RIGHT : BUTTON_LEFT;
|
||||
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, button);
|
||||
usleep(TOUCH_CLICK_DELAY);
|
||||
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, button);
|
||||
}
|
||||
}
|
||||
dev->touchDownX = TOUCH_UP;
|
||||
dev->touchDownY = TOUCH_UP;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
gamepadModified = true;
|
||||
if (dev->map == NULL)
|
||||
@ -343,6 +375,30 @@ static bool evdev_handle_event(struct input_event *ev, struct input_device *dev)
|
||||
}
|
||||
break;
|
||||
case EV_ABS:
|
||||
if (dev->is_touchscreen) {
|
||||
switch (ev->code) {
|
||||
case ABS_X:
|
||||
if (dev->touchDownX == TOUCH_UP) {
|
||||
dev->touchDownX = ev->value;
|
||||
dev->touchX = ev->value;
|
||||
} else {
|
||||
dev->mouseDeltaX += (ev->value - dev->touchX);
|
||||
dev->touchX = ev->value;
|
||||
}
|
||||
break;
|
||||
case ABS_Y:
|
||||
if (dev->touchDownY == TOUCH_UP) {
|
||||
dev->touchDownY = ev->value;
|
||||
dev->touchY = ev->value;
|
||||
} else {
|
||||
dev->mouseDeltaY += (ev->value - dev->touchY);
|
||||
dev->touchY = ev->value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (dev->map == NULL)
|
||||
break;
|
||||
|
||||
@ -518,13 +574,14 @@ void evdev_create(const char* device, struct mapping* mappings, bool verbose, in
|
||||
|
||||
bool is_keyboard = libevdev_has_event_code(evdev, EV_KEY, KEY_Q);
|
||||
bool is_mouse = libevdev_has_event_type(evdev, EV_REL) || libevdev_has_event_code(evdev, EV_KEY, BTN_LEFT);
|
||||
bool is_touchscreen = libevdev_has_event_code(evdev, EV_KEY, BTN_TOUCH);
|
||||
|
||||
if (mappings == NULL && !(is_keyboard || is_mouse)) {
|
||||
if (mappings == NULL && !(is_keyboard || is_mouse || is_touchscreen)) {
|
||||
fprintf(stderr, "No mapping available for %s (%s) on %s\n", name, str_guid, device);
|
||||
mappings = default_mapping;
|
||||
}
|
||||
|
||||
if (!is_keyboard && !is_mouse)
|
||||
if (!is_keyboard && !is_mouse && !is_touchscreen)
|
||||
evdev_gamepads++;
|
||||
|
||||
int dev = numDevices;
|
||||
@ -549,7 +606,13 @@ void evdev_create(const char* device, struct mapping* mappings, bool verbose, in
|
||||
memset(&devices[dev].abs_map, -2, sizeof(devices[dev].abs_map));
|
||||
devices[dev].is_keyboard = is_keyboard;
|
||||
devices[dev].is_mouse = is_mouse;
|
||||
<<<<<<< HEAD
|
||||
devices[dev].rotate = rotate;
|
||||
=======
|
||||
devices[dev].is_touchscreen = is_touchscreen;
|
||||
devices[dev].touchDownX = TOUCH_UP;
|
||||
devices[dev].touchDownY = TOUCH_UP;
|
||||
>>>>>>> tomblind/touchscreen
|
||||
|
||||
int nbuttons = 0;
|
||||
for (int i = BTN_JOYSTICK; i < KEY_MAX; ++i) {
|
||||
@ -584,7 +647,7 @@ void evdev_create(const char* device, struct mapping* mappings, bool verbose, in
|
||||
fprintf(stderr, "Mapping for %s (%s) on %s is incorrect\n", name, str_guid, device);
|
||||
}
|
||||
|
||||
if (grabbingDevices && (is_keyboard || is_mouse)) {
|
||||
if (grabbingDevices && (is_keyboard || is_mouse || is_touchscreen)) {
|
||||
if (ioctl(fd, EVIOCGRAB, 1) < 0) {
|
||||
fprintf(stderr, "EVIOCGRAB failed with error %d\n", errno);
|
||||
}
|
||||
@ -711,7 +774,7 @@ void evdev_start() {
|
||||
// we're ready to take input events. Ctrl+C works up until
|
||||
// this point.
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
if ((devices[i].is_keyboard || devices[i].is_mouse) && ioctl(devices[i].fd, EVIOCGRAB, 1) < 0) {
|
||||
if ((devices[i].is_keyboard || devices[i].is_mouse || devices[i].is_touchscreen) && ioctl(devices[i].fd, EVIOCGRAB, 1) < 0) {
|
||||
fprintf(stderr, "EVIOCGRAB failed with error %d\n", errno);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user