mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2025-07-01 23:35:47 +00:00
Applied display rotation to mouse movement in evdev
This commit is contained in:
parent
aae24557f9
commit
b22b07e5a0
@ -57,6 +57,7 @@ struct input_device {
|
||||
struct libevdev *dev;
|
||||
bool is_keyboard;
|
||||
bool is_mouse;
|
||||
int rotate;
|
||||
struct mapping* map;
|
||||
int key_map[KEY_MAX];
|
||||
int abs_map[ABS_MAX];
|
||||
@ -177,7 +178,20 @@ static bool evdev_handle_event(struct input_event *ev, struct input_device *dev)
|
||||
switch (ev->type) {
|
||||
case EV_SYN:
|
||||
if (dev->mouseDeltaX != 0 || dev->mouseDeltaY != 0) {
|
||||
LiSendMouseMoveEvent(dev->mouseDeltaX, dev->mouseDeltaY);
|
||||
switch (dev->rotate) {
|
||||
case 90:
|
||||
LiSendMouseMoveEvent(dev->mouseDeltaY, -dev->mouseDeltaX);
|
||||
break;
|
||||
case 180:
|
||||
LiSendMouseMoveEvent(-dev->mouseDeltaX, -dev->mouseDeltaY);
|
||||
break;
|
||||
case 270:
|
||||
LiSendMouseMoveEvent(-dev->mouseDeltaY, dev->mouseDeltaX);
|
||||
break;
|
||||
default:
|
||||
LiSendMouseMoveEvent(dev->mouseDeltaX, dev->mouseDeltaY);
|
||||
break;
|
||||
}
|
||||
dev->mouseDeltaX = 0;
|
||||
dev->mouseDeltaY = 0;
|
||||
}
|
||||
@ -455,7 +469,7 @@ static int evdev_handle(int fd) {
|
||||
return LOOP_OK;
|
||||
}
|
||||
|
||||
void evdev_create(const char* device, struct mapping* mappings, bool verbose) {
|
||||
void evdev_create(const char* device, struct mapping* mappings, bool verbose, int rotate) {
|
||||
int fd = open(device, O_RDWR|O_NONBLOCK);
|
||||
if (fd <= 0) {
|
||||
fprintf(stderr, "Failed to open device %s\n", device);
|
||||
@ -535,6 +549,7 @@ void evdev_create(const char* device, struct mapping* mappings, bool verbose) {
|
||||
memset(&devices[dev].abs_map, -2, sizeof(devices[dev].abs_map));
|
||||
devices[dev].is_keyboard = is_keyboard;
|
||||
devices[dev].is_mouse = is_mouse;
|
||||
devices[dev].rotate = rotate;
|
||||
|
||||
int nbuttons = 0;
|
||||
for (int i = BTN_JOYSTICK; i < KEY_MAX; ++i) {
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
extern int evdev_gamepads;
|
||||
|
||||
void evdev_create(const char* device, struct mapping* mappings, bool verbose);
|
||||
void evdev_create(const char* device, struct mapping* mappings, bool verbose, int rotate);
|
||||
void evdev_loop();
|
||||
|
||||
void evdev_init();
|
||||
|
@ -37,6 +37,7 @@ static struct mapping* defaultMappings;
|
||||
static struct udev *udev;
|
||||
static struct udev_monitor *udev_mon;
|
||||
static int udev_fd;
|
||||
static int inputRotate;
|
||||
|
||||
static int udev_handle(int fd) {
|
||||
struct udev_device *dev = udev_monitor_receive_device(udev_mon);
|
||||
@ -46,7 +47,7 @@ static int udev_handle(int fd) {
|
||||
const char *devnode = udev_device_get_devnode(dev);
|
||||
int id;
|
||||
if (devnode != NULL && sscanf(devnode, "/dev/input/event%d", &id) == 1) {
|
||||
evdev_create(devnode, defaultMappings, debug);
|
||||
evdev_create(devnode, defaultMappings, debug, inputRotate);
|
||||
}
|
||||
}
|
||||
udev_device_unref(dev);
|
||||
@ -54,7 +55,7 @@ static int udev_handle(int fd) {
|
||||
return LOOP_OK;
|
||||
}
|
||||
|
||||
void udev_init(bool autoload, struct mapping* mappings, bool verbose) {
|
||||
void udev_init(bool autoload, struct mapping* mappings, bool verbose, int rotate) {
|
||||
udev = udev_new();
|
||||
debug = verbose;
|
||||
if (!udev) {
|
||||
@ -76,7 +77,7 @@ void udev_init(bool autoload, struct mapping* mappings, bool verbose) {
|
||||
const char *devnode = udev_device_get_devnode(dev);
|
||||
int id;
|
||||
if (devnode != NULL && sscanf(devnode, "/dev/input/event%d", &id) == 1) {
|
||||
evdev_create(devnode, mappings, verbose);
|
||||
evdev_create(devnode, mappings, verbose, rotate);
|
||||
}
|
||||
udev_device_unref(dev);
|
||||
}
|
||||
@ -89,6 +90,7 @@ void udev_init(bool autoload, struct mapping* mappings, bool verbose) {
|
||||
udev_monitor_enable_receiving(udev_mon);
|
||||
|
||||
defaultMappings = mappings;
|
||||
inputRotate = rotate;
|
||||
|
||||
int udev_fd = udev_monitor_get_fd(udev_mon);
|
||||
loop_add_fd(udev_fd, &udev_handle, POLLIN);
|
||||
|
@ -19,5 +19,5 @@
|
||||
|
||||
#include "mapping.h"
|
||||
|
||||
void udev_init(bool autoload, struct mapping* mappings, bool verbose);
|
||||
void udev_init(bool autoload, struct mapping* mappings, bool verbose, int rotate);
|
||||
void evdev_destroy();
|
||||
|
@ -245,7 +245,7 @@ int main(int argc, char* argv[]) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
evdev_create(config.inputs[0], NULL, config.debug_level > 0);
|
||||
evdev_create(config.inputs[0], NULL, config.debug_level > 0, config.rotate);
|
||||
evdev_map(config.inputs[0]);
|
||||
exit(0);
|
||||
}
|
||||
@ -342,10 +342,10 @@ int main(int argc, char* argv[]) {
|
||||
if (config.debug_level > 0)
|
||||
printf("Add input %s...\n", config.inputs[i]);
|
||||
|
||||
evdev_create(config.inputs[i], mappings, config.debug_level > 0);
|
||||
evdev_create(config.inputs[i], mappings, config.debug_level > 0, config.rotate);
|
||||
}
|
||||
|
||||
udev_init(!inputAdded, mappings, config.debug_level > 0);
|
||||
udev_init(!inputAdded, mappings, config.debug_level > 0, config.rotate);
|
||||
evdev_init();
|
||||
rumble_handler = evdev_rumble;
|
||||
#ifdef HAVE_LIBCEC
|
||||
|
Loading…
x
Reference in New Issue
Block a user