2013-02-18 16:15:53 -05:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
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
|
2013-05-31 18:09:54 +01:00
|
|
|
device_added(struct udev_device *udev_device, struct udev_input *input)
|
2013-02-18 16:15:53 -05:00
|
|
|
{
|
|
|
|
|
struct evdev_device *device;
|
|
|
|
|
const char *devnode;
|
2013-12-15 17:50:04 +01:00
|
|
|
const char *sysname;
|
2013-07-22 15:11:11 -07:00
|
|
|
const char *device_seat, *seat_name, *output_name;
|
2013-02-18 16:15:53 -05:00
|
|
|
const char *calibration_values;
|
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;
|
|
|
|
|
|
2013-05-31 18:09:54 +01:00
|
|
|
if (strcmp(device_seat, input->seat_id))
|
2013-02-18 16:15:53 -05:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
devnode = udev_device_get_devnode(udev_device);
|
2013-12-15 17:50:04 +01: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 */
|
|
|
|
|
seat_name = udev_device_get_property_value(udev_device, "WL_SEAT");
|
|
|
|
|
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-01-30 14:54:31 +10:00
|
|
|
device = evdev_device_create(&seat->base, devnode, sysname);
|
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) {
|
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
|
|
|
log_info("not using input device '%s'.\n", devnode);
|
2014-01-22 23:48:39 +01:00
|
|
|
return 0;
|
2013-02-18 16:15:53 -05:00
|
|
|
} else if (device == 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
|
|
|
log_info("failed to create input device '%s'.\n", devnode);
|
2014-01-22 23:48:39 +01:00
|
|
|
return 0;
|
2013-02-18 16:15:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
calibration_values =
|
|
|
|
|
udev_device_get_property_value(udev_device,
|
|
|
|
|
"WL_CALIBRATION");
|
|
|
|
|
|
|
|
|
|
if (calibration_values && sscanf(calibration_values,
|
|
|
|
|
"%f %f %f %f %f %f",
|
|
|
|
|
&device->abs.calibration[0],
|
|
|
|
|
&device->abs.calibration[1],
|
|
|
|
|
&device->abs.calibration[2],
|
|
|
|
|
&device->abs.calibration[3],
|
|
|
|
|
&device->abs.calibration[4],
|
|
|
|
|
&device->abs.calibration[5]) == 6) {
|
|
|
|
|
device->abs.apply_calibration = 1;
|
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
|
|
|
log_info("Applying calibration: %f %f %f %f %f %f\n",
|
|
|
|
|
device->abs.calibration[0],
|
|
|
|
|
device->abs.calibration[1],
|
|
|
|
|
device->abs.calibration[2],
|
|
|
|
|
device->abs.calibration[3],
|
|
|
|
|
device->abs.calibration[4],
|
|
|
|
|
device->abs.calibration[5]);
|
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");
|
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
|
|
|
if (output_name)
|
|
|
|
|
device->output_name = strdup(output_name);
|
2013-10-17 23:04:08 +02:00
|
|
|
|
2013-02-18 16:15:53 -05:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
sysname = udev_device_get_sysname(device);
|
|
|
|
|
if (strncmp("event", sysname, 5) != 0) {
|
|
|
|
|
udev_device_unref(device);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-31 18:09:54 +01:00
|
|
|
if (device_added(device, input) < 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;
|
|
|
|
|
struct evdev_device *device, *next;
|
|
|
|
|
const char *action;
|
|
|
|
|
const char *devnode;
|
2013-05-31 18:09:59 +01:00
|
|
|
struct udev_seat *seat;
|
2013-02-18 16:15:53 -05:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
if (!strcmp(action, "add")) {
|
2013-05-31 18:09:54 +01:00
|
|
|
device_added(udev_device, input);
|
2013-02-18 16:15:53 -05:00
|
|
|
}
|
|
|
|
|
else if (!strcmp(action, "remove")) {
|
|
|
|
|
devnode = udev_device_get_devnode(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
|
|
|
list_for_each(seat, &input->base.seat_list, base.link) {
|
|
|
|
|
list_for_each_safe(device, next,
|
|
|
|
|
&seat->base.devices_list, base.link)
|
2013-05-31 18:09:59 +01:00
|
|
|
if (!strcmp(device->devnode, devnode)) {
|
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
|
|
|
log_info("input device %s, %s removed\n",
|
|
|
|
|
device->devname, device->devnode);
|
|
|
|
|
evdev_device_remove(device);
|
2013-10-22 00:28:08 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2013-05-31 18:09:59 +01:00
|
|
|
}
|
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;
|
|
|
|
|
|
2014-01-08 12:53:46 +10:00
|
|
|
if (input->udev_monitor)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2013-05-31 18:09:54 +01:00
|
|
|
input->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
|
|
|
|
|
if (!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
|
|
|
log_info("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)) {
|
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
|
|
|
log_info("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
|
|
|
if (!seat)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
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) {
|
2014-01-15 17:04:00 +10:00
|
|
|
if (strcmp(seat->base.logical_name, seat_name) == 0)
|
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
|
|
|
|
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,
|
|
|
|
|
};
|
|
|
|
|
|
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-01-29 15:35:20 +10:00
|
|
|
libinput_udev_create_for_seat(const struct libinput_interface *interface,
|
|
|
|
|
void *user_data,
|
|
|
|
|
struct udev *udev,
|
|
|
|
|
const char *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
|
|
|
{
|
|
|
|
|
struct udev_input *input;
|
|
|
|
|
|
2013-12-09 16:34:49 +10:00
|
|
|
if (!interface || !udev || !seat_id)
|
|
|
|
|
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);
|
|
|
|
|
if (!input)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2013-12-13 11:37:31 +10:00
|
|
|
if (libinput_init(&input->base, interface,
|
|
|
|
|
&interface_backend, user_data) != 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
|
|
|
free(input);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
input->udev = udev_ref(udev);
|
|
|
|
|
input->seat_id = strdup(seat_id);
|
|
|
|
|
|
2013-12-13 11:37:31 +10:00
|
|
|
if (udev_input_enable(&input->base) < 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
|
|
|
udev_unref(udev);
|
|
|
|
|
libinput_destroy(&input->base);
|
|
|
|
|
free(input);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &input->base;
|
|
|
|
|
}
|