Merge pull request #5045 from casdevel/mice

Add player mouse device selection
This commit is contained in:
Twinaphex 2017-06-10 04:13:16 +02:00 committed by GitHub
commit 6d85e1f0a6
7 changed files with 155 additions and 114 deletions

View File

@ -1585,6 +1585,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();
@ -2342,6 +2343,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);
@ -3496,6 +3500,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 */

View File

@ -268,6 +268,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;

View File

@ -54,6 +54,7 @@
#include "../../gfx/video_driver.h"
#include "../common/linux_common.h"
#include "../common/epoll_common.h"
#include "../configuration.h"
#include "../../verbosity.h"
@ -89,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;
@ -101,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;
};
@ -184,78 +184,76 @@ static void udev_input_kb_free(void)
#endif
}
static void udev_handle_touchpad(void *data,
const struct input_event *event, udev_input_device_t *dev)
static udev_input_mouse_t *udev_get_mouse(struct udev_input *udev, unsigned port)
{
unsigned i;
udev_input_t *udev = (udev_input_t*)data;
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)
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;
}
++mouse_index;
}
return mouse;
}
static void udev_handle_touchpad(void *data,
const struct input_event *event, udev_input_device_t *dev)
{
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;
}
}
}
@ -471,17 +469,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;
}
fds.fd = udev_monitor_get_fd(udev->monitor);
@ -519,20 +520,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;
@ -565,20 +553,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;
@ -630,13 +605,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;
@ -645,18 +619,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;

View File

@ -15,6 +15,7 @@
#include <Windows.h>
#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:

View File

@ -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,

View File

@ -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 *******
@ -1921,6 +1950,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];
@ -1928,6 +1958,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';
@ -1949,6 +1980,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,
@ -1968,6 +2001,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,
@ -2061,6 +2097,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 ++)

View File

@ -575,6 +575,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),