From 44930716ba5eb208f313c2a9680c40b519a4e88a Mon Sep 17 00:00:00 2001 From: Zoran Vuckovic Date: Thu, 8 Jun 2017 18:49:08 +0200 Subject: [PATCH] Add player mouse index handling to udev input driver --- input/drivers/udev_input.c | 73 ++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index ba04a12488..fea29bbe50 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -54,6 +54,7 @@ #include "../common/linux_common.h" #include "../common/udev_common.h" #include "../common/epoll_common.h" +#include "../configuration.h" #include "../../verbosity.h" @@ -184,6 +185,33 @@ static void udev_input_kb_free(void) #endif } +static udev_input_mouse_t *udev_get_mouse(struct udev_input *udev, unsigned port) +{ + unsigned i; + unsigned mouse_index = 0; + settings_t *settings = config_get_ptr(); + udev_input_mouse_t *mouse = NULL; + + if (port >= MAX_USERS) + return NULL; + + for (i = 0; i < udev->num_devices; ++i) + { + if (udev->devices[i]->type != UDEV_INPUT_MOUSE) + continue; + + if (mouse_index == settings->uints.input_mouse_index[port]) + { + mouse = &udev->devices[i]->state.mouse; + break; + } + + ++mouse_index; + } + + return mouse; +} + static void udev_handle_touchpad(void *data, const struct input_event *event, udev_input_device_t *dev) { @@ -512,20 +540,7 @@ static void udev_input_poll(void *data) static int16_t udev_mouse_state(udev_input_t *udev, unsigned port, unsigned id, bool screen) { - unsigned i, j; - udev_input_mouse_t *mouse = NULL; - - for (i = j = 0; i < udev->num_devices; ++i) - { - if (udev->devices[i]->type != UDEV_INPUT_MOUSE) - continue; - if (j == port) - { - mouse = &udev->devices[i]->state.mouse; - break; - } - ++j; - } + udev_input_mouse_t *mouse = udev_get_mouse(udev, port); if (!mouse) return 0; @@ -558,20 +573,7 @@ static int16_t udev_mouse_state(udev_input_t *udev, static int16_t udev_lightgun_state(udev_input_t *udev, unsigned port, unsigned id) { - unsigned i, j; - udev_input_mouse_t *mouse = NULL; - - for (i = j = 0; i < udev->num_devices; ++i) - { - if (udev->devices[i]->type != UDEV_INPUT_MOUSE) - continue; - if (j == port) - { - mouse = &udev->devices[i]->state.mouse; - break; - } - ++j; - } + udev_input_mouse_t *mouse = udev_get_mouse(udev, port); if (!mouse) return 0; @@ -623,13 +625,12 @@ static int16_t udev_pointer_state(udev_input_t *udev, unsigned port, unsigned id, bool screen) { struct video_viewport vp; - unsigned i, j; bool inside = false; int16_t res_x = 0; int16_t res_y = 0; int16_t res_screen_x = 0; int16_t res_screen_y = 0; - udev_input_mouse_t *mouse = NULL; + udev_input_mouse_t *mouse = udev_get_mouse(udev, port); vp.x = 0; vp.y = 0; @@ -638,18 +639,6 @@ static int16_t udev_pointer_state(udev_input_t *udev, vp.full_width = 0; vp.full_height = 0; - for (i = j = 0; i < udev->num_devices; ++i) - { - if (udev->devices[i]->type != UDEV_INPUT_MOUSE) - continue; - if (j == port) - { - mouse = &udev->devices[i]->state.mouse; - break; - } - ++j; - } - if (!mouse) return 0;