2013-12-10 13:20:36 +10:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and
|
|
|
|
|
* its documentation for any purpose is hereby granted without fee, provided
|
|
|
|
|
* that the above copyright notice appear in all copies and that both that
|
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
|
* documentation, and that the name of the copyright holders not be used in
|
|
|
|
|
* advertising or publicity pertaining to distribution of the software
|
|
|
|
|
* without specific, written prior permission. The copyright holders make
|
|
|
|
|
* no representations about the suitability of this software for any
|
|
|
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
|
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
|
|
|
|
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2014-01-29 16:37:45 +10:00
|
|
|
#include <errno.h>
|
2013-12-10 13:20:36 +10:00
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <libudev.h>
|
|
|
|
|
|
|
|
|
|
#include "path.h"
|
|
|
|
|
#include "evdev.h"
|
|
|
|
|
|
2014-01-21 12:03:47 +10:00
|
|
|
static const char default_seat[] = "seat0";
|
|
|
|
|
static const char default_seat_name[] = "default";
|
|
|
|
|
|
2013-12-10 13:20:36 +10:00
|
|
|
int path_input_process_event(struct libinput_event);
|
|
|
|
|
static void path_seat_destroy(struct libinput_seat *seat);
|
|
|
|
|
|
2014-01-29 16:37:45 +10:00
|
|
|
static void
|
|
|
|
|
path_disable_device(struct libinput *libinput,
|
|
|
|
|
struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_seat *seat = device->base.seat;
|
|
|
|
|
struct evdev_device *dev, *next;
|
|
|
|
|
|
|
|
|
|
list_for_each_safe(dev, next,
|
|
|
|
|
&seat->devices_list, base.link) {
|
|
|
|
|
if (dev != device)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
evdev_device_remove(device);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-10 13:20:36 +10:00
|
|
|
static void
|
|
|
|
|
path_input_disable(struct libinput *libinput)
|
|
|
|
|
{
|
|
|
|
|
struct path_input *input = (struct path_input*)libinput;
|
2014-01-29 15:57:53 +10:00
|
|
|
struct path_seat *seat, *tmp;
|
|
|
|
|
struct evdev_device *device, *next;
|
|
|
|
|
|
|
|
|
|
list_for_each_safe(seat, tmp, &input->base.seat_list, base.link) {
|
|
|
|
|
libinput_seat_ref(&seat->base);
|
|
|
|
|
list_for_each_safe(device, next,
|
2014-01-29 16:37:45 +10:00
|
|
|
&seat->base.devices_list, base.link)
|
|
|
|
|
path_disable_device(libinput, device);
|
2014-01-29 15:57:53 +10:00
|
|
|
libinput_seat_unref(&seat->base);
|
2013-12-10 13:20:36 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
path_seat_destroy(struct libinput_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
struct path_seat *pseat = (struct path_seat*)seat;
|
|
|
|
|
free(pseat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct path_seat*
|
2014-01-21 12:03:47 +10:00
|
|
|
path_seat_create(struct path_input *input,
|
|
|
|
|
const char *seat_name,
|
|
|
|
|
const char *seat_logical_name)
|
2013-12-10 13:20:36 +10:00
|
|
|
{
|
|
|
|
|
struct path_seat *seat;
|
|
|
|
|
|
|
|
|
|
seat = zalloc(sizeof(*seat));
|
|
|
|
|
if (!seat)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2014-01-21 12:03:47 +10:00
|
|
|
libinput_seat_init(&seat->base, &input->base, seat_name,
|
|
|
|
|
seat_logical_name, path_seat_destroy);
|
2013-12-10 13:20:36 +10:00
|
|
|
|
|
|
|
|
return seat;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 15:57:53 +10:00
|
|
|
static struct path_seat*
|
|
|
|
|
path_seat_get_named(struct path_input *input,
|
|
|
|
|
const char *seat_name_physical,
|
|
|
|
|
const char *seat_name_logical)
|
|
|
|
|
{
|
|
|
|
|
struct path_seat *seat;
|
|
|
|
|
|
|
|
|
|
list_for_each(seat, &input->base.seat_list, base.link) {
|
|
|
|
|
if (strcmp(seat->base.physical_name, seat_name_physical) == 0 &&
|
|
|
|
|
strcmp(seat->base.logical_name, seat_name_logical) == 0)
|
|
|
|
|
return seat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-21 12:03:47 +10:00
|
|
|
static int
|
2014-11-20 13:36:32 +10:00
|
|
|
path_get_udev_properties(struct udev *udev,
|
|
|
|
|
const char *path,
|
2014-01-28 15:46:37 +10:00
|
|
|
char **sysname,
|
2014-01-30 16:33:24 +10:00
|
|
|
char **syspath,
|
2014-01-21 12:03:47 +10:00
|
|
|
char **seat_name,
|
|
|
|
|
char **seat_logical_name)
|
2013-12-10 13:20:36 +10:00
|
|
|
{
|
|
|
|
|
struct udev_device *device = NULL;
|
|
|
|
|
struct stat st;
|
2014-01-21 12:03:47 +10:00
|
|
|
const char *seat;
|
|
|
|
|
int rc = -1;
|
2013-12-10 13:20:36 +10:00
|
|
|
|
|
|
|
|
if (stat(path, &st) < 0)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
device = udev_device_new_from_devnum(udev, 'c', st.st_rdev);
|
|
|
|
|
if (!device)
|
|
|
|
|
goto out;
|
|
|
|
|
|
2014-01-28 15:46:37 +10:00
|
|
|
*sysname = strdup(udev_device_get_sysname(device));
|
2014-01-30 16:33:24 +10:00
|
|
|
*syspath = strdup(udev_device_get_syspath(device));
|
2014-01-21 12:03:47 +10:00
|
|
|
|
|
|
|
|
seat = udev_device_get_property_value(device, "ID_SEAT");
|
|
|
|
|
*seat_name = strdup(seat ? seat : default_seat);
|
|
|
|
|
|
|
|
|
|
seat = udev_device_get_property_value(device, "WL_SEAT");
|
|
|
|
|
*seat_logical_name = strdup(seat ? seat : default_seat_name);
|
|
|
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
|
|
2013-12-10 13:20:36 +10:00
|
|
|
out:
|
|
|
|
|
if (device)
|
|
|
|
|
udev_device_unref(device);
|
2014-01-21 12:03:47 +10:00
|
|
|
return rc;
|
2013-12-10 13:20:36 +10:00
|
|
|
}
|
|
|
|
|
|
2014-01-29 15:57:53 +10:00
|
|
|
static struct libinput_device *
|
|
|
|
|
path_device_enable(struct path_input *input, const char *devnode)
|
2013-12-10 13:20:36 +10:00
|
|
|
{
|
|
|
|
|
struct path_seat *seat;
|
2014-01-29 15:57:53 +10:00
|
|
|
struct evdev_device *device = NULL;
|
2014-01-30 16:33:24 +10:00
|
|
|
char *sysname = NULL, *syspath = NULL;
|
2014-02-21 22:17:17 +01:00
|
|
|
char *seat_name = NULL, *seat_logical_name = NULL;
|
2013-12-10 13:20:36 +10:00
|
|
|
|
2014-11-20 13:36:32 +10:00
|
|
|
if (path_get_udev_properties(input->udev,
|
|
|
|
|
devnode,
|
|
|
|
|
&sysname,
|
|
|
|
|
&syspath,
|
|
|
|
|
&seat_name,
|
|
|
|
|
&seat_logical_name) == -1) {
|
2014-06-18 19:51:19 +10:00
|
|
|
log_info(&input->base,
|
|
|
|
|
"failed to obtain sysname for device '%s'.\n",
|
|
|
|
|
devnode);
|
2014-01-29 15:57:53 +10:00
|
|
|
return NULL;
|
2013-12-10 13:20:36 +10:00
|
|
|
}
|
|
|
|
|
|
2014-01-29 15:57:53 +10:00
|
|
|
seat = path_seat_get_named(input, seat_name, seat_logical_name);
|
2013-12-10 13:20:36 +10:00
|
|
|
|
2014-01-29 15:57:53 +10:00
|
|
|
if (seat) {
|
|
|
|
|
libinput_seat_ref(&seat->base);
|
|
|
|
|
} else {
|
|
|
|
|
seat = path_seat_create(input, seat_name, seat_logical_name);
|
|
|
|
|
if (!seat) {
|
2014-06-18 19:51:19 +10:00
|
|
|
log_info(&input->base,
|
|
|
|
|
"failed to create seat for device '%s'.\n",
|
|
|
|
|
devnode);
|
2014-01-29 15:57:53 +10:00
|
|
|
goto out;
|
|
|
|
|
}
|
2014-01-29 16:08:54 +10:00
|
|
|
}
|
|
|
|
|
|
2014-01-30 16:33:24 +10:00
|
|
|
device = evdev_device_create(&seat->base, devnode, sysname, syspath);
|
2014-01-22 23:48:39 +01:00
|
|
|
libinput_seat_unref(&seat->base);
|
2013-12-10 13:20:36 +10:00
|
|
|
|
|
|
|
|
if (device == EVDEV_UNHANDLED_DEVICE) {
|
2014-01-29 15:57:53 +10:00
|
|
|
device = NULL;
|
2014-06-18 19:51:19 +10:00
|
|
|
log_info(&input->base,
|
|
|
|
|
"not using input device '%s'.\n",
|
|
|
|
|
devnode);
|
2014-01-29 15:57:53 +10:00
|
|
|
goto out;
|
2013-12-10 13:20:36 +10:00
|
|
|
} else if (device == NULL) {
|
2014-06-18 19:51:19 +10:00
|
|
|
log_info(&input->base,
|
|
|
|
|
"failed to create input device '%s'.\n",
|
|
|
|
|
devnode);
|
2014-01-29 15:57:53 +10:00
|
|
|
goto out;
|
2013-12-10 13:20:36 +10:00
|
|
|
}
|
|
|
|
|
|
2014-01-29 15:57:53 +10:00
|
|
|
out:
|
|
|
|
|
free(sysname);
|
2014-01-30 16:33:24 +10:00
|
|
|
free(syspath);
|
2014-01-29 15:57:53 +10:00
|
|
|
free(seat_name);
|
|
|
|
|
free(seat_logical_name);
|
|
|
|
|
|
|
|
|
|
return device ? &device->base : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
path_input_enable(struct libinput *libinput)
|
|
|
|
|
{
|
|
|
|
|
struct path_input *input = (struct path_input*)libinput;
|
|
|
|
|
struct path_device *dev;
|
|
|
|
|
|
|
|
|
|
list_for_each(dev, &input->path_list, link) {
|
|
|
|
|
if (path_device_enable(input, dev->path) == NULL) {
|
|
|
|
|
path_input_disable(libinput);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-10 13:20:36 +10:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
path_input_destroy(struct libinput *input)
|
|
|
|
|
{
|
|
|
|
|
struct path_input *path_input = (struct path_input*)input;
|
2014-01-29 15:57:53 +10:00
|
|
|
struct path_device *dev, *tmp;
|
|
|
|
|
|
2014-11-20 13:36:32 +10:00
|
|
|
udev_unref(path_input->udev);
|
|
|
|
|
|
2014-01-29 15:57:53 +10:00
|
|
|
list_for_each_safe(dev, tmp, &path_input->path_list, link) {
|
|
|
|
|
free(dev->path);
|
|
|
|
|
free(dev);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-10 13:20:36 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct libinput_interface_backend interface_backend = {
|
|
|
|
|
.resume = path_input_enable,
|
|
|
|
|
.suspend = path_input_disable,
|
|
|
|
|
.destroy = path_input_destroy,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT struct libinput *
|
2014-01-29 15:38:48 +10:00
|
|
|
libinput_path_create_context(const struct libinput_interface *interface,
|
|
|
|
|
void *user_data)
|
2013-12-10 13:20:36 +10:00
|
|
|
{
|
|
|
|
|
struct path_input *input;
|
2014-11-20 13:36:32 +10:00
|
|
|
struct udev *udev;
|
2013-12-10 13:20:36 +10:00
|
|
|
|
2014-01-29 15:38:48 +10:00
|
|
|
if (!interface)
|
2013-12-10 13:20:36 +10:00
|
|
|
return NULL;
|
|
|
|
|
|
2014-11-20 13:36:32 +10:00
|
|
|
udev = udev_new();
|
|
|
|
|
if (!udev)
|
2013-12-10 13:20:36 +10:00
|
|
|
return NULL;
|
|
|
|
|
|
2014-11-20 13:36:32 +10:00
|
|
|
input = zalloc(sizeof *input);
|
|
|
|
|
if (!input ||
|
|
|
|
|
libinput_init(&input->base, interface,
|
2013-12-10 13:20:36 +10:00
|
|
|
&interface_backend, user_data) != 0) {
|
2014-11-20 13:36:32 +10:00
|
|
|
udev_unref(udev);
|
2013-12-10 13:20:36 +10:00
|
|
|
free(input);
|
2014-01-29 15:57:53 +10:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 13:36:32 +10:00
|
|
|
input->udev = udev;
|
2014-01-29 15:57:53 +10:00
|
|
|
list_init(&input->path_list);
|
|
|
|
|
|
2013-12-10 13:20:36 +10:00
|
|
|
return &input->base;
|
|
|
|
|
}
|
2014-01-29 16:37:45 +10:00
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT struct libinput_device *
|
|
|
|
|
libinput_path_add_device(struct libinput *libinput,
|
|
|
|
|
const char *path)
|
|
|
|
|
{
|
|
|
|
|
struct path_input *input = (struct path_input*)libinput;
|
|
|
|
|
struct path_device *dev;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
|
|
|
|
|
if (libinput->interface_backend != &interface_backend) {
|
2014-06-18 19:51:19 +10:00
|
|
|
log_bug_client(libinput, "Mismatching backends.\n");
|
2014-01-29 16:37:45 +10:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dev = zalloc(sizeof *dev);
|
|
|
|
|
if (!dev)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
dev->path = strdup(path);
|
|
|
|
|
if (!dev->path) {
|
|
|
|
|
free(dev);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list_insert(&input->path_list, &dev->link);
|
|
|
|
|
|
|
|
|
|
device = path_device_enable(input, dev->path);
|
|
|
|
|
|
|
|
|
|
if (!device) {
|
|
|
|
|
list_remove(&dev->link);
|
|
|
|
|
free(dev->path);
|
|
|
|
|
free(dev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return device;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT void
|
|
|
|
|
libinput_path_remove_device(struct libinput_device *device)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *libinput = device->seat->libinput;
|
|
|
|
|
struct path_input *input = (struct path_input*)libinput;
|
|
|
|
|
struct libinput_seat *seat;
|
|
|
|
|
struct evdev_device *evdev = (struct evdev_device*)device;
|
|
|
|
|
struct path_device *dev;
|
|
|
|
|
|
|
|
|
|
if (libinput->interface_backend != &interface_backend) {
|
2014-06-18 19:51:19 +10:00
|
|
|
log_bug_client(libinput, "Mismatching backends.\n");
|
2014-01-29 16:37:45 +10:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list_for_each(dev, &input->path_list, link) {
|
|
|
|
|
if (strcmp(evdev->devnode, dev->path) == 0) {
|
|
|
|
|
list_remove(&dev->link);
|
|
|
|
|
free(dev->path);
|
|
|
|
|
free(dev);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
seat = device->seat;
|
|
|
|
|
libinput_seat_ref(seat);
|
|
|
|
|
path_disable_device(libinput, evdev);
|
|
|
|
|
libinput_seat_unref(seat);
|
|
|
|
|
}
|