mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-06 12:38:06 +02:00
udev-seat: Separate the seat out to its own structure
Thie will allow us to instantiate multiple seats.
This commit is contained in:
parent
8065462d6d
commit
07b0da9c77
2 changed files with 68 additions and 26 deletions
|
|
@ -32,6 +32,11 @@
|
||||||
|
|
||||||
static const char default_seat[] = "seat0";
|
static const char default_seat[] = "seat0";
|
||||||
|
|
||||||
|
static struct udev_seat *
|
||||||
|
udev_seat_create(struct weston_compositor *c);
|
||||||
|
static void
|
||||||
|
udev_seat_destroy(struct udev_seat *seat);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
device_added(struct udev_device *udev_device, struct udev_input *input)
|
device_added(struct udev_device *udev_device, struct udev_input *input)
|
||||||
{
|
{
|
||||||
|
|
@ -41,6 +46,7 @@ device_added(struct udev_device *udev_device, struct udev_input *input)
|
||||||
const char *device_seat;
|
const char *device_seat;
|
||||||
const char *calibration_values;
|
const char *calibration_values;
|
||||||
int fd;
|
int fd;
|
||||||
|
struct udev_seat *seat;
|
||||||
|
|
||||||
device_seat = udev_device_get_property_value(udev_device, "ID_SEAT");
|
device_seat = udev_device_get_property_value(udev_device, "ID_SEAT");
|
||||||
if (!device_seat)
|
if (!device_seat)
|
||||||
|
|
@ -49,9 +55,18 @@ device_added(struct udev_device *udev_device, struct udev_input *input)
|
||||||
if (strcmp(device_seat, input->seat_id))
|
if (strcmp(device_seat, input->seat_id))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
c = input->base.compositor;
|
c = input->compositor;
|
||||||
devnode = udev_device_get_devnode(udev_device);
|
devnode = udev_device_get_devnode(udev_device);
|
||||||
|
|
||||||
|
/* Single default seat for now */
|
||||||
|
if (!input->seat)
|
||||||
|
input->seat = udev_seat_create(c);
|
||||||
|
|
||||||
|
if (!input->seat)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
seat = input->seat;
|
||||||
|
|
||||||
/* Use non-blocking mode so that we can loop on read on
|
/* Use non-blocking mode so that we can loop on read on
|
||||||
* evdev_device_data() until all events on the fd are
|
* evdev_device_data() until all events on the fd are
|
||||||
* read. mtdev_get() also expects this. */
|
* read. mtdev_get() also expects this. */
|
||||||
|
|
@ -61,7 +76,7 @@ device_added(struct udev_device *udev_device, struct udev_input *input)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
device = evdev_device_create(&input->base, devnode, fd);
|
device = evdev_device_create(&seat->base, devnode, fd);
|
||||||
if (device == EVDEV_UNHANDLED_DEVICE) {
|
if (device == EVDEV_UNHANDLED_DEVICE) {
|
||||||
close(fd);
|
close(fd);
|
||||||
weston_log("not using input device '%s'.\n", devnode);
|
weston_log("not using input device '%s'.\n", devnode);
|
||||||
|
|
@ -94,7 +109,7 @@ device_added(struct udev_device *udev_device, struct udev_input *input)
|
||||||
device->abs.calibration[5]);
|
device->abs.calibration[5]);
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_list_insert(input->devices_list.prev, &device->link);
|
wl_list_insert(seat->devices_list.prev, &device->link);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -130,9 +145,9 @@ udev_input_add_devices(struct udev_input *input, struct udev *udev)
|
||||||
}
|
}
|
||||||
udev_enumerate_unref(e);
|
udev_enumerate_unref(e);
|
||||||
|
|
||||||
evdev_notify_keyboard_focus(&input->base, &input->devices_list);
|
evdev_notify_keyboard_focus(&input->seat->base, &input->seat->devices_list);
|
||||||
|
|
||||||
if (wl_list_empty(&input->devices_list)) {
|
if (wl_list_empty(&input->seat->devices_list)) {
|
||||||
weston_log(
|
weston_log(
|
||||||
"warning: no input devices on entering Weston. "
|
"warning: no input devices on entering Weston. "
|
||||||
"Possible causes:\n"
|
"Possible causes:\n"
|
||||||
|
|
@ -171,7 +186,7 @@ evdev_udev_handler(int fd, uint32_t mask, void *data)
|
||||||
}
|
}
|
||||||
else if (!strcmp(action, "remove")) {
|
else if (!strcmp(action, "remove")) {
|
||||||
devnode = udev_device_get_devnode(udev_device);
|
devnode = udev_device_get_devnode(udev_device);
|
||||||
wl_list_for_each_safe(device, next, &input->devices_list, link)
|
wl_list_for_each_safe(device, next, &input->seat->devices_list, link)
|
||||||
if (!strcmp(device->devnode, devnode)) {
|
if (!strcmp(device->devnode, devnode)) {
|
||||||
weston_log("input device %s, %s removed\n",
|
weston_log("input device %s, %s removed\n",
|
||||||
device->devname, device->devnode);
|
device->devname, device->devnode);
|
||||||
|
|
@ -190,7 +205,7 @@ int
|
||||||
udev_input_enable(struct udev_input *input, struct udev *udev)
|
udev_input_enable(struct udev_input *input, struct udev *udev)
|
||||||
{
|
{
|
||||||
struct wl_event_loop *loop;
|
struct wl_event_loop *loop;
|
||||||
struct weston_compositor *c = input->base.compositor;
|
struct weston_compositor *c = input->compositor;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
input->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
|
input->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
|
||||||
|
|
@ -229,11 +244,11 @@ udev_input_remove_devices(struct udev_input *input)
|
||||||
{
|
{
|
||||||
struct evdev_device *device, *next;
|
struct evdev_device *device, *next;
|
||||||
|
|
||||||
wl_list_for_each_safe(device, next, &input->devices_list, link)
|
wl_list_for_each_safe(device, next, &input->seat->devices_list, link)
|
||||||
evdev_device_destroy(device);
|
evdev_device_destroy(device);
|
||||||
|
|
||||||
if (input->base.keyboard)
|
if (input->seat->base.keyboard)
|
||||||
notify_keyboard_focus_out(&input->base);
|
notify_keyboard_focus_out(&input->seat->base);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -250,26 +265,14 @@ udev_input_disable(struct udev_input *input)
|
||||||
udev_input_remove_devices(input);
|
udev_input_remove_devices(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
drm_led_update(struct weston_seat *seat_base, enum weston_led leds)
|
|
||||||
{
|
|
||||||
struct udev_input *seat = (struct udev_input *) seat_base;
|
|
||||||
struct evdev_device *device;
|
|
||||||
|
|
||||||
wl_list_for_each(device, &seat->devices_list, link)
|
|
||||||
evdev_led_update(device, leds);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
udev_input_init(struct udev_input *input, struct weston_compositor *c, struct udev *udev,
|
udev_input_init(struct udev_input *input, struct weston_compositor *c, struct udev *udev,
|
||||||
const char *seat_id)
|
const char *seat_id)
|
||||||
{
|
{
|
||||||
memset(input, 0, sizeof *input);
|
memset(input, 0, sizeof *input);
|
||||||
weston_seat_init(&input->base, c, "default");
|
|
||||||
input->base.led_update = drm_led_update;
|
|
||||||
|
|
||||||
wl_list_init(&input->devices_list);
|
|
||||||
input->seat_id = strdup(seat_id);
|
input->seat_id = strdup(seat_id);
|
||||||
|
input->compositor = c;
|
||||||
if (udev_input_enable(input, udev) < 0)
|
if (udev_input_enable(input, udev) < 0)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
|
@ -284,7 +287,40 @@ void
|
||||||
udev_input_destroy(struct udev_input *input)
|
udev_input_destroy(struct udev_input *input)
|
||||||
{
|
{
|
||||||
udev_input_disable(input);
|
udev_input_disable(input);
|
||||||
|
udev_seat_destroy(input->seat);
|
||||||
weston_seat_release(&input->base);
|
|
||||||
free(input->seat_id);
|
free(input->seat_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
drm_led_update(struct weston_seat *seat_base, enum weston_led leds)
|
||||||
|
{
|
||||||
|
struct udev_seat *seat = (struct udev_seat *) seat_base;
|
||||||
|
struct evdev_device *device;
|
||||||
|
|
||||||
|
wl_list_for_each(device, &seat->devices_list, link)
|
||||||
|
evdev_led_update(device, leds);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct udev_seat *
|
||||||
|
udev_seat_create(struct weston_compositor *c)
|
||||||
|
{
|
||||||
|
struct udev_seat *seat;
|
||||||
|
|
||||||
|
seat = malloc(sizeof *seat);
|
||||||
|
|
||||||
|
if (!seat)
|
||||||
|
return NULL;
|
||||||
|
memset(seat, 0, sizeof *seat);
|
||||||
|
weston_seat_init(&seat->base, c, "default");
|
||||||
|
seat->base.led_update = drm_led_update;
|
||||||
|
|
||||||
|
wl_list_init(&seat->devices_list);
|
||||||
|
return seat;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
udev_seat_destroy(struct udev_seat *seat)
|
||||||
|
{
|
||||||
|
weston_seat_release(&seat->base);
|
||||||
|
free(seat);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,20 @@
|
||||||
|
|
||||||
#include "compositor.h"
|
#include "compositor.h"
|
||||||
|
|
||||||
struct udev_input {
|
struct udev_seat {
|
||||||
struct weston_seat base;
|
struct weston_seat base;
|
||||||
struct wl_list devices_list;
|
struct wl_list devices_list;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct udev_input {
|
||||||
struct udev_monitor *udev_monitor;
|
struct udev_monitor *udev_monitor;
|
||||||
struct wl_event_source *udev_monitor_source;
|
struct wl_event_source *udev_monitor_source;
|
||||||
char *seat_id;
|
char *seat_id;
|
||||||
|
struct weston_compositor *compositor;
|
||||||
|
struct udev_seat *seat;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int udev_input_enable(struct udev_input *input, struct udev *udev);
|
int udev_input_enable(struct udev_input *input, struct udev *udev);
|
||||||
void udev_input_disable(struct udev_input *input);
|
void udev_input_disable(struct udev_input *input);
|
||||||
int udev_input_init(struct udev_input *input,
|
int udev_input_init(struct udev_input *input,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue