Compare commits

..

3 Commits

Author SHA1 Message Date
Peter Hutterer
efb5cacb25 xf86-input-libinput 0.5.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-01-16 14:39:29 +10:00
Peter Hutterer
2348a6812a Fix for new libinput APIs
Scroll events carry multiple axes.

Left-handed config was renamed to drop the "button" bit

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-01-15 13:12:36 +10:00
Peter Hutterer
0c4eaf5480 Support server-side fds
libinput's device handling and server-side fd handling are a bit of a
mismatch, so this is hackier than one would hope for.

The server sets pInfo->fd and the options "fd" and "device".
The server requires pInfo->fd to be the one triggering select(2) to call the
correct pInfo->read_input. We can't pass an fd to use into libinput, all we
have is the open_restricted callback. That callback gives us the context, but
not the pInfo with the fd we want.

The solution:
1) In PreInit, store the patch + fd combination in a driver-wide list. Search
that list for an fd in open_restricted, return the pre-openend fd.

2) Overwrite all devices' pInfo->fd with the libinput epollfd. In this driver
we don't care about which device read_input is called on, we get the correct
pInfo to post events from through the struct libinput_device of the libinput
events.

3) When a device is closed, swap the real fd back in so systemd-logind closes the
right fd.

This saves us worrying about keeping the right refcount on who currently has
the fd set to the libinput fd. We just set it for all devices, let the server
figure out which device to call (the first in inputInfo.devices) and we only
need to remember to swap it back during DEVICE_OFF.

If the server calls close on a pInfo->fd without telling the driver, that's a
bug anyway.

This patch also drops the pInfo->fd = -1 calls, they've been unnecessary since
at least 1.11, possibly earlier.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-12-08 08:36:16 +10:00
2 changed files with 163 additions and 28 deletions

View File

