2 * Copyright © 2013 Red Hat, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32 int path_input_process_event(struct libinput_event);
33 static void path_seat_destroy(struct libinput_seat *seat);
36 path_input_disable(struct libinput *libinput)
38 struct path_input *input = (struct path_input*)libinput;
39 struct evdev_device *device = input->device;
40 struct path_seat *seat, *tmp;
43 close_restricted(libinput, device->fd);
44 evdev_device_remove(device);
48 /* should only be one seat anyway */
49 list_for_each_safe(seat, tmp, &libinput->seat_list, base.link) {
50 list_remove(&seat->base.link);
51 list_init(&seat->base.link);
52 libinput_seat_unref(&seat->base);
57 path_seat_destroy(struct libinput_seat *seat)
59 struct path_seat *pseat = (struct path_seat*)seat;
63 static struct path_seat*
64 path_seat_create(struct path_input *input)
66 struct path_seat *seat;
68 seat = zalloc(sizeof(*seat));
72 seat->name = "default";
74 /* FIXME: get physical seat from udev */
75 libinput_seat_init(&seat->base, &input->base, seat->name, seat->name, path_seat_destroy);
76 list_insert(&input->base.seat_list, &seat->base.link);
82 path_get_sysname(const char *path)
84 struct udev *udev = NULL;
85 struct udev_device *device = NULL;
93 if (stat(path, &st) < 0)
96 device = udev_device_new_from_devnum(udev, 'c', st.st_rdev);
100 syspath = strdup(udev_device_get_syspath(device));
103 udev_device_unref(device);
110 path_input_enable(struct libinput *libinput)
112 struct path_input *input = (struct path_input*)libinput;
113 struct path_seat *seat;
114 struct evdev_device *device;
115 const char *devnode = input->path;
122 fd = open_restricted(libinput, input->path, O_RDWR|O_NONBLOCK);
124 log_info("opening input device '%s' failed.\n", devnode);
128 syspath = path_get_sysname(devnode);
130 close_restricted(libinput, fd);
131 log_info("failed to obtain syspath for device '%s'.\n", devnode);
135 seat = path_seat_create(input);
137 device = evdev_device_create(&seat->base, devnode, syspath, fd);
140 if (device == EVDEV_UNHANDLED_DEVICE) {
141 close_restricted(libinput, fd);
142 log_info("not using input device '%s'.\n", devnode);
143 libinput_seat_unref(&seat->base);
145 } else if (device == NULL) {
146 close_restricted(libinput, fd);
147 log_info("failed to create input device '%s'.\n", devnode);
148 libinput_seat_unref(&seat->base);
152 input->device = device;
158 path_input_destroy(struct libinput *input)
160 struct path_input *path_input = (struct path_input*)input;
161 free(path_input->path);
164 static const struct libinput_interface_backend interface_backend = {
165 .resume = path_input_enable,
166 .suspend = path_input_disable,
167 .destroy = path_input_destroy,
170 LIBINPUT_EXPORT struct libinput *
171 libinput_create_from_path(const struct libinput_interface *interface,
175 struct path_input *input;
177 if (!interface || !path)
180 input = zalloc(sizeof *input);
184 if (libinput_init(&input->base, interface,
185 &interface_backend, user_data) != 0) {
190 input->path = strdup(path);
192 if (path_input_enable(&input->base) < 0) {
193 libinput_destroy(&input->base);