From 1d697d7adfa9822dbdd34e93f5f09a300e093a68 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 25 Jun 2013 18:56:40 +0100 Subject: [PATCH] udev-seat: Refactor out seat lookup and possible creation This change spills the code for looking up a seat by name and then potentially creating it if it doesn't exist into a new function called udev_seat_get_named. This change allows us to reuse this code when looking up the seat when parsing seat constraints per output. --- src/udev-seat.c | 29 ++++++++++++++++++++--------- src/udev-seat.h | 2 ++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/udev-seat.c b/src/udev-seat.c index a8790b3f..bd255351 100644 --- a/src/udev-seat.c +++ b/src/udev-seat.c @@ -66,18 +66,11 @@ device_added(struct udev_device *udev_device, struct udev_input *input) if (!seat_name) seat_name = default_seat_name; - 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_get_named(c, seat_name); - seat = udev_seat_create(c, seat_name); - - if (!seat) + if (seat == NULL) return -1; -seat_found: - /* Use non-blocking mode so that we can loop on read on * evdev_device_data() until all events on the fd are * read. mtdev_get() also expects this. */ @@ -350,3 +343,21 @@ udev_seat_destroy(struct udev_seat *seat) weston_seat_release(&seat->base); free(seat); } + +struct udev_seat * +udev_seat_get_named(struct weston_compositor *c, const char *seat_name) +{ + struct udev_seat *seat; + + wl_list_for_each(seat, &c->seat_list, base.link) { + if (strcmp(seat->base.seat_name, seat_name) == 0) + return seat; + } + + seat = udev_seat_create(c, seat_name); + + if (!seat) + return NULL; + + return seat; +} diff --git a/src/udev-seat.h b/src/udev-seat.h index 7dd5987d..3543e7c3 100644 --- a/src/udev-seat.h +++ b/src/udev-seat.h @@ -48,4 +48,6 @@ int udev_input_init(struct udev_input *input, const char *seat_id); void udev_input_destroy(struct udev_input *input); +struct udev_seat *udev_seat_get_named(struct weston_compositor *c, + const char *seat_name); #endif