RetroArch/input/drivers/udev_input.c

732 lines
18 KiB
C
Raw Normal View History

2013-12-07 14:13:40 +01:00
/* RetroArch - A frontend for libretro.
2015-01-07 17:46:50 +01:00
* Copyright (C) 2010-2015 - Hans-Kristian Arntzen
2013-12-07 14:13:40 +01:00
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <string.h>
2015-06-03 17:11:32 +02:00
2015-11-14 22:03:37 +01:00
#include <fcntl.h>
#include <unistd.h>
2013-12-07 14:13:40 +01:00
#include <limits.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
2015-11-14 22:03:37 +01:00
2013-12-07 14:13:40 +01:00
#include <libudev.h>
#include <linux/types.h>
#include <linux/input.h>
#include <linux/kd.h>
2013-12-07 14:13:40 +01:00
2015-06-03 17:11:32 +02:00
#include <file/file_path.h>
#include "../drivers_keyboard/keyboard_event_udev.h"
2015-11-17 06:46:32 +01:00
#include "../common/linux_common.h"
2015-11-30 18:05:10 +01:00
#include "../common/epoll_common.h"
2015-11-30 16:39:22 +01:00
#include "../common/udev_common.h"
2015-11-14 09:01:41 +01:00
#include "../input_config.h"
#include "../input_joypad_driver.h"
2015-06-03 17:11:32 +02:00
#include "../input_keymaps.h"
#include "../../general.h"
2015-11-23 12:03:38 +01:00
#include "../../verbosity.h"
2015-06-03 17:11:32 +02:00
#ifdef HAVE_CONFIG_H
2015-01-12 06:16:52 +01:00
#include "../../config.h"
#endif
typedef struct udev_input udev_input_t;
2013-12-07 22:09:08 +01:00
typedef void (*device_handle_cb)(void *data,
const struct input_event *event, udev_input_device_t *dev);
struct udev_input_device
{
int fd;
dev_t dev;
2013-12-07 22:09:08 +01:00
device_handle_cb handle_cb;
char devnode[PATH_MAX_LENGTH];
2013-12-07 22:09:08 +01:00
union
{
/*
* keyboard
* mouse
*/
2013-12-07 22:09:08 +01:00
struct
{
float x, y;
2013-12-07 22:16:19 +01:00
float mod_x, mod_y;
2013-12-07 22:09:08 +01:00
struct input_absinfo info_x;
struct input_absinfo info_y;
bool touch;
} touchpad;
} state;
};
struct udev_input
2013-12-07 14:13:40 +01:00
{
bool blocked;
const input_device_driver_t *joypad;
2013-12-07 14:13:40 +01:00
udev_input_device_t **devices;
unsigned num_devices;
2013-12-07 14:13:40 +01:00
int16_t mouse_x;
int16_t mouse_y;
bool mouse_l, mouse_r, mouse_m, mouse_wu, mouse_wd, mouse_whu, mouse_whd;
};
2013-12-07 14:13:40 +01:00
#ifdef HAVE_XKBCOMMON
int init_xkb(void);
#endif
2013-12-07 22:09:08 +01:00
static void udev_handle_touchpad(void *data,
const struct input_event *event, udev_input_device_t *dev)
2013-12-07 22:09:08 +01:00
{
udev_input_t *udev = (udev_input_t*)data;
2013-12-07 22:09:08 +01:00
switch (event->type)
{
case EV_ABS:
switch (event->code)
{
case ABS_X:
{
2015-06-03 17:11:32 +02:00
int x = event->value - dev->state.touchpad.info_x.minimum;
int range = dev->state.touchpad.info_x.maximum -
2014-10-04 15:14:39 +02:00
dev->state.touchpad.info_x.minimum;
2013-12-07 22:09:08 +01:00
float x_norm = (float)x / range;
2015-06-03 17:11:32 +02:00
float rel_x = x_norm - dev->state.touchpad.x;
2013-12-07 22:09:08 +01:00
2013-12-07 22:16:19 +01:00
if (dev->state.touchpad.touch)
2014-10-04 15:14:39 +02:00
udev->mouse_x += (int16_t)
roundf(dev->state.touchpad.mod_x * rel_x);
2013-12-07 22:09:08 +01:00
2013-12-07 22:16:19 +01:00
dev->state.touchpad.x = x_norm;
2014-10-04 15:14:39 +02:00
/* Some factor, not sure what's good to do here ... */
2013-12-07 22:16:19 +01:00
dev->state.touchpad.mod_x = 500.0f;
2013-12-07 22:09:08 +01:00
break;
}
case ABS_Y:
{
2015-06-03 17:11:32 +02:00
int y = event->value - dev->state.touchpad.info_y.minimum;
int range = dev->state.touchpad.info_y.maximum -
2014-10-04 15:14:39 +02:00
dev->state.touchpad.info_y.minimum;
2013-12-07 22:09:08 +01:00
float y_norm = (float)y / range;
2015-06-03 17:11:32 +02:00
float rel_y = y_norm - dev->state.touchpad.y;
2013-12-07 22:09:08 +01:00
2013-12-07 22:16:19 +01:00
if (dev->state.touchpad.touch)
udev->mouse_y += (int16_t)roundf(dev->state.touchpad.mod_y * rel_y);
2013-12-07 22:09:08 +01:00
2013-12-07 22:16:19 +01:00
dev->state.touchpad.y = y_norm;
2014-10-04 15:14:39 +02:00
/* Some factor, not sure what's good to do here ... */
2013-12-07 22:16:19 +01:00
dev->state.touchpad.mod_y = 500.0f;
2013-12-07 22:09:08 +01:00
break;
}
default:
break;
}
break;
case EV_KEY:
switch (event->code)
2013-12-07 14:13:40 +01:00
{
2013-12-07 22:09:08 +01:00
case BTN_TOUCH:
dev->state.touchpad.touch = event->value;
2014-10-04 15:14:39 +02:00
dev->state.touchpad.mod_x = 0.0f; /* First ABS event is not a relative one. */
2013-12-07 22:16:19 +01:00
dev->state.touchpad.mod_y = 0.0f;
break;
default:
break;
2013-12-07 14:13:40 +01:00
}
}
}
2013-12-07 14:13:40 +01:00
static void udev_handle_mouse(void *data,
const struct input_event *event, udev_input_device_t *dev)
{
udev_input_t *udev = (udev_input_t*)data;
2013-12-07 22:09:08 +01:00
switch (event->type)
2013-12-07 14:13:40 +01:00
{
2013-12-07 22:09:08 +01:00
case EV_KEY:
/* TODO: mouse wheel up/down doesn't work */
2013-12-07 22:09:08 +01:00
switch (event->code)
2013-12-07 14:13:40 +01:00
{
2013-12-07 22:09:08 +01:00
case BTN_LEFT:
udev->mouse_l = event->value;
break;
2013-12-07 22:09:08 +01:00
case BTN_RIGHT:
udev->mouse_r = event->value;
break;
2013-12-07 22:09:08 +01:00
case BTN_MIDDLE:
udev->mouse_m = event->value;
break;
2013-12-07 22:09:08 +01:00
default:
break;
}
break;
2013-12-07 22:09:08 +01:00
case EV_REL:
switch (event->code)
{
case REL_X:
udev->mouse_x += event->value;
break;
2013-12-07 22:09:08 +01:00
case REL_Y:
udev->mouse_y += event->value;
break;
2015-03-09 16:23:09 +01:00
case REL_WHEEL:
if (event->value == 1)
udev->mouse_wu = 1;
else if (event->value == -1)
udev->mouse_wd = 1;
break;
case REL_HWHEEL:
if (event->value == 1)
udev->mouse_whu = 1;
else if (event->value == -1)
udev->mouse_whd = 1;
break;
default:
break;
2013-12-07 14:13:40 +01:00
}
2013-12-07 22:09:08 +01:00
break;
default:
break;
2013-12-07 14:13:40 +01:00
}
}
2014-10-04 15:14:39 +02:00
static bool add_device(udev_input_t *udev,
const char *devnode, device_handle_cb cb)
{
2014-10-04 15:14:39 +02:00
int fd;
udev_input_device_t **tmp;
udev_input_device_t *device = NULL;
2015-06-03 18:12:06 +02:00
struct stat st = {0};
2014-10-04 15:14:39 +02:00
if (stat(devnode, &st) < 0)
return false;
2014-10-04 15:14:39 +02:00
fd = open(devnode, O_RDONLY | O_NONBLOCK);
if (fd < 0)
return false;
device = (udev_input_device_t*)calloc(1, sizeof(*device));
if (!device)
2015-07-12 02:44:53 +02:00
goto error;
2015-06-03 17:11:32 +02:00
device->fd = fd;
device->dev = st.st_dev;
2013-12-07 22:09:08 +01:00
device->handle_cb = cb;
strlcpy(device->devnode, devnode, sizeof(device->devnode));
2015-06-26 17:03:05 +02:00
/* Touchpads report in absolute coords. */
2013-12-07 22:09:08 +01:00
if (cb == udev_handle_touchpad &&
(ioctl(fd, EVIOCGABS(ABS_X), &device->state.touchpad.info_x) < 0 ||
ioctl(fd, EVIOCGABS(ABS_Y), &device->state.touchpad.info_y) < 0))
2015-07-12 02:44:53 +02:00
goto error;
2013-12-07 22:09:08 +01:00
tmp = ( udev_input_device_t**)realloc(udev->devices,
(udev->num_devices + 1) * sizeof(*udev->devices));
if (!tmp)
2015-07-12 02:44:53 +02:00
goto error;
tmp[udev->num_devices++] = device;
2015-07-12 02:44:53 +02:00
udev->devices = tmp;
2015-11-30 18:14:07 +01:00
epoll_add(fd, device);
return true;
2015-07-12 02:44:53 +02:00
error:
close(fd);
if (device)
free(device);
return false;
}
2015-02-20 20:56:22 -03:00
static void udev_input_remove_device(udev_input_t *udev, const char *devnode)
{
unsigned i;
for (i = 0; i < udev->num_devices; i++)
{
2015-06-03 18:12:06 +02:00
if (strcmp(devnode, udev->devices[i]->devnode) != 0)
continue;
close(udev->devices[i]->fd);
free(udev->devices[i]);
memmove(udev->devices + i, udev->devices + i + 1,
(udev->num_devices - (i + 1)) * sizeof(*udev->devices));
udev->num_devices--;
}
}
2015-02-20 20:56:22 -03:00
static void udev_input_handle_hotplug(udev_input_t *udev)
{
bool is_keyboard, is_mouse, is_touchpad;
device_handle_cb cb = NULL;
const char *devtype = NULL;
const char *val_keyboard = NULL;
const char *val_mouse = NULL;
const char *val_touchpad = NULL;
const char *action = NULL;
const char *devnode = NULL;
2015-11-30 16:47:43 +01:00
struct udev_device *dev = udev_mon_receive_device();
if (!dev)
return;
2015-06-03 17:11:32 +02:00
val_keyboard = udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD");
val_mouse = udev_device_get_property_value(dev, "ID_INPUT_MOUSE");
val_touchpad = udev_device_get_property_value(dev, "ID_INPUT_TOUCHPAD");
action = udev_device_get_action(dev);
devnode = udev_device_get_devnode(dev);
2015-06-03 17:11:32 +02:00
is_keyboard = val_keyboard && !strcmp(val_keyboard, "1") && devnode;
is_mouse = val_mouse && !strcmp(val_mouse, "1") && devnode;
is_touchpad = val_touchpad && !strcmp(val_touchpad, "1") && devnode;
2013-12-07 22:09:08 +01:00
2013-12-10 19:42:50 +01:00
if (!is_keyboard && !is_mouse && !is_touchpad)
goto end;
2013-12-07 22:09:08 +01:00
if (is_keyboard)
{
cb = udev_handle_keyboard;
devtype = "keyboard";
}
else if (is_touchpad)
{
cb = udev_handle_touchpad;
devtype = "touchpad";
}
else if (is_mouse)
{
cb = udev_handle_mouse;
devtype = "mouse";
}
if (!strcmp(action, "add"))
{
2013-12-07 22:09:08 +01:00
RARCH_LOG("[udev]: Hotplug add %s: %s.\n", devtype, devnode);
add_device(udev, devnode, cb);
}
else if (!strcmp(action, "remove"))
{
2013-12-07 22:09:08 +01:00
RARCH_LOG("[udev]: Hotplug remove %s: %s.\n", devtype, devnode);
2015-02-20 20:56:22 -03:00
udev_input_remove_device(udev, devnode);
}
end:
udev_device_unref(dev);
}
static void udev_input_poll(void *data)
{
2014-10-04 15:14:39 +02:00
int i, ret;
struct epoll_event events[32];
udev_input_t *udev = (udev_input_t*)data;
2015-06-03 17:11:32 +02:00
udev->mouse_x = udev->mouse_y = 0;
udev->mouse_wu = udev->mouse_wd = 0;
udev->mouse_whu = udev->mouse_whd = 0;
2015-11-30 16:42:52 +01:00
while (udev_mon_hotplug_available())
2015-02-20 20:56:22 -03:00
udev_input_handle_hotplug(udev);
2015-11-30 18:08:00 +01:00
ret = epoll_waiting(events, ARRAY_SIZE(events), 0);
for (i = 0; i < ret; i++)
{
if (events[i].events & EPOLLIN)
{
2014-10-04 15:14:39 +02:00
int j, len;
struct input_event input_events[32];
udev_input_device_t *device = (udev_input_device_t*)events[i].data.ptr;
2013-12-07 22:09:08 +01:00
while ((len = read(device->fd, input_events, sizeof(input_events))) > 0)
2013-12-07 22:09:08 +01:00
{
len /= sizeof(*input_events);
2013-12-07 22:09:08 +01:00
for (j = 0; j < len; j++)
device->handle_cb(udev, &input_events[j], device);
2013-12-07 22:09:08 +01:00
}
}
}
2013-12-07 14:13:40 +01:00
if (udev->joypad)
udev->joypad->poll();
2013-12-07 14:13:40 +01:00
}
static int16_t udev_mouse_state(udev_input_t *udev, unsigned id)
{
switch (id)
{
case RETRO_DEVICE_ID_MOUSE_X:
return udev->mouse_x;
case RETRO_DEVICE_ID_MOUSE_Y:
return udev->mouse_y;
case RETRO_DEVICE_ID_MOUSE_LEFT:
return udev->mouse_l;
case RETRO_DEVICE_ID_MOUSE_RIGHT:
return udev->mouse_r;
2014-04-25 23:44:53 +02:00
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
return udev->mouse_m;
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
return udev->mouse_wu;
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
return udev->mouse_wd;
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP:
return udev->mouse_whu;
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN:
return udev->mouse_whd;
2013-12-07 14:13:40 +01:00
}
2014-10-04 15:14:39 +02:00
return 0;
2013-12-07 14:13:40 +01:00
}
static int16_t udev_lightgun_state(udev_input_t *udev, unsigned id)
{
switch (id)
{
case RETRO_DEVICE_ID_LIGHTGUN_X:
return udev->mouse_x;
case RETRO_DEVICE_ID_LIGHTGUN_Y:
return udev->mouse_y;
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
return udev->mouse_l;
case RETRO_DEVICE_ID_LIGHTGUN_CURSOR:
return udev->mouse_m;
case RETRO_DEVICE_ID_LIGHTGUN_TURBO:
return udev->mouse_r;
case RETRO_DEVICE_ID_LIGHTGUN_START:
return udev->mouse_m && udev->mouse_r;
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
return udev->mouse_m && udev->mouse_l;
}
2014-10-04 15:14:39 +02:00
return 0;
2013-12-07 14:13:40 +01:00
}
static int16_t udev_analog_pressed(const struct retro_keybind *binds, unsigned idx, unsigned id)
2013-12-07 14:13:40 +01:00
{
unsigned id_minus = 0;
unsigned id_plus = 0;
int16_t pressed_minus = 0, pressed_plus = 0;
2014-10-20 20:31:00 +02:00
input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus);
2013-12-07 14:13:40 +01:00
if (udev_input_is_pressed(binds, id_minus))
pressed_minus = -0x7fff;
if (udev_input_is_pressed(binds, id_plus))
pressed_plus = 0x7fff;
2013-12-07 14:13:40 +01:00
return pressed_plus + pressed_minus;
}
static int16_t udev_pointer_state(udev_input_t *udev,
unsigned idx, unsigned id, bool screen)
{
bool valid, inside;
int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0;
if (idx != 0)
return 0;
valid = input_translate_coord_viewport(udev->mouse_x, udev->mouse_y,
&res_x, &res_y, &res_screen_x, &res_screen_y);
if (!valid)
return 0;
if (screen)
{
res_x = res_screen_x;
res_y = res_screen_y;
}
inside = (res_x >= -0x7fff) && (res_y >= -0x7fff);
if (!inside)
return 0;
switch (id)
{
case RETRO_DEVICE_ID_POINTER_X:
return res_x;
case RETRO_DEVICE_ID_POINTER_Y:
return res_y;
case RETRO_DEVICE_ID_POINTER_PRESSED:
return udev->mouse_l;
}
return 0;
}
2013-12-07 14:13:40 +01:00
static int16_t udev_input_state(void *data, const struct retro_keybind **binds,
2014-10-20 20:31:00 +02:00
unsigned port, unsigned device, unsigned idx, unsigned id)
2013-12-07 14:13:40 +01:00
{
int16_t ret;
udev_input_t *udev = (udev_input_t*)data;
2013-12-07 14:13:40 +01:00
switch (device)
{
case RETRO_DEVICE_JOYPAD:
return udev_input_is_pressed(binds[port], id) ||
2013-12-07 14:13:40 +01:00
input_joypad_pressed(udev->joypad, port, binds[port], id);
case RETRO_DEVICE_ANALOG:
ret = udev_analog_pressed(binds[port], idx, id);
2013-12-07 14:13:40 +01:00
if (!ret)
2014-10-20 20:31:00 +02:00
ret = input_joypad_analog(udev->joypad, port, idx, id, binds[port]);
2013-12-07 14:13:40 +01:00
return ret;
case RETRO_DEVICE_KEYBOARD:
return udev_input_state_kb(data, binds, port, device, idx, id);
2013-12-07 14:13:40 +01:00
case RETRO_DEVICE_MOUSE:
return udev_mouse_state(udev, id);
case RETRO_DEVICE_POINTER:
case RARCH_DEVICE_POINTER_SCREEN:
return udev_pointer_state(udev, idx, id,
device == RARCH_DEVICE_POINTER_SCREEN);
2013-12-07 14:13:40 +01:00
case RETRO_DEVICE_LIGHTGUN:
return udev_lightgun_state(udev, id);
}
2015-01-10 01:34:16 +01:00
return 0;
2013-12-07 14:13:40 +01:00
}
2015-11-07 20:59:12 +01:00
static bool udev_input_key_pressed(void *data, int key)
2013-12-07 14:13:40 +01:00
{
udev_input_t *udev = (udev_input_t*)data;
settings_t *settings = config_get_ptr();
2015-03-20 22:32:09 +01:00
if (udev_input_is_pressed(settings->input.binds[0], key))
2015-10-23 08:22:59 +02:00
return true;
if (input_joypad_pressed(udev->joypad, 0, settings->input.binds[0], key))
return true;
2015-10-23 08:22:59 +02:00
return false;
2013-12-07 14:13:40 +01:00
}
2015-11-07 20:59:12 +01:00
static bool udev_input_meta_key_pressed(void *data, int key)
2015-07-17 03:31:51 +02:00
{
return false;
}
2013-12-07 14:13:40 +01:00
static void udev_input_free(void *data)
{
unsigned i;
2013-12-07 14:13:40 +01:00
udev_input_t *udev = (udev_input_t*)data;
2014-10-04 15:14:39 +02:00
if (!data || !udev)
return;
2013-12-07 14:13:40 +01:00
if (udev->joypad)
udev->joypad->destroy();
2015-11-30 18:05:10 +01:00
epoll_free(false);
for (i = 0; i < udev->num_devices; i++)
{
close(udev->devices[i]->fd);
free(udev->devices[i]);
}
free(udev->devices);
2013-12-07 14:13:40 +01:00
2015-11-30 16:39:22 +01:00
udev_mon_free(false);
udev_input_kb_free();
free(udev);
}
2013-12-07 22:09:08 +01:00
static bool open_devices(udev_input_t *udev, const char *type, device_handle_cb cb)
2013-12-07 14:13:40 +01:00
{
2015-06-03 17:06:22 +02:00
struct udev_list_entry *devs = NULL;
struct udev_list_entry *item = NULL;
2015-11-30 16:52:29 +01:00
struct udev_enumerate *enumerate = udev_mon_enumerate();
2013-12-07 14:13:40 +01:00
if (!enumerate)
return false;
2013-12-07 14:13:40 +01:00
udev_enumerate_add_match_property(enumerate, type, "1");
udev_enumerate_scan_devices(enumerate);
devs = udev_enumerate_get_list_entry(enumerate);
2013-12-07 14:13:40 +01:00
for (item = devs; item; item = udev_list_entry_get_next(item))
{
2015-11-30 16:52:29 +01:00
const char *name = udev_list_entry_get_name(item);
struct udev_device *dev = udev_mon_device_new(name);
const char *devnode = udev_device_get_devnode(dev);
2013-12-07 14:13:40 +01:00
if (devnode)
2013-12-07 14:13:40 +01:00
{
int fd = open(devnode, O_RDONLY | O_NONBLOCK);
2015-09-29 18:08:33 +02:00
(void)fd;
RARCH_LOG("[udev] Adding device %s as type %s.\n", devnode, type);
if (!add_device(udev, devnode, cb))
RARCH_ERR("[udev] Failed to open device: %s (%s).\n", devnode, strerror(errno));
2013-12-07 14:13:40 +01:00
}
udev_device_unref(dev);
2013-12-07 14:13:40 +01:00
}
udev_enumerate_unref(enumerate);
return true;
2013-12-07 14:13:40 +01:00
}
static void *udev_input_init(void)
{
2015-03-20 22:32:09 +01:00
settings_t *settings = config_get_ptr();
2013-12-07 14:13:40 +01:00
udev_input_t *udev = (udev_input_t*)calloc(1, sizeof(*udev));
2013-12-07 14:13:40 +01:00
if (!udev)
return NULL;
if (!udev_mon_new(false))
goto error;
#ifdef HAVE_XKBCOMMON
if (init_xkb() == -1)
2014-10-27 19:00:03 +01:00
goto error;
#endif
2015-11-30 18:05:10 +01:00
if (!epoll_new(false))
{
RARCH_ERR("Failed to create epoll FD.\n");
goto error;
}
2013-12-07 14:13:40 +01:00
2013-12-07 22:09:08 +01:00
if (!open_devices(udev, "ID_INPUT_KEYBOARD", udev_handle_keyboard))
{
RARCH_ERR("Failed to open keyboard.\n");
goto error;
}
2013-12-07 22:09:08 +01:00
if (!open_devices(udev, "ID_INPUT_MOUSE", udev_handle_mouse))
{
RARCH_ERR("Failed to open mouse.\n");
goto error;
}
2013-12-07 14:13:40 +01:00
2013-12-07 22:09:08 +01:00
if (!open_devices(udev, "ID_INPUT_TOUCHPAD", udev_handle_touchpad))
{
RARCH_ERR("Failed to open touchpads.\n");
goto error;
}
2014-10-27 19:00:03 +01:00
/* If using KMS and we forgot this,
* we could lock ourselves out completely. */
2013-12-07 22:09:08 +01:00
if (!udev->num_devices)
2014-01-24 10:19:42 +01:00
RARCH_WARN("[udev]: Couldn't open any keyboard, mouse or touchpad. Are permissions set correctly for /dev/input/event*?\n");
2013-12-07 22:09:08 +01:00
udev->joypad = input_joypad_init_driver(settings->input.joypad_driver, udev);
input_keymaps_init_keyboard_lut(rarch_key_map_linux);
2015-11-14 22:03:37 +01:00
linux_terminal_disable_input();
2013-12-07 14:13:40 +01:00
return udev;
error:
udev_input_free(udev);
return NULL;
2013-12-07 14:13:40 +01:00
}
static uint64_t udev_input_get_capabilities(void *data)
{
(void)data;
return
2014-10-04 15:14:39 +02:00
(1 << RETRO_DEVICE_JOYPAD) |
(1 << RETRO_DEVICE_ANALOG) |
2013-12-07 14:13:40 +01:00
(1 << RETRO_DEVICE_KEYBOARD) |
2014-10-04 15:14:39 +02:00
(1 << RETRO_DEVICE_MOUSE) |
2013-12-07 14:13:40 +01:00
(1 << RETRO_DEVICE_LIGHTGUN);
}
static void udev_input_grab_mouse(void *data, bool state)
{
2014-10-04 15:14:39 +02:00
/* Dummy for now. Might be useful in the future. */
(void)data;
(void)state;
}
2013-12-07 14:13:40 +01:00
static bool udev_input_set_rumble(void *data, unsigned port, enum retro_rumble_effect effect, uint16_t strength)
{
udev_input_t *udev = (udev_input_t*)data;
2014-10-04 15:14:39 +02:00
if (udev && udev->joypad)
return input_joypad_set_rumble(udev->joypad, port, effect, strength);
return false;
2013-12-07 14:13:40 +01:00
}
static const input_device_driver_t *udev_input_get_joypad_driver(void *data)
2013-12-07 14:13:40 +01:00
{
udev_input_t *udev = (udev_input_t*)data;
2015-01-10 01:34:16 +01:00
if (!udev)
return NULL;
return udev->joypad;
2013-12-07 14:13:40 +01:00
}
static bool udev_input_keyboard_mapping_is_blocked(void *data)
{
udev_input_t *udev = (udev_input_t*)data;
if (!udev)
return false;
return udev->blocked;
}
static void udev_input_keyboard_mapping_set_block(void *data, bool value)
{
udev_input_t *udev = (udev_input_t*)data;
if (!udev)
return;
udev->blocked = value;
}
2014-09-11 07:06:20 +02:00
input_driver_t input_udev = {
2013-12-07 14:13:40 +01:00
udev_input_init,
udev_input_poll,
udev_input_state,
udev_input_key_pressed,
2015-07-17 03:31:51 +02:00
udev_input_meta_key_pressed,
2013-12-07 14:13:40 +01:00
udev_input_free,
NULL,
NULL,
udev_input_get_capabilities,
"udev",
udev_input_grab_mouse,
2015-11-14 09:01:41 +01:00
linux_terminal_grab_stdin,
2013-12-07 14:13:40 +01:00
udev_input_set_rumble,
udev_input_get_joypad_driver,
2015-11-16 02:42:10 +01:00
NULL,
udev_input_keyboard_mapping_is_blocked,
udev_input_keyboard_mapping_set_block,
2013-12-07 14:13:40 +01:00
};