[PATCH weston 06/10] udev-seat: Make the udev_input structure an embedded structure
Kristian Høgsberg
hoegsberg at gmail.com
Tue Jun 4 21:23:05 PDT 2013
On Fri, May 31, 2013 at 06:09:55PM +0100, Rob Bradford wrote:
> From: Rob Bradford <rob at linux.intel.com>
>
> And as a result of this stop iterating through the compositor seat list
> (of one item) and instead access the udev_input structure directly.
I think we should move udev_input to udev-seat.c eventually and just
malloc it.
Kristian
> This enables a refactoring to pull out the weston_seat into a separate
> structure permitting multiple seats.
> ---
> src/compositor-drm.c | 18 ++++++------------
> src/compositor-fbdev.c | 15 +++++----------
> src/udev-seat.c | 16 ++++------------
> src/udev-seat.h | 7 ++++---
> 4 files changed, 19 insertions(+), 37 deletions(-)
>
> diff --git a/src/compositor-drm.c b/src/compositor-drm.c
> index 1845978..79b6ce8 100644
> --- a/src/compositor-drm.c
> +++ b/src/compositor-drm.c
> @@ -107,6 +107,7 @@ struct drm_compositor {
> uint32_t prev_state;
>
> clockid_t clock;
> + struct udev_input input;
> };
>
> struct drm_mode {
> @@ -2228,10 +2229,8 @@ static void
> drm_destroy(struct weston_compositor *ec)
> {
> struct drm_compositor *d = (struct drm_compositor *) ec;
> - struct udev_input *input, *next;
>
> - wl_list_for_each_safe(input, next, &ec->seat_list, base.link)
> - udev_input_destroy(input);
> + udev_input_destroy(&d->input);
>
> wl_event_source_remove(d->udev_drm_source);
> wl_event_source_remove(d->drm_source);
> @@ -2288,7 +2287,6 @@ static void
> vt_func(struct weston_compositor *compositor, int event)
> {
> struct drm_compositor *ec = (struct drm_compositor *) compositor;
> - struct udev_input *input;
> struct drm_sprite *sprite;
> struct drm_output *output;
>
> @@ -2303,13 +2301,11 @@ vt_func(struct weston_compositor *compositor, int event)
> compositor->state = ec->prev_state;
> drm_compositor_set_modes(ec);
> weston_compositor_damage_all(compositor);
> - wl_list_for_each(input, &compositor->seat_list, base.link)
> - udev_input_enable(input, ec->udev);
> + udev_input_enable(&ec->input, ec->udev);
> break;
> case TTY_LEAVE_VT:
> weston_log("leaving VT\n");
> - wl_list_for_each(input, &compositor->seat_list, base.link)
> - udev_input_disable(input);
> + udev_input_disable(&ec->input);
>
> compositor->focus = 0;
> ec->prev_state = compositor->state;
> @@ -2437,7 +2433,6 @@ drm_compositor_create(struct wl_display *display,
> struct drm_compositor *ec;
> struct udev_device *drm_device;
> struct wl_event_loop *loop;
> - struct udev_input *udev_input, *next;
> const char *path;
> uint32_t key;
>
> @@ -2526,7 +2521,7 @@ drm_compositor_create(struct wl_display *display,
>
> path = NULL;
>
> - if (udev_input_create(&ec->base, ec->udev, seat_id) == NULL) {
> + if (udev_input_init(&ec->input, &ec->base, ec->udev, seat_id) < 0) {
> weston_log("failed to create input devices\n");
> goto err_sprite;
> }
> @@ -2569,8 +2564,7 @@ err_udev_monitor:
> udev_monitor_unref(ec->udev_monitor);
> err_drm_source:
> wl_event_source_remove(ec->drm_source);
> - wl_list_for_each_safe(udev_input, next, &ec->base.seat_list, base.link)
> - udev_input_destroy(udev_input);
> + udev_input_destroy(&ec->input);
> err_sprite:
> ec->base.renderer->destroy(&ec->base);
> gbm_device_destroy(ec->gbm);
> diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c
> index 43897da..605dcd8 100644
> --- a/src/compositor-fbdev.c
> +++ b/src/compositor-fbdev.c
> @@ -52,6 +52,7 @@ struct fbdev_compositor {
>
> struct udev *udev;
> struct tty *tty;
> + struct udev_input input;
> };
>
> struct fbdev_screeninfo {
> @@ -751,11 +752,8 @@ static void
> fbdev_compositor_destroy(struct weston_compositor *base)
> {
> struct fbdev_compositor *compositor = to_fbdev_compositor(base);
> - struct udev_input *input, *next;
>
> - /* Destroy all inputs. */
> - wl_list_for_each_safe(input, next, &compositor->base.seat_list, base.link)
> - udev_input_destroy(input);
> + udev_input_destroy(&compositor->input);
>
> /* Destroy the output. */
> weston_compositor_shutdown(&compositor->base);
> @@ -771,7 +769,6 @@ static void
> vt_func(struct weston_compositor *base, int event)
> {
> struct fbdev_compositor *compositor = to_fbdev_compositor(base);
> - struct udev_input *input;
> struct weston_output *output;
>
> switch (event) {
> @@ -786,13 +783,11 @@ vt_func(struct weston_compositor *base, int event)
>
> weston_compositor_damage_all(&compositor->base);
>
> - wl_list_for_each(input, &compositor->base.seat_list, base.link)
> - udev_input_enable(input, compositor->udev);
> + udev_input_enable(&compositor->input, compositor->udev);
> break;
> case TTY_LEAVE_VT:
> weston_log("leaving VT\n");
> - wl_list_for_each(input, &compositor->base.seat_list, base.link)
> - udev_input_disable(input);
> + udev_input_disable(&compositor->input);
>
> wl_list_for_each(output, &compositor->base.output_list, link) {
> fbdev_output_disable(output);
> @@ -884,7 +879,7 @@ fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[],
> if (fbdev_output_create(compositor, param->device) < 0)
> goto out_pixman;
>
> - udev_input_create(&compositor->base, compositor->udev, seat);
> + udev_input_init(&compositor->input, &compositor->base, compositor->udev, seat);
>
> return &compositor->base;
>
> diff --git a/src/udev-seat.c b/src/udev-seat.c
> index 8c30643..4091088 100644
> --- a/src/udev-seat.c
> +++ b/src/udev-seat.c
> @@ -259,16 +259,10 @@ drm_led_update(struct weston_seat *seat_base, enum weston_led leds)
> evdev_led_update(device, leds);
> }
>
> -struct udev_input *
> -udev_input_create(struct weston_compositor *c, struct udev *udev,
> +int
> +udev_input_init(struct udev_input *input, struct weston_compositor *c, struct udev *udev,
> const char *seat_id)
> {
> - struct udev_input *input;
> -
> - input = malloc(sizeof *input);
> - if (input == NULL)
> - return NULL;
> -
> memset(input, 0, sizeof *input);
> weston_seat_init(&input->base, c, "default");
> input->base.led_update = drm_led_update;
> @@ -278,12 +272,11 @@ udev_input_create(struct weston_compositor *c, struct udev *udev,
> if (udev_input_enable(input, udev) < 0)
> goto err;
>
> - return input;
> + return 0;
>
> err:
> free(input->seat_id);
> - free(input);
> - return NULL;
> + return -1;
> }
>
> void
> @@ -293,5 +286,4 @@ udev_input_destroy(struct udev_input *input)
>
> weston_seat_release(&input->base);
> free(input->seat_id);
> - free(input);
> }
> diff --git a/src/udev-seat.h b/src/udev-seat.h
> index dbc6269..e19a93d 100644
> --- a/src/udev-seat.h
> +++ b/src/udev-seat.h
> @@ -37,9 +37,10 @@ struct udev_input {
>
> int udev_input_enable(struct udev_input *input, struct udev *udev);
> void udev_input_disable(struct udev_input *input);
> -struct udev_input *udev_input_create(struct weston_compositor *c,
> - struct udev *udev,
> - const char *seat_id);
> +int udev_input_init(struct udev_input *input,
> + struct weston_compositor *c,
> + struct udev *udev,
> + const char *seat_id);
> void udev_input_destroy(struct udev_input *input);
>
> #endif
> --
> 1.8.1.4
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
More information about the wayland-devel
mailing list