2013-02-18 16:15:53 -05:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 Intel Corporation
|
2015-05-28 08:23:59 +10:00
|
|
|
* Copyright © 2013-2015 Red Hat, Inc.
|
2013-02-18 16:15:53 -05:00
|
|
|
*
|
2015-06-11 12:09:18 +10:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2013-02-18 16:15:53 -05:00
|
|
|
*
|
2015-06-11 12:09:18 +10:00
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2013-02-18 16:15:53 -05:00
|
|
|
*/
|
|
|
|
|
|
2013-05-22 18:03:19 +03:00
|
|
|
#include "config.h"
|
|
|
|
|
|
2013-02-18 16:15:53 -05:00
|
|
|
#include <stdlib.h>
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
#include <stdio.h>
|
2013-02-18 16:15:53 -05:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
|
|
#include "evdev.h"
|
|
|
|
|
#include "udev-seat.h"
|
|
|
|
|
|
|
|
|
|
static const char default_seat[] = "seat0";
|
2013-05-31 18:09:59 +01:00
|
|
|
static const char default_seat_name[] = "default";
|
2013-02-18 16:15:53 -05:00
|
|
|
|
2013-05-31 18:09:58 +01:00
|
|
|
static struct udev_seat *
|
2014-01-15 17:04:00 +10:00
|
|
|
udev_seat_create(struct udev_input *input,
|
|
|
|
|
const char *device_seat,
|
|
|
|
|
const char *seat_name);
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
static struct udev_seat *
|
|
|
|
|
udev_seat_get_named(struct udev_input *input, const char *seat_name);
|
2013-05-31 18:09:58 +01:00
|
|
|
|
2013-02-18 16:15:53 -05:00
|
|
|
static int
|
2014-11-19 14:12:16 +10:00
|
|
|
device_added(struct udev_device *udev_device,
|
|
|
|
|
struct udev_input *input,
|
|
|
|
|
const char *seat_name)
|
2013-02-18 16:15:53 -05:00
|
|
|
{
|
|
|
|
|
struct evdev_device *device;
|
2017-02-13 14:17:52 +10:00
|
|
|
const char *devnode, *sysname;
|
2014-11-19 14:12:16 +10:00
|
|
|
const char *device_seat, *output_name;
|
2013-05-31 18:09:58 +01:00
|
|
|
struct udev_seat *seat;
|
2013-02-18 16:15:53 -05:00
|
|
|
|
|
|
|
|
device_seat = udev_device_get_property_value(udev_device, "ID_SEAT");
|
|
|
|
|
if (!device_seat)
|
|
|
|
|
device_seat = default_seat;
|
|
|
|
|
|
2015-05-26 08:46:05 +10:00
|
|
|
if (!streq(device_seat, input->seat_id))
|
2013-02-18 16:15:53 -05:00
|
|
|
return 0;
|
|
|
|
|
|
2015-07-27 16:08:04 +08:00
|
|
|
if (ignore_litest_test_suite_device(udev_device))
|
|
|
|
|
return 0;
|
|
|
|
|
|
2013-02-18 16:15:53 -05:00
|
|
|
devnode = udev_device_get_devnode(udev_device);
|
2017-02-13 14:17:52 +10:00
|
|
|
sysname = udev_device_get_sysname(udev_device);
|
2013-02-18 16:15:53 -05:00
|
|
|
|
2013-05-31 18:09:59 +01:00
|
|
|
/* Search for matching logical seat */
|
2014-11-19 14:12:16 +10:00
|
|
|
if (!seat_name)
|
|
|
|
|
seat_name = udev_device_get_property_value(udev_device, "WL_SEAT");
|
2013-05-31 18:09:59 +01:00
|
|
|
if (!seat_name)
|
|
|
|
|
seat_name = default_seat_name;
|
2013-05-31 18:09:58 +01:00
|
|
|
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
seat = udev_seat_get_named(input, seat_name);
|
2013-05-31 18:09:59 +01:00
|
|
|
|
2013-12-23 14:10:56 +10:00
|
|
|
if (seat)
|
|
|
|
|
libinput_seat_ref(&seat->base);
|
|
|
|
|
else {
|
2014-01-15 17:04:00 +10:00
|
|
|
seat = udev_seat_create(input, device_seat, seat_name);
|
2013-12-23 14:10:56 +10:00
|
|
|
if (!seat)
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2013-05-31 18:09:58 +01:00
|
|
|
|
2014-11-20 13:55:48 +10:00
|
|
|
device = evdev_device_create(&seat->base, udev_device);
|
2014-01-22 23:48:39 +01:00
|
|
|
libinput_seat_unref(&seat->base);
|
|
|
|
|
|
2013-02-18 16:15:53 -05:00
|
|
|
if (device == EVDEV_UNHANDLED_DEVICE) {
|
2017-02-13 14:17:52 +10:00
|
|
|
log_info(&input->base,
|
|
|
|
|
"%-7s - not using input device '%s'\n",
|
|
|
|
|
sysname,
|
|
|
|
|
devnode);
|
2014-01-22 23:48:39 +01:00
|
|
|
return 0;
|
2013-02-18 16:15:53 -05:00
|
|
|
} else if (device == NULL) {
|
2017-02-13 14:17:52 +10:00
|
|
|
log_info(&input->base,
|
|
|
|
|
"%-7s - failed to create input device '%s'\n",
|
|
|
|
|
sysname,
|
|
|
|
|
devnode);
|
2014-01-22 23:48:39 +01:00
|
|
|
return 0;
|
2013-02-18 16:15:53 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-25 13:54:35 +10:00
|
|
|
evdev_read_calibration_prop(device);
|
2013-02-18 16:15:53 -05:00
|
|
|
|
2013-07-22 15:11:11 -07:00
|
|
|
output_name = udev_device_get_property_value(udev_device, "WL_OUTPUT");
|
2017-07-07 09:47:06 +10:00
|
|
|
device->output_name = safe_strdup(output_name);
|
2013-10-17 23:04:08 +02:00
|
|
|
|
2013-02-18 16:15:53 -05:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-13 14:24:48 +10:00
|
|
|
static void
|
|
|
|
|
device_removed(struct udev_device *udev_device, struct udev_input *input)
|
|
|
|
|
{
|
|
|
|
|
struct evdev_device *device, *next;
|
|
|
|
|
struct udev_seat *seat;
|
2014-11-20 13:55:48 +10:00
|
|
|
const char *syspath;
|
2014-03-13 14:24:48 +10:00
|
|
|
|
2014-11-20 13:55:48 +10:00
|
|
|
syspath = udev_device_get_syspath(udev_device);
|
2014-03-13 14:24:48 +10:00
|
|
|
list_for_each(seat, &input->base.seat_list, base.link) {
|
|
|
|
|
list_for_each_safe(device, next,
|
|
|
|
|
&seat->base.devices_list, base.link) {
|
2015-05-26 08:46:05 +10:00
|
|
|
if (streq(syspath,
|
|
|
|
|
udev_device_get_syspath(device->udev_device))) {
|
2014-03-13 14:24:48 +10:00
|
|
|
evdev_device_remove(device);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-18 16:50:19 -05:00
|
|
|
static int
|
2013-05-31 18:09:54 +01:00
|
|
|
udev_input_add_devices(struct udev_input *input, struct udev *udev)
|
2013-02-18 16:15:53 -05:00
|
|
|
{
|
|
|
|
|
struct udev_enumerate *e;
|
|
|
|
|
struct udev_list_entry *entry;
|
|
|
|
|
struct udev_device *device;
|
|
|
|
|
const char *path, *sysname;
|
|
|
|
|
|
|
|
|
|
e = udev_enumerate_new(udev);
|
|
|
|
|
udev_enumerate_add_match_subsystem(e, "input");
|
|
|
|
|
udev_enumerate_scan_devices(e);
|
|
|
|
|
udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
|
|
|
|
|
path = udev_list_entry_get_name(entry);
|
|
|
|
|
device = udev_device_new_from_syspath(udev, path);
|
2015-02-18 13:36:44 +10:00
|
|
|
if (!device)
|
|
|
|
|
continue;
|
2013-02-18 16:15:53 -05:00
|
|
|
|
|
|
|
|
sysname = udev_device_get_sysname(device);
|
|
|
|
|
if (strncmp("event", sysname, 5) != 0) {
|
|
|
|
|
udev_device_unref(device);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-04 14:51:33 +03:00
|
|
|
/* Skip unconfigured device. udev will send an event
|
|
|
|
|
* when device is fully configured */
|
|
|
|
|
if (!udev_device_get_is_initialized(device)) {
|
|
|
|
|
log_debug(&input->base,
|
|
|
|
|
"%-7s - skip unconfigured input device '%s'\n",
|
|
|
|
|
sysname,
|
|
|
|
|
udev_device_get_devnode(device));
|
|
|
|
|
udev_device_unref(device);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-19 14:12:16 +10:00
|
|
|
if (device_added(device, input, NULL) < 0) {
|
2013-02-18 16:15:53 -05:00
|
|
|
udev_device_unref(device);
|
|
|
|
|
udev_enumerate_unref(e);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
udev_device_unref(device);
|
|
|
|
|
}
|
|
|
|
|
udev_enumerate_unref(e);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
static void
|
|
|
|
|
evdev_udev_handler(void *data)
|
2013-02-18 16:15:53 -05:00
|
|
|
{
|
2013-05-31 18:09:54 +01:00
|
|
|
struct udev_input *input = data;
|
2013-02-18 16:15:53 -05:00
|
|
|
struct udev_device *udev_device;
|
|
|
|
|
const char *action;
|
|
|
|
|
|
2013-05-31 18:09:54 +01:00
|
|
|
udev_device = udev_monitor_receive_device(input->udev_monitor);
|
2013-02-18 16:15:53 -05:00
|
|
|
if (!udev_device)
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
return;
|
2013-02-18 16:15:53 -05:00
|
|
|
|
|
|
|
|
action = udev_device_get_action(udev_device);
|
|
|
|
|
if (!action)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
if (strncmp("event", udev_device_get_sysname(udev_device), 5) != 0)
|
|
|
|
|
goto out;
|
|
|
|
|
|
2015-05-26 08:46:05 +10:00
|
|
|
if (streq(action, "add"))
|
2014-11-19 14:12:16 +10:00
|
|
|
device_added(udev_device, input, NULL);
|
2015-05-26 08:46:05 +10:00
|
|
|
else if (streq(action, "remove"))
|
2014-03-13 14:24:48 +10:00
|
|
|
device_removed(udev_device, input);
|
2013-02-18 16:15:53 -05:00
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
udev_device_unref(udev_device);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 11:37:31 +10:00
|
|
|
static void
|
|
|
|
|
udev_input_remove_devices(struct udev_input *input)
|
|
|
|
|
{
|
|
|
|
|
struct evdev_device *device, *next;
|
2013-12-23 14:10:56 +10:00
|
|
|
struct udev_seat *seat, *tmp;
|
2013-12-13 11:37:31 +10:00
|
|
|
|
2013-12-23 14:10:56 +10:00
|
|
|
list_for_each_safe(seat, tmp, &input->base.seat_list, base.link) {
|
2014-01-15 16:31:29 +10:00
|
|
|
libinput_seat_ref(&seat->base);
|
2013-12-13 11:37:31 +10:00
|
|
|
list_for_each_safe(device, next,
|
|
|
|
|
&seat->base.devices_list, base.link) {
|
|
|
|
|
evdev_device_remove(device);
|
|
|
|
|
}
|
2014-01-15 16:31:29 +10:00
|
|
|
libinput_seat_unref(&seat->base);
|
2013-12-13 11:37:31 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
udev_input_disable(struct libinput *libinput)
|
2013-02-18 16:15:53 -05:00
|
|
|
{
|
2013-12-13 11:37:31 +10:00
|
|
|
struct udev_input *input = (struct udev_input*)libinput;
|
|
|
|
|
|
|
|
|
|
if (!input->udev_monitor)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
udev_monitor_unref(input->udev_monitor);
|
|
|
|
|
input->udev_monitor = NULL;
|
|
|
|
|
libinput_remove_source(&input->base, input->udev_monitor_source);
|
|
|
|
|
input->udev_monitor_source = NULL;
|
|
|
|
|
|
|
|
|
|
udev_input_remove_devices(input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
udev_input_enable(struct libinput *libinput)
|
|
|
|
|
{
|
|
|
|
|
struct udev_input *input = (struct udev_input*)libinput;
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
struct udev *udev = input->udev;
|
2013-02-18 16:15:53 -05:00
|
|
|
int fd;
|
|
|
|
|
|
2018-02-16 16:42:00 +10:00
|
|
|
if (input->udev_monitor || !input->seat_id)
|
2014-01-08 12:53:46 +10:00
|
|
|
return 0;
|
|
|
|
|
|
2013-05-31 18:09:54 +01:00
|
|
|
input->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
|
|
|
|
|
if (!input->udev_monitor) {
|
2014-06-18 19:51:19 +10:00
|
|
|
log_info(libinput,
|
|
|
|
|
"udev: failed to create the udev monitor\n");
|
2013-02-18 16:50:19 -05:00
|
|
|
return -1;
|
2013-02-18 16:15:53 -05:00
|
|
|
}
|
|
|
|
|
|
2013-05-31 18:09:54 +01:00
|
|
|
udev_monitor_filter_add_match_subsystem_devtype(input->udev_monitor,
|
2013-02-18 16:15:53 -05:00
|
|
|
"input", NULL);
|
|
|
|
|
|
2013-05-31 18:09:54 +01:00
|
|
|
if (udev_monitor_enable_receiving(input->udev_monitor)) {
|
2014-06-18 19:51:19 +10:00
|
|
|
log_info(libinput, "udev: failed to bind the udev monitor\n");
|
2013-05-31 18:09:54 +01:00
|
|
|
udev_monitor_unref(input->udev_monitor);
|
2014-01-08 12:53:46 +10:00
|
|
|
input->udev_monitor = NULL;
|
2013-02-18 16:50:19 -05:00
|
|
|
return -1;
|
2013-02-18 16:15:53 -05:00
|
|
|
}
|
|
|
|
|
|
2013-05-31 18:09:54 +01:00
|
|
|
fd = udev_monitor_get_fd(input->udev_monitor);
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
input->udev_monitor_source = libinput_add_fd(&input->base,
|
|
|
|
|
fd,
|
|
|
|
|
evdev_udev_handler,
|
|
|
|
|
input);
|
2013-05-31 18:09:54 +01:00
|
|
|
if (!input->udev_monitor_source) {
|
|
|
|
|
udev_monitor_unref(input->udev_monitor);
|
2014-01-08 12:53:46 +10:00
|
|
|
input->udev_monitor = NULL;
|
2013-02-18 16:50:19 -05:00
|
|
|
return -1;
|
2013-02-18 16:15:53 -05:00
|
|
|
}
|
|
|
|
|
|
2013-12-05 18:37:26 +10:00
|
|
|
if (udev_input_add_devices(input, udev) < 0) {
|
2013-12-13 11:37:31 +10:00
|
|
|
udev_input_disable(libinput);
|
2013-02-18 16:50:19 -05:00
|
|
|
return -1;
|
2013-12-05 18:37:26 +10:00
|
|
|
}
|
2013-02-18 16:50:19 -05:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-12-13 11:37:31 +10:00
|
|
|
udev_input_destroy(struct libinput *input)
|
2013-02-18 16:15:53 -05:00
|
|
|
{
|
2013-12-13 11:37:31 +10:00
|
|
|
struct udev_input *udev_input = (struct udev_input*)input;
|
2013-12-09 21:27:31 +10:00
|
|
|
|
|
|
|
|
if (input == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-12-13 11:37:31 +10:00
|
|
|
udev_unref(udev_input->udev);
|
|
|
|
|
free(udev_input->seat_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
udev_seat_destroy(struct libinput_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
struct udev_seat *useat = (struct udev_seat*)seat;
|
|
|
|
|
free(useat);
|
2013-02-18 16:15:53 -05:00
|
|
|
}
|
2013-05-31 18:09:58 +01:00
|
|
|
|
|
|
|
|
static struct udev_seat *
|
2014-01-15 17:04:00 +10:00
|
|
|
udev_seat_create(struct udev_input *input,
|
|
|
|
|
const char *device_seat,
|
|
|
|
|
const char *seat_name)
|
2013-05-31 18:09:58 +01:00
|
|
|
{
|
|
|
|
|
struct udev_seat *seat;
|
|
|
|
|
|
2013-08-08 11:57:05 +10:00
|
|
|
seat = zalloc(sizeof *seat);
|
2013-05-31 18:09:58 +01:00
|
|
|
|
2014-01-15 17:04:00 +10:00
|
|
|
libinput_seat_init(&seat->base, &input->base,
|
|
|
|
|
device_seat, seat_name,
|
|
|
|
|
udev_seat_destroy);
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
|
2013-05-31 18:09:58 +01:00
|
|
|
return seat;
|
|
|
|
|
}
|
|
|
|
|
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
static struct udev_seat *
|
|
|
|
|
udev_seat_get_named(struct udev_input *input, const char *seat_name)
|
2013-06-25 18:56:40 +01:00
|
|
|
{
|
|
|
|
|
struct udev_seat *seat;
|
|
|
|
|
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
list_for_each(seat, &input->base.seat_list, base.link) {
|
2015-05-26 08:46:05 +10:00
|
|
|
if (streq(seat->base.logical_name, seat_name))
|
2013-06-25 18:56:40 +01:00
|
|
|
return seat;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-23 14:10:56 +10:00
|
|
|
return NULL;
|
2013-06-25 18:56:40 +01:00
|
|
|
}
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
|
2014-11-19 13:43:59 +10:00
|
|
|
static int
|
|
|
|
|
udev_device_change_seat(struct libinput_device *device,
|
|
|
|
|
const char *seat_name)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *libinput = device->seat->libinput;
|
|
|
|
|
struct udev_input *input = (struct udev_input *)libinput;
|
2017-01-30 19:48:33 +10:00
|
|
|
struct evdev_device *evdev = evdev_device(device);
|
|
|
|
|
struct udev_device *udev_device = evdev->udev_device;
|
2014-11-19 13:43:59 +10:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
udev_device_ref(udev_device);
|
|
|
|
|
device_removed(udev_device, input);
|
|
|
|
|
rc = device_added(udev_device, input, seat_name);
|
|
|
|
|
udev_device_unref(udev_device);
|
|
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 11:37:31 +10:00
|
|
|
static const struct libinput_interface_backend interface_backend = {
|
|
|
|
|
.resume = udev_input_enable,
|
|
|
|
|
.suspend = udev_input_disable,
|
|
|
|
|
.destroy = udev_input_destroy,
|
2014-11-19 13:43:59 +10:00
|
|
|
.device_change_seat = udev_device_change_seat,
|
2013-12-13 11:37:31 +10:00
|
|
|
};
|
|
|
|
|
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
LIBINPUT_EXPORT struct libinput *
|
2014-06-12 11:44:31 +10:00
|
|
|
libinput_udev_create_context(const struct libinput_interface *interface,
|
|
|
|
|
void *user_data,
|
|
|
|
|
struct udev *udev)
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
{
|
|
|
|
|
struct udev_input *input;
|
|
|
|
|
|
2014-06-12 11:44:31 +10:00
|
|
|
if (!interface || !udev)
|
2013-12-09 16:34:49 +10:00
|
|
|
return NULL;
|
|
|
|
|
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
input = zalloc(sizeof *input);
|
|
|
|
|
|
2013-12-13 11:37:31 +10:00
|
|
|
if (libinput_init(&input->base, interface,
|
|
|
|
|
&interface_backend, user_data) != 0) {
|
2014-06-25 10:32:42 +10:00
|
|
|
libinput_unref(&input->base);
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
free(input);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
input->udev = udev_ref(udev);
|
2014-06-12 11:44:31 +10:00
|
|
|
|
|
|
|
|
return &input->base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT int
|
|
|
|
|
libinput_udev_assign_seat(struct libinput *libinput,
|
|
|
|
|
const char *seat_id)
|
|
|
|
|
{
|
|
|
|
|
struct udev_input *input = (struct udev_input*)libinput;
|
|
|
|
|
|
2019-02-08 11:07:15 +10:00
|
|
|
if (!seat_id)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if (strlen(seat_id) > 256) {
|
|
|
|
|
log_bug_client(libinput,
|
|
|
|
|
"Unexpected seat id, limited to 256 characters.\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-24 11:46:31 +10:00
|
|
|
/* We cannot do this during udev_create_context because the log
|
|
|
|
|
* handler isn't set up there but we really want to log to the right
|
|
|
|
|
* place if the quirks run into parser errors. So we have to do it
|
|
|
|
|
* here since we can expect the log handler to be set up by now.
|
|
|
|
|
*/
|
|
|
|
|
libinput_init_quirks(libinput);
|
|
|
|
|
|
2014-06-12 11:44:31 +10:00
|
|
|
if (libinput->interface_backend != &interface_backend) {
|
2014-06-18 19:51:19 +10:00
|
|
|
log_bug_client(libinput, "Mismatching backends.\n");
|
2014-06-12 11:44:31 +10:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-13 11:48:49 +10:00
|
|
|
if (input->seat_id != NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
2017-07-07 09:47:06 +10:00
|
|
|
input->seat_id = safe_strdup(seat_id);
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
|
2014-06-12 11:44:31 +10:00
|
|
|
if (udev_input_enable(&input->base) < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|