@@ -23,7 +23,7 @@
# Initialize Autoconf
AC_PREREQ([2.60])
AC_INIT([xf86-input-libinput],
[0.4.0],
[0.5.0],
[https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],
[xf86-input-libinput])
AC_CONFIG_SRCDIR([Makefile.am])
@@ -45,7 +45,7 @@ XORG_DEFAULT_OPTIONS
# Obtain compiler/linker options from server and required extensions
PKG_CHECK_MODULES(XORG, [xorg-server >= 1.10] xproto [inputproto >= 2.2])
PKG_CHECK_MODULES(LIBINPUT, [libinput >= 0.7.0])
PKG_CHECK_MODULES(LIBINPUT, [libinput >= 0.8.0])
# Define a configure option for an alternate input module directory
AC_ARG_WITH(xorg-module-dir,

View File

@@ -31,6 +31,7 @@
#include <time.h>
#include <unistd.h>
#include <xorg-server.h>
#include <list.h>
#include <exevents.h>
#include <xkbsrv.h>
#include <xf86Xinput.h>
@@ -40,6 +41,10 @@
#include <X11/Xatom.h>
#ifndef XI86_SERVER_FD
#define XI86_SERVER_FD 0x20
#endif
#define TOUCHPAD_NUM_AXES 4 /* x, y, hscroll, vscroll */
#define TOUCH_MAX_SLOTS 15
#define XORG_KEYCODE_OFFSET 8
@@ -54,13 +59,14 @@
/*
libinput scales wheel events by DEFAULT_AXIS_STEP_DISTANCE, which is
currently 10.
currently 15.
*/
#define DEFAULT_LIBINPUT_AXIS_STEP_DISTANCE 10
#define DEFAULT_LIBINPUT_AXIS_STEP_DISTANCE 15
struct xf86libinput_driver {
struct libinput *libinput;
int device_enabled_count;
struct xorg_list server_fds;
};
static struct xf86libinput_driver driver_context;
@@ -95,6 +101,80 @@ struct xf86libinput {
} options;
};
/*
libinput provides a userdata for the context, but not per path device. so
the open_restricted call has the libinput context, but no reference to
the pInfo->fd that we actually need to return.
To avoid this, we store each path/fd combination during pre_init in the
context, then return that during open_restricted. If a device is added
twice with two different fds this may give us the wrong fd but why are
you doing that anyway.
*/
struct serverfd {
struct xorg_list node;
int fd;
char *path;
};
static inline int
use_server_fd(const InputInfoPtr pInfo) {
return pInfo->fd > -1 && (pInfo->flags & XI86_SERVER_FD);
}
static inline void
fd_push(struct xf86libinput_driver *context,
int fd,
const char *path)
{
struct serverfd *sfd = xnfcalloc(1, sizeof(*sfd));
sfd->fd = fd;
sfd->path = xnfstrdup(path);
xorg_list_add(&sfd->node, &context->server_fds);
}
static inline int
fd_get(struct xf86libinput_driver *context,
const char *path)
{
struct serverfd *sfd;
xorg_list_for_each_entry(sfd, &context->server_fds, node) {
if (strcmp(path, sfd->path) == 0)
return sfd->fd;
}
return -1;
}
static inline void
fd_pop(struct xf86libinput_driver *context, int fd)
{
struct serverfd *sfd;
xorg_list_for_each_entry(sfd, &context->server_fds, node) {
if (fd != sfd->fd)
continue;
xorg_list_del(&sfd->node);
free(sfd->path);
free(sfd);
break;
}
}
static inline int
fd_find(struct xf86libinput_driver *context, int fd)
{
struct serverfd *sfd;
xorg_list_for_each_entry(sfd, &context->server_fds, node) {
if (fd == sfd->fd)
return fd;
}
return -1;
}
static inline unsigned int
btn_linux2xorg(unsigned int b)
{
@@ -183,8 +263,8 @@ LibinputApplyConfig(DeviceIntPtr dev)
driver_data->options.matrix[6], driver_data->options.matrix[7],
driver_data->options.matrix[8]);
if (libinput_device_config_buttons_set_left_handed(device,
driver_data->options.left_handed) != LIBINPUT_CONFIG_STATUS_SUCCESS)
if (libinput_device_config_left_handed_set(device,
driver_data->options.left_handed) != LIBINPUT_CONFIG_STATUS_SUCCESS)
xf86IDrvMsg(pInfo, X_ERROR,
"Failed to set LeftHanded to %d\n",
driver_data->options.left_handed);
@@ -222,13 +302,24 @@ xf86libinput_on(DeviceIntPtr dev)
struct libinput *libinput = driver_context.libinput;
struct libinput_device *device = driver_data->device;
if (use_server_fd(pInfo)) {
char *path = xf86SetStrOption(pInfo->options, "Device", NULL);
fd_push(&driver_context, pInfo->fd, path);
free(path);
}
device = libinput_path_add_device(libinput, driver_data->path);
if (!device)
return !Success;
libinput_device_ref(device);
libinput_device_set_user_data(device, pInfo);
driver_data->device = device;
/* if we use server fds, overwrite the fd with the one from
libinput nonetheless, otherwise the server won't call ReadInput
for our device. This must be swapped back to the real fd in
DEVICE_OFF so systemd-logind closes the right fd */
pInfo->fd = libinput_get_fd(libinput);
if (driver_context.device_enabled_count == 0) {
@@ -252,7 +343,13 @@ xf86libinput_off(DeviceIntPtr dev)
RemoveEnabledDevice(pInfo->fd);
}
pInfo->fd = -1;
if (use_server_fd(pInfo)) {
fd_pop(&driver_context, pInfo->fd);
pInfo->fd = xf86SetIntOption(pInfo->options, "fd", -1);
} else {
pInfo->fd = -1;
}
dev->public.on = FALSE;
libinput_device_set_user_data(driver_data->device, NULL);
@@ -621,19 +718,38 @@ xf86libinput_handle_axis(InputInfoPtr pInfo, struct libinput_event_pointer *even
DeviceIntPtr dev = pInfo->dev;
struct xf86libinput *driver_data = pInfo->private;
ValuatorMask *mask = driver_data->valuators;
int axis;
double value;
if (libinput_event_pointer_get_axis(event) ==
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)
axis = 3;
else
axis = 2;
value = libinput_event_pointer_get_axis_value(event) / DEFAULT_LIBINPUT_AXIS_STEP_DISTANCE;
enum libinput_pointer_axis axis;
enum libinput_pointer_axis_source source;
valuator_mask_zero(mask);
valuator_mask_set_double(mask, axis, value);
source = libinput_event_pointer_get_axis_source(event);
switch(source) {
case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
break;
default:
return;
}
axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
if (libinput_event_pointer_has_axis(event, axis)) {
if (source == LIBINPUT_POINTER_AXIS_SOURCE_WHEEL)
value = libinput_event_pointer_get_axis_value_discrete(event, axis);
else
value = libinput_event_pointer_get_axis_value(event, axis);
valuator_mask_set_double(mask, 3, value);
}
axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
if (libinput_event_pointer_has_axis(event, axis)) {
if (source == LIBINPUT_POINTER_AXIS_SOURCE_WHEEL)
value = libinput_event_pointer_get_axis_value_discrete(event, axis);
else
value = libinput_event_pointer_get_axis_value(event, axis);
valuator_mask_set_double(mask, 2, value);
}
xf86PostMotionEventM(dev, Relative, mask);
}
@@ -763,14 +879,22 @@ xf86libinput_read_input(InputInfoPtr pInfo)
static int
open_restricted(const char *path, int flags, void *data)
{
int fd = open(path, flags);
struct xf86libinput_driver *context = data;
int fd;
fd = fd_get(context, path);
if (fd == -1)
fd = open(path, flags);
return fd < 0 ? -errno : fd;
}
static void
close_restricted(int fd, void *data)
{
close(fd);
struct xf86libinput_driver *context = data;
if (fd_find(context, fd) == -1)
close(fd);
}
const struct libinput_interface interface = {
@@ -931,17 +1055,17 @@ xf86libinput_parse_options(InputInfoPtr pInfo,
}
}
if (libinput_device_config_buttons_has_left_handed(device)) {
if (libinput_device_config_left_handed_is_available(device)) {
BOOL left_handed = xf86SetBoolOption(pInfo->options,
"LeftHanded",
libinput_device_config_buttons_get_left_handed(device));
if (libinput_device_config_buttons_set_left_handed(device,
left_handed) !=
libinput_device_config_left_handed_get(device));
if (libinput_device_config_left_handed_set(device,
left_handed) !=
LIBINPUT_CONFIG_STATUS_SUCCESS) {
xf86IDrvMsg(pInfo, X_ERROR,
"Failed to set LeftHanded to %d\n",
left_handed);
left_handed = libinput_device_config_buttons_get_left_handed(device);
left_handed = libinput_device_config_left_handed_get(device);
}
driver_data->options.left_handed = left_handed;
}
@@ -1004,7 +1128,6 @@ static int xf86libinput_pre_init(InputDriverPtr drv,
struct libinput_device *device;
char *path;
pInfo->fd = -1;
pInfo->type_name = 0;
pInfo->device_control = xf86libinput_device_control;
pInfo->read_input = xf86libinput_read_input;
@@ -1033,6 +1156,7 @@ static int xf86libinput_pre_init(InputDriverPtr drv,
/* we want all msgs, let the server filter */
libinput_log_set_priority(driver_context.libinput,
LIBINPUT_LOG_PRIORITY_DEBUG);
xorg_list_init(&driver_context.server_fds);
} else {
libinput_ref(driver_context.libinput);
}
@@ -1044,6 +1168,9 @@ static int xf86libinput_pre_init(InputDriverPtr drv,
goto fail;
}
if (use_server_fd(pInfo))
fd_push(&driver_context, pInfo->fd, path);
device = libinput_path_add_device(libinput, path);
if (!device) {
xf86IDrvMsg(pInfo, X_ERROR, "Failed to create a device for %s\n", path);
@@ -1055,8 +1182,9 @@ static int xf86libinput_pre_init(InputDriverPtr drv,
*/
libinput_device_ref(device);
libinput_path_remove_device(device);
if (use_server_fd(pInfo))
fd_pop(&driver_context, pInfo->fd);
pInfo->fd = -1;
pInfo->private = driver_data;
driver_data->path = path;
driver_data->device = device;
@@ -1081,6 +1209,8 @@ static int xf86libinput_pre_init(InputDriverPtr drv,
return Success;
fail:
if (use_server_fd(pInfo) && driver_context.libinput != NULL)
fd_pop(&driver_context, pInfo->fd);
if (driver_data->valuators)
valuator_mask_free(&driver_data->valuators);
free(path);
@@ -1109,6 +1239,11 @@ InputDriverRec xf86libinput_driver = {
.driverName = "libinput",
.PreInit = xf86libinput_pre_init,
.UnInit = xf86libinput_uninit,
.module = NULL,
.default_options= NULL,
#ifdef XI86_DRV_CAP_SERVER_FD
.capabilities = XI86_DRV_CAP_SERVER_FD
#endif
};
static XF86ModuleVersionInfo xf86libinput_version_info = {
@@ -1353,7 +1488,7 @@ LibinputSetPropertyLeftHanded(DeviceIntPtr dev,
data = (BOOL*)val->data;
if (checkonly) {
int supported = libinput_device_config_buttons_has_left_handed(device);
int supported = libinput_device_config_left_handed_is_available(device);
int left_handed = *data;
if (!supported && left_handed)
@@ -1586,7 +1721,7 @@ LibinputInitProperty(DeviceIntPtr dev)
}
if (libinput_device_config_buttons_has_left_handed(device)) {
if (libinput_device_config_left_handed_is_available(device)) {
BOOL left_handed = driver_data->options.left_handed;
prop_left_handed = MakeAtom(PROP_LEFT_HANDED,