From d355b8017201a964ce47f7678e208278bf342ceb Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Fri, 31 May 2013 18:09:55 +0100 Subject: [PATCH] udev-seat: Make the udev_input structure an embedded structure And as a result of this stop iterating through the compositor seat list (of one item) and instead access the udev_input structure directly. 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 add4fd0..beb6ba5 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 { @@ -2222,10 +2223,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); @@ -2282,7 +2281,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; @@ -2297,13 +2295,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; @@ -2431,7 +2427,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; @@ -2520,7 +2515,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; } @@ -2563,8 +2558,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 06117ae..34fcea0 100644 --- a/src/udev-seat.c +++ b/src/udev-seat.c @@ -260,16 +260,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; @@ -279,12 +273,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 @@ -294,5 +287,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 -- 2.7.4