summaryrefslogtreecommitdiff
path: root/src/evdev.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/evdev.c')
-rw-r--r--src/evdev.c143
1 files changed, 103 insertions, 40 deletions
diff --git a/src/evdev.c b/src/evdev.c
index 3bdd9985..a3a72ef8 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1386,6 +1386,27 @@ evdev_device_dispatch(void *data)
}
}
+static inline int
+evdev_init_accel(struct evdev_device *device,
+ enum libinput_config_accel_profile which)
+{
+ struct motion_filter *filter;
+
+ if (which == LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT)
+ filter = create_pointer_accelerator_filter_flat(device->dpi);
+ else if (device->tags & EVDEV_TAG_TRACKPOINT)
+ filter = create_pointer_accelerator_filter_trackpoint(device->dpi);
+ else if (device->dpi < DEFAULT_MOUSE_DPI)
+ filter = create_pointer_accelerator_filter_linear_low_dpi(device->dpi);
+ else
+ filter = create_pointer_accelerator_filter_linear(device->dpi);
+
+ if (!filter)
+ return -1;
+
+ return evdev_device_init_pointer_acceleration(device, filter);
+}
+
static int
evdev_accel_config_available(struct libinput_device *device)
{
@@ -1419,20 +1440,83 @@ evdev_accel_config_get_default_speed(struct libinput_device *device)
return 0.0;
}
+static uint32_t
+evdev_accel_config_get_profiles(struct libinput_device *libinput_device)
+{
+ struct evdev_device *device = (struct evdev_device*)libinput_device;
+
+ if (!device->pointer.filter)
+ return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
+
+ return LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE |
+ LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;
+}
+
+static enum libinput_config_status
+evdev_accel_config_set_profile(struct libinput_device *libinput_device,
+ enum libinput_config_accel_profile profile)
+{
+ struct evdev_device *device = (struct evdev_device*)libinput_device;
+ struct motion_filter *filter;
+ double speed;
+
+ filter = device->pointer.filter;
+ if (filter_get_type(filter) == profile)
+ return LIBINPUT_CONFIG_STATUS_SUCCESS;
+
+ speed = filter_get_speed(filter);
+ device->pointer.filter = NULL;
+
+ if (evdev_init_accel(device, profile) == 0) {
+ evdev_accel_config_set_speed(libinput_device, speed);
+ filter_destroy(filter);
+ } else {
+ device->pointer.filter = filter;
+ }
+
+ return LIBINPUT_CONFIG_STATUS_SUCCESS;
+}
+
+static enum libinput_config_accel_profile
+evdev_accel_config_get_profile(struct libinput_device *libinput_device)
+{
+ struct evdev_device *device = (struct evdev_device*)libinput_device;
+
+ return filter_get_type(device->pointer.filter);
+}
+
+static enum libinput_config_accel_profile
+evdev_accel_config_get_default_profile(struct libinput_device *libinput_device)
+{
+ struct evdev_device *device = (struct evdev_device*)libinput_device;
+
+ if (!device->pointer.filter)
+ return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
+
+ /* No device has a flat profile as default */
+ return LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
+}
+
int
evdev_device_init_pointer_acceleration(struct evdev_device *device,
struct motion_filter *filter)
{
device->pointer.filter = filter;
- device->pointer.config.available = evdev_accel_config_available;
- device->pointer.config.set_speed = evdev_accel_config_set_speed;
- device->pointer.config.get_speed = evdev_accel_config_get_speed;
- device->pointer.config.get_default_speed = evdev_accel_config_get_default_speed;
- device->base.config.accel = &device->pointer.config;
+ if (device->base.config.accel == NULL) {
+ device->pointer.config.available = evdev_accel_config_available;
+ device->pointer.config.set_speed = evdev_accel_config_set_speed;
+ device->pointer.config.get_speed = evdev_accel_config_get_speed;
+ device->pointer.config.get_default_speed = evdev_accel_config_get_default_speed;
+ device->pointer.config.get_profiles = evdev_accel_config_get_profiles;
+ device->pointer.config.set_profile = evdev_accel_config_set_profile;
+ device->pointer.config.get_profile = evdev_accel_config_get_profile;
+ device->pointer.config.get_default_profile = evdev_accel_config_get_default_profile;
+ device->base.config.accel = &device->pointer.config;
- evdev_accel_config_set_speed(&device->base,
- evdev_accel_config_get_default_speed(&device->base));
+ evdev_accel_config_set_speed(&device->base,
+ evdev_accel_config_get_default_speed(&device->base));
+ }
return 0;
}
@@ -1869,24 +1953,6 @@ evdev_configure_mt_device(struct evdev_device *device)
return 0;
}
-static inline int
-evdev_init_accel(struct evdev_device *device)
-{
- struct motion_filter *filter;
-
- if (device->tags & EVDEV_TAG_TRACKPOINT)
- filter = create_pointer_accelerator_filter_trackpoint(device->dpi);
- else if (device->dpi < DEFAULT_MOUSE_DPI)
- filter = create_pointer_accelerator_filter_linear_low_dpi(device->dpi);
- else
- filter = create_pointer_accelerator_filter_linear(device->dpi);
-
- if (!filter)
- return -1;
-
- return evdev_device_init_pointer_acceleration(device, filter);
-}
-
static int
evdev_configure_device(struct evdev_device *device)
{
@@ -1919,6 +1985,13 @@ evdev_configure_device(struct evdev_device *device)
udev_tags & EVDEV_UDEV_TAG_ACCELEROMETER ? " Accelerometer" : "",
udev_tags & EVDEV_UDEV_TAG_BUTTONSET ? " Buttonset" : "");
+ if (udev_tags & EVDEV_UDEV_TAG_ACCELEROMETER) {
+ log_info(libinput,
+ "input device '%s', %s is an accelerometer, ignoring\n",
+ device->devname, devnode);
+ return -1;
+ }
+
/* libwacom *adds* TABLET, TOUCHPAD but leaves JOYSTICK in place, so
make sure we only ignore real joystick devices */
if ((udev_tags & EVDEV_UDEV_TAG_JOYSTICK) == udev_tags) {
@@ -1998,7 +2071,7 @@ evdev_configure_device(struct evdev_device *device)
if (libevdev_has_event_code(evdev, EV_REL, REL_X) &&
libevdev_has_event_code(evdev, EV_REL, REL_Y) &&
- evdev_init_accel(device) == -1)
+ evdev_init_accel(device, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE) == -1)
return -1;
device->seat_caps |= EVDEV_DEVICE_POINTER;
@@ -2098,27 +2171,17 @@ static int
evdev_set_device_group(struct evdev_device *device,
struct udev_device *udev_device)
{
+ struct libinput *libinput = device->base.seat->libinput;
struct libinput_device_group *group = NULL;
const char *udev_group;
udev_group = udev_device_get_property_value(udev_device,
"LIBINPUT_DEVICE_GROUP");
- if (udev_group) {
- struct libinput_device *d;
-
- list_for_each(d, &device->base.seat->devices_list, link) {
- const char *identifier = d->group->identifier;
-
- if (identifier &&
- strcmp(identifier, udev_group) == 0) {
- group = d->group;
- break;
- }
- }
- }
+ if (udev_group)
+ group = libinput_device_group_find_group(libinput, udev_group);
if (!group) {
- group = libinput_device_group_create(udev_group);
+ group = libinput_device_group_create(libinput, udev_group);
if (!group)
return 1;
libinput_device_set_device_group(&device->base, group);