diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2014-06-12 11:44:31 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2014-06-23 15:39:08 +1000 |
commit | 6250397ac8a7a23fb41c726b9555d93ead0f1dc8 (patch) | |
tree | be028c08adbcd424b3a9fad8d8bea5b072ba4522 /src/udev-seat.c | |
parent | 3f500b657f5e9f90ade90a6f2678d8596cd6b799 (diff) |
udev: split libinput_udev context init into two functions
This is preparation work for context-specific log handlers.
Callers are now encouraged to first initialize the context with
libinput_udev_create_context() and then set the seat for this context with
libinput_udev_assign_seat().
In the upcoming patch to support context-specific log handlers this enables a
caller to set the log handler for a context before any devices are
initialized. Otherwise, a log message generated by a new device may pass a
libinput context that the caller is not yet aware of.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'src/udev-seat.c')
-rw-r--r-- | src/udev-seat.c | 58 |
1 files changed, 48 insertions, 10 deletions
diff --git a/src/udev-seat.c b/src/udev-seat.c index 38a13b72..89160ff8 100644 --- a/src/udev-seat.c +++ b/src/udev-seat.c @@ -333,14 +333,13 @@ static const struct libinput_interface_backend interface_backend = { }; LIBINPUT_EXPORT struct libinput * -libinput_udev_create_for_seat(const struct libinput_interface *interface, - void *user_data, - struct udev *udev, - const char *seat_id) +libinput_udev_create_context(const struct libinput_interface *interface, + void *user_data, + struct udev *udev) { struct udev_input *input; - if (!interface || !udev || !seat_id) + if (!interface || !udev) return NULL; input = zalloc(sizeof *input); @@ -354,14 +353,53 @@ libinput_udev_create_for_seat(const struct libinput_interface *interface, } input->udev = udev_ref(udev); + + 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; + + if (!seat_id) + return -1; + if (input->seat_id != NULL) + return -1; + + if (libinput->interface_backend != &interface_backend) { + log_bug_client("Mismatching backends.\n"); + return -1; + } + input->seat_id = strdup(seat_id); - if (udev_input_enable(&input->base) < 0) { - udev_unref(udev); - libinput_destroy(&input->base); - free(input); + if (udev_input_enable(&input->base) < 0) + return -1; + + return 0; +} + +LIBINPUT_EXPORT struct libinput * +libinput_udev_create_for_seat(const struct libinput_interface *interface, + void *user_data, + struct udev *udev, + const char *seat_id) +{ + struct libinput *libinput; + + if (!interface || !udev || !seat_id) return NULL; + + libinput = libinput_udev_create_context(interface, user_data, udev); + if (!libinput) + return NULL; + + if (libinput_udev_assign_seat(libinput, seat_id) != 0) { + libinput_destroy(libinput); + libinput = NULL; } - return &input->base; + return libinput; } |