From a74197dc49ab2c8667f4ac45855d9dd5540d45f6 Mon Sep 17 00:00:00 2001 From: Zoran Vuckovic Date: Thu, 8 Jun 2017 16:13:45 +0200 Subject: [PATCH 1/4] Add player mouse index setting --- configuration.c | 6 ++++++ configuration.h | 1 + intl/msg_hash_us.h | 2 ++ menu/menu_setting.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ msg_hash.h | 1 + 5 files changed, 62 insertions(+) diff --git a/configuration.c b/configuration.c index 60911d2f30..cec6bfbe60 100644 --- a/configuration.c +++ b/configuration.c @@ -1582,6 +1582,7 @@ static void config_set_defaults(void) settings->uints.input_analog_dpad_mode[i] = ANALOG_DPAD_NONE; if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_LIBRETRO_DEVICE, &i)) input_config_set_device(i, RETRO_DEVICE_JOYPAD); + settings->uints.input_mouse_index[i] = 0; } video_driver_reset_custom_viewport(); @@ -2339,6 +2340,9 @@ static bool config_load_file(const char *path, bool set_defaults, snprintf(buf, sizeof(buf), "input_player%u_analog_dpad_mode", i + 1); CONFIG_GET_INT_BASE(conf, settings, uints.input_analog_dpad_mode[i], buf); + snprintf(buf, sizeof(buf), "input_player%u_mouse_index", i + 1); + CONFIG_GET_INT_BASE(conf, settings, uints.input_mouse_index[i], buf); + if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_LIBRETRO_DEVICE, &i)) { snprintf(buf, sizeof(buf), "input_libretro_device_p%u", i + 1); @@ -3492,6 +3496,8 @@ bool config_save_file(const char *path) config_set_int(conf, cfg, input_config_get_device(i)); snprintf(cfg, sizeof(cfg), "input_player%u_analog_dpad_mode", i + 1); config_set_int(conf, cfg, settings->uints.input_analog_dpad_mode[i]); + snprintf(cfg, sizeof(cfg), "input_player%u_mouse_index", i + 1); + config_set_int(conf, cfg, settings->uints.input_mouse_index[i]); } /* Boolean settings */ diff --git a/configuration.h b/configuration.h index 8183212f45..0e99efd17b 100644 --- a/configuration.h +++ b/configuration.h @@ -267,6 +267,7 @@ typedef struct settings unsigned input_joypad_map[MAX_USERS]; unsigned input_device[MAX_USERS]; + unsigned input_mouse_index[MAX_USERS]; unsigned input_turbo_period; unsigned input_turbo_duty_cycle; diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 62567e1355..423038c9e7 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -701,6 +701,8 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_DEVICE_INDEX, "Device Index") MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_DEVICE_TYPE, "Device Type") +MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_INDEX, + "Mouse Index") MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_DRIVER, "Input Driver") MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_DUTY_CYCLE, diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 844fdc2e69..1d1768fc1e 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -1299,7 +1299,36 @@ static int setting_action_right_bind_device(void *data, bool wraparound) return 0; } +static int setting_action_left_mouse_index(void *data, bool wraparound) +{ + rarch_setting_t *setting = (rarch_setting_t*)data; + settings_t *settings = config_get_ptr(); + if (!setting) + return -1; + + if (settings->uints.input_mouse_index[setting->index_offset]) + { + --settings->uints.input_mouse_index[setting->index_offset]; + settings->modified = true; + } + + return 0; +} + +static int setting_action_right_mouse_index(void *data, bool wraparound) +{ + rarch_setting_t *setting = (rarch_setting_t*)data; + settings_t *settings = config_get_ptr(); + + if (!setting) + return -1; + + ++settings->uints.input_mouse_index[setting->index_offset]; + settings->modified = true; + + return 0; +} /** ******* ACTION OK CALLBACK FUNCTIONS ******* @@ -1918,6 +1947,7 @@ static bool setting_append_list_input_player_options( static char key_bind_all[MAX_USERS][64]; static char key_bind_all_save_autoconfig[MAX_USERS][64]; static char key_bind_defaults[MAX_USERS][64]; + static char mouse_index[MAX_USERS][64]; static char label[MAX_USERS][64]; static char label_type[MAX_USERS][64]; @@ -1925,6 +1955,7 @@ static bool setting_append_list_input_player_options( static char label_bind_all[MAX_USERS][64]; static char label_bind_all_save_autoconfig[MAX_USERS][64]; static char label_bind_defaults[MAX_USERS][64]; + static char label_mouse_index[MAX_USERS][64]; tmp_string[0] = '\0'; @@ -1946,6 +1977,8 @@ static bool setting_append_list_input_player_options( fill_pathname_join_delim(key_bind_defaults[user], tmp_string, "bind_defaults", '_', sizeof(key_bind_defaults[user])); + fill_pathname_join_delim(mouse_index[user], tmp_string, "mouse_index", '_', + sizeof(mouse_index[user])); snprintf(label[user], sizeof(label[user]), "%s %u %s", msg_hash_to_str(MENU_ENUM_LABEL_VALUE_USER), user + 1, @@ -1965,6 +1998,9 @@ static bool setting_append_list_input_player_options( snprintf(label_bind_all_save_autoconfig[user], sizeof(label_bind_all_save_autoconfig[user]), "%s %u %s", msg_hash_to_str(MENU_ENUM_LABEL_VALUE_USER), user + 1, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_SAVE_AUTOCONFIG)); + snprintf(label_mouse_index[user], sizeof(label_mouse_index[user]), + "%s %u %s", msg_hash_to_str(MENU_ENUM_LABEL_VALUE_USER), user + 1, + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_INDEX)); CONFIG_UINT_ALT( list, list_info, @@ -2058,6 +2094,22 @@ static bool setting_append_list_input_player_options( (*list)[list_info->index - 1].index_offset = user; (*list)[list_info->index - 1].action_ok = &setting_action_ok_bind_all_save_autoconfig; (*list)[list_info->index - 1].action_cancel = NULL; + + CONFIG_UINT_ALT( + list, list_info, + &settings->uints.input_mouse_index[user], + mouse_index[user], + label_mouse_index[user], + 0, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler); + (*list)[list_info->index - 1].index = user + 1; + (*list)[list_info->index - 1].index_offset = user; + (*list)[list_info->index - 1].action_left = &setting_action_left_mouse_index; + (*list)[list_info->index - 1].action_right = &setting_action_right_mouse_index; } for (i = 0; i < RARCH_BIND_LIST_END; i ++) diff --git a/msg_hash.h b/msg_hash.h index 60aa55c89d..6dad693b26 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -574,6 +574,7 @@ enum msg_hash_enums MENU_ENUM_LABEL_VALUE_INPUT_BIND_ALL, MENU_ENUM_LABEL_VALUE_INPUT_BIND_DEFAULT_ALL, MENU_ENUM_LABEL_VALUE_INPUT_SAVE_AUTOCONFIG, + MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_INDEX, MENU_LABEL(INPUT_MAX_USERS), MENU_LABEL(INPUT_USER_BINDS), From 44930716ba5eb208f313c2a9680c40b519a4e88a Mon Sep 17 00:00:00 2001 From: Zoran Vuckovic Date: Thu, 8 Jun 2017 18:49:08 +0200 Subject: [PATCH 2/4] 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; From 39108f97e9145f9e251d2ce5b1717c344dc4390d Mon Sep 17 00:00:00 2001 From: Zoran Vuckovic Date: Thu, 8 Jun 2017 17:35:34 +0200 Subject: [PATCH 3/4] Add player mouse index handling to winraw input driver --- input/drivers/winraw_input.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/input/drivers/winraw_input.c b/input/drivers/winraw_input.c index 0f97d33aee..bc1e0f09bb 100644 --- a/input/drivers/winraw_input.c +++ b/input/drivers/winraw_input.c @@ -15,6 +15,7 @@ #include +#include "../configuration.h" #include "../input_driver.h" #include "../input_keymaps.h" #include "../video_driver.h" @@ -230,8 +231,28 @@ static bool winraw_set_mouse_input(HWND window, bool grab) return true; } -static int16_t winraw_mouse_state(winraw_mouse_t *mouse, bool abs, unsigned id) +static int16_t winraw_mouse_state(winraw_input_t *wr, + unsigned port, bool abs, unsigned id) { + unsigned i; + settings_t *settings = config_get_ptr(); + winraw_mouse_t *mouse = NULL; + + if (port >= MAX_USERS) + return 0; + + for (i = 0; i < g_mouse_cnt; ++i) + { + if (i == settings->uints.input_mouse_index[port]) + { + mouse = &wr->mice[i]; + break; + } + } + + if (!mouse) + return 0; + switch (id) { case RETRO_DEVICE_ID_MOUSE_X: @@ -491,13 +512,9 @@ static int16_t winraw_input_state(void *d, } break; case RETRO_DEVICE_MOUSE: - if (port < g_mouse_cnt) - return winraw_mouse_state(&wr->mice[port], false, id); - break; + return winraw_mouse_state(wr, port, false, id); case RARCH_DEVICE_MOUSE_SCREEN: - if (port < g_mouse_cnt) - return winraw_mouse_state(&wr->mice[port], true, id); - break; + return winraw_mouse_state(wr, port, true, id); case RETRO_DEVICE_JOYPAD: return winraw_joypad_state(wr, joypad_info, binds[port], port, id); case RETRO_DEVICE_ANALOG: From e698e75a51c309ccb200c26b2af901be000606a8 Mon Sep 17 00:00:00 2001 From: Zoran Vuckovic Date: Fri, 9 Jun 2017 21:17:11 +0200 Subject: [PATCH 4/4] Adapt touchpad code for multiple mice support --- input/drivers/udev_input.c | 121 ++++++++++++++----------------------- 1 file changed, 47 insertions(+), 74 deletions(-) diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index fea29bbe50..c2aa0fa52a 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -90,6 +90,13 @@ typedef struct bool wu, wd, whu, whd; } udev_input_mouse_t; +typedef struct +{ + struct input_absinfo info_x; + struct input_absinfo info_y; + udev_input_mouse_t mouse; /* touch-pad will be presented to RA/core as mouse */ +} udev_input_touchpad_t; + struct udev_input_device { int fd; @@ -102,15 +109,7 @@ struct udev_input_device union { udev_input_mouse_t mouse; - - struct - { - float x, y; - float mod_x, mod_y; - struct input_absinfo info_x; - struct input_absinfo info_y; - bool touch; - } touchpad; + udev_input_touchpad_t touchpad; } state; }; @@ -197,12 +196,15 @@ static udev_input_mouse_t *udev_get_mouse(struct udev_input *udev, unsigned port for (i = 0; i < udev->num_devices; ++i) { - if (udev->devices[i]->type != UDEV_INPUT_MOUSE) + if (udev->devices[i]->type == UDEV_INPUT_KEYBOARD) continue; if (mouse_index == settings->uints.input_mouse_index[port]) { - mouse = &udev->devices[i]->state.mouse; + if (udev->devices[i]->type == UDEV_INPUT_MOUSE) + mouse = &udev->devices[i]->state.mouse; + else + mouse = &udev->devices[i]->state.touchpad.mouse; break; } @@ -215,75 +217,43 @@ static udev_input_mouse_t *udev_get_mouse(struct udev_input *udev, unsigned port static void udev_handle_touchpad(void *data, const struct input_event *event, udev_input_device_t *dev) { - unsigned i; - udev_input_t *udev = (udev_input_t*)data; - udev_input_mouse_t *mouse = NULL; - - for (i = 0; i < udev->num_devices; ++i) - { - if (udev->devices[i]->type == UDEV_INPUT_MOUSE) - { - mouse = &udev->devices[i]->state.mouse; - break; - } - } + int16_t pos; + unsigned width = 0; + unsigned height = 0; + udev_input_touchpad_t *touchpad = &dev->state.touchpad; + udev_input_mouse_t *mouse = &dev->state.touchpad.mouse; switch (event->type) { case EV_ABS: + video_driver_get_size(&width, &height); switch (event->code) { case ABS_X: - { - int x = event->value - dev->state.touchpad.info_x.minimum; - int range = dev->state.touchpad.info_x.maximum - - dev->state.touchpad.info_x.minimum; - float x_norm = (float)x / range; - float rel_x = x_norm - dev->state.touchpad.x; - - if (dev->state.touchpad.touch && mouse) - mouse->dlt_x += (int16_t)roundf(dev->state.touchpad.mod_x * rel_x); - - dev->state.touchpad.x = x_norm; - /* Some factor, not sure what's good to do here ... */ - dev->state.touchpad.mod_x = 500.0f; + pos = (float)(event->value - touchpad->info_x.minimum) / + (touchpad->info_x.maximum - touchpad->info_x.minimum) * width; + mouse->dlt_x += pos - mouse->x; + mouse->x = pos; break; - } - case ABS_Y: - { - int y = event->value - dev->state.touchpad.info_y.minimum; - int range = dev->state.touchpad.info_y.maximum - - dev->state.touchpad.info_y.minimum; - float y_norm = (float)y / range; - float rel_y = y_norm - dev->state.touchpad.y; - - if (dev->state.touchpad.touch && mouse) - mouse->dlt_y += (int16_t)roundf(dev->state.touchpad.mod_y * rel_y); - - dev->state.touchpad.y = y_norm; - - /* Some factor, not sure what's good to do here ... */ - dev->state.touchpad.mod_y = 500.0f; - break; - } - - default: - break; + pos = (float)(event->value - touchpad->info_y.minimum) / + (touchpad->info_y.maximum - touchpad->info_y.minimum) * height; + mouse->dlt_y += pos - mouse->y; + mouse->y = pos; } break; case EV_KEY: switch (event->code) { - case BTN_TOUCH: - dev->state.touchpad.touch = event->value; - dev->state.touchpad.mod_x = 0.0f; /* First ABS event is not a relative one. */ - dev->state.touchpad.mod_y = 0.0f; + case BTN_LEFT: + mouse->l = event->value; break; - - default: + case BTN_MIDDLE: + mouse->m = event->value; break; + case BTN_RIGHT: + mouse->r = event->value; } } } @@ -497,17 +467,20 @@ static void udev_input_poll(void *data) for (i = 0; i < udev->num_devices; ++i) { if (udev->devices[i]->type == UDEV_INPUT_MOUSE) - { - mouse = &udev->devices[i]->state.mouse; - mouse->x = x; - mouse->y = y; - mouse->dlt_x = 0; - mouse->dlt_y = 0; - mouse->wu = false; - mouse->wd = false; - mouse->whu = false; - mouse->whd = false; - } + mouse = &udev->devices[i]->state.mouse; + else if (udev->devices[i]->type == UDEV_INPUT_TOUCHPAD) + mouse = &udev->devices[i]->state.touchpad.mouse; + else + continue; + + mouse->x = x; + mouse->y = y; + mouse->dlt_x = 0; + mouse->dlt_y = 0; + mouse->wu = false; + mouse->wd = false; + mouse->whu = false; + mouse->whd = false; } while (udev->monitor && udev_hotplug_available(udev->monitor))