[PATCH weston 10/10] udev-seat: Use udev rules to support multiple seats
Rob Bradford
robert.bradford at intel.com
Fri May 31 10:09:59 PDT 2013
From: Rob Bradford <rob at linux.intel.com>
By labelling devices with ENV{WL_SEAT} in udev rules the devices will be
pulled into multiple weston seats.
As a result you can get multiple independent seats under the DRM and
fbdev backends.
---
src/udev-seat.c | 66 +++++++++++++++++++++++++++++++++++++++------------------
src/udev-seat.h | 1 -
2 files changed, 45 insertions(+), 22 deletions(-)
diff --git a/src/udev-seat.c b/src/udev-seat.c
index 5c289c4..e5156bd 100644
--- a/src/udev-seat.c
+++ b/src/udev-seat.c
@@ -31,9 +31,10 @@
#include "udev-seat.h"
static const char default_seat[] = "seat0";
+static const char default_seat_name[] = "default";
static struct udev_seat *
-udev_seat_create(struct weston_compositor *c);
+udev_seat_create(struct weston_compositor *c, const char *seat_name);
static void
udev_seat_destroy(struct udev_seat *seat);
@@ -43,7 +44,7 @@ device_added(struct udev_device *udev_device, struct udev_input *input)
struct weston_compositor *c;
struct evdev_device *device;
const char *devnode;
- const char *device_seat;
+ const char *device_seat, *seat_name;
const char *calibration_values;
int fd;
struct udev_seat *seat;
@@ -58,14 +59,22 @@ device_added(struct udev_device *udev_device, struct udev_input *input)
c = input->compositor;
devnode = udev_device_get_devnode(udev_device);
- /* Single default seat for now */
- if (!input->seat)
- input->seat = udev_seat_create(c);
+ /* Search for matching logical seat */
+ seat_name = udev_device_get_property_value(udev_device, "WL_SEAT");
+ if (!seat_name)
+ seat_name = default_seat_name;
- if (!input->seat)
+ wl_list_for_each(seat, &c->seat_list, base.link) {
+ if (strcmp(seat->base.seat_name, seat_name) == 0)
+ goto seat_found;
+ }
+
+ seat = udev_seat_create(c, seat_name);
+
+ if (!seat)
return -1;
- seat = input->seat;
+seat_found:
/* Use non-blocking mode so that we can loop on read on
* evdev_device_data() until all events on the fd are
@@ -121,6 +130,8 @@ udev_input_add_devices(struct udev_input *input, struct udev *udev)
struct udev_list_entry *entry;
struct udev_device *device;
const char *path, *sysname;
+ struct udev_seat *seat;
+ int devices_found = 0;
e = udev_enumerate_new(udev);
udev_enumerate_add_match_subsystem(e, "input");
@@ -145,9 +156,14 @@ udev_input_add_devices(struct udev_input *input, struct udev *udev)
}
udev_enumerate_unref(e);
- evdev_notify_keyboard_focus(&input->seat->base, &input->seat->devices_list);
+ wl_list_for_each(seat, &input->compositor->seat_list, base.link) {
+ evdev_notify_keyboard_focus(&seat->base, &seat->devices_list);
- if (wl_list_empty(&input->seat->devices_list)) {
+ if (!wl_list_empty(&seat->devices_list))
+ devices_found = 1;
+ }
+
+ if (devices_found == 0) {
weston_log(
"warning: no input devices on entering Weston. "
"Possible causes:\n"
@@ -168,6 +184,7 @@ evdev_udev_handler(int fd, uint32_t mask, void *data)
struct evdev_device *device, *next;
const char *action;
const char *devnode;
+ struct udev_seat *seat;
udev_device = udev_monitor_receive_device(input->udev_monitor);
if (!udev_device)
@@ -185,13 +202,15 @@ evdev_udev_handler(int fd, uint32_t mask, void *data)
}
else if (!strcmp(action, "remove")) {
devnode = udev_device_get_devnode(udev_device);
- wl_list_for_each_safe(device, next, &input->seat->devices_list, link)
- if (!strcmp(device->devnode, devnode)) {
- weston_log("input device %s, %s removed\n",
- device->devname, device->devnode);
- evdev_device_destroy(device);
+ wl_list_for_each(seat, &input->compositor->seat_list, base.link) {
+ wl_list_for_each_safe(device, next, &seat->devices_list, link)
+ if (!strcmp(device->devnode, devnode)) {
+ weston_log("input device %s, %s removed\n",
+ device->devname, device->devnode);
+ evdev_device_destroy(device);
break;
}
+ }
}
out:
@@ -242,12 +261,15 @@ static void
udev_input_remove_devices(struct udev_input *input)
{
struct evdev_device *device, *next;
+ struct udev_seat *seat;
- wl_list_for_each_safe(device, next, &input->seat->devices_list, link)
- evdev_device_destroy(device);
+ wl_list_for_each(seat, &input->compositor->seat_list, base.link) {
+ wl_list_for_each_safe(device, next, &seat->devices_list, link)
+ evdev_device_destroy(device);
- if (input->seat->base.keyboard)
- notify_keyboard_focus_out(&input->seat->base);
+ if (seat->base.keyboard)
+ notify_keyboard_focus_out(&seat->base);
+ }
}
void
@@ -285,8 +307,10 @@ udev_input_init(struct udev_input *input, struct weston_compositor *c, struct ud
void
udev_input_destroy(struct udev_input *input)
{
+ struct udev_seat *seat, *next;
udev_input_disable(input);
- udev_seat_destroy(input->seat);
+ wl_list_for_each_safe(seat, next, &input->compositor->seat_list, base.link)
+ udev_seat_destroy(seat);
free(input->seat_id);
}
@@ -301,7 +325,7 @@ drm_led_update(struct weston_seat *seat_base, enum weston_led leds)
}
static struct udev_seat *
-udev_seat_create(struct weston_compositor *c)
+udev_seat_create(struct weston_compositor *c, const char *seat_name)
{
struct udev_seat *seat;
@@ -310,7 +334,7 @@ udev_seat_create(struct weston_compositor *c)
if (!seat)
return NULL;
memset(seat, 0, sizeof *seat);
- weston_seat_init(&seat->base, c, "default");
+ weston_seat_init(&seat->base, c, seat_name);
seat->base.led_update = drm_led_update;
wl_list_init(&seat->devices_list);
diff --git a/src/udev-seat.h b/src/udev-seat.h
index 60aef68..7dd5987 100644
--- a/src/udev-seat.h
+++ b/src/udev-seat.h
@@ -37,7 +37,6 @@ struct udev_input {
struct wl_event_source *udev_monitor_source;
char *seat_id;
struct weston_compositor *compositor;
- struct udev_seat *seat;
};
--
1.8.1.4
More information about the wayland-devel
mailing list