So we don't unnecessarily advertise interfaces the seat doesn't support.

Signed-off-by: Daniel Stone <[email protected]>
---
 src/compositor-wayland.c |    2 ++
 src/compositor-x11.c     |    2 ++
 src/compositor.c         |   40 +++++++++++++++++++++++++++++++++++++---
 src/compositor.h         |   10 ++++++++++
 src/evdev.c              |    8 ++++++++
 5 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index 4f763ff..c6d9890 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -639,6 +639,7 @@ input_handle_capabilities(void *data, struct wl_seat *seat,
                wl_pointer_set_user_data(input->pointer, input);
                wl_pointer_add_listener(input->pointer, &pointer_listener,
                                        input);
+               weston_seat_init_pointer((struct weston_seat *) seat);
        } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
                wl_pointer_destroy(input->pointer);
                input->pointer = NULL;
@@ -649,6 +650,7 @@ input_handle_capabilities(void *data, struct wl_seat *seat,
                wl_keyboard_set_user_data(input->keyboard, input);
                wl_keyboard_add_listener(input->keyboard, &keyboard_listener,
                                         input);
+               weston_seat_init_keyboard((struct weston_seat *) seat);
        } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) {
                wl_keyboard_destroy(input->keyboard);
                input->keyboard = NULL;
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index c69f292..ac914be 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -98,6 +98,8 @@ x11_input_create(struct x11_compositor *c)
 
        memset(input, 0, sizeof *input);
        weston_seat_init(&input->base, &c->base);
+       weston_seat_init_pointer(&input->base);
+       weston_seat_init_keyboard(&input->base);
 
        c->base.seat = &input->base;
 
diff --git a/src/compositor.c b/src/compositor.c
index 545a207..0a2f71d 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -2281,16 +2281,49 @@ static void weston_compositor_xkb_destroy(struct 
weston_compositor *ec)
 }
 
 WL_EXPORT void
-weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec)
+weston_seat_init_pointer(struct weston_seat *seat)
 {
-       wl_seat_init(&seat->seat);
+       if (seat->has_pointer)
+               return;
+
        wl_pointer_init(&seat->pointer);
        wl_seat_set_pointer(&seat->seat, &seat->pointer);
+
+       seat->has_pointer = 1;
+}
+
+WL_EXPORT void
+weston_seat_init_keyboard(struct weston_seat *seat)
+{
+       if (seat->has_keyboard)
+               return;
+
        wl_keyboard_init(&seat->keyboard);
        wl_seat_set_keyboard(&seat->seat, &seat->keyboard);
+
+       seat->has_keyboard = 1;
+}
+
+WL_EXPORT void
+weston_seat_init_touch(struct weston_seat *seat)
+{
+       if (seat->has_touch)
+               return;
+
        wl_touch_init(&seat->touch);
        wl_seat_set_touch(&seat->seat, &seat->touch);
 
+       seat->has_touch = 1;
+}
+
+WL_EXPORT void
+weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec)
+{
+       wl_seat_init(&seat->seat);
+       seat->has_pointer = 0;
+       seat->has_keyboard = 0;
+       seat->has_touch = 0;
+
        wl_display_add_global(ec->wl_display, &wl_seat_interface, seat,
                              bind_seat);
 
@@ -2336,7 +2369,8 @@ weston_seat_release(struct weston_seat *seat)
        if (seat->sprite)
                destroy_surface(&seat->sprite->surface.resource);
 
-       xkb_state_unref(seat->xkb_state.state);
+       if (seat->xkb_state.state != NULL)
+               xkb_state_unref(seat->xkb_state.state);
 
        wl_seat_release(&seat->seat);
 }
diff --git a/src/compositor.h b/src/compositor.h
index 19df4c4..e2a172a 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -160,8 +160,12 @@ struct weston_output {
 struct weston_seat {
        struct wl_seat seat;
        struct wl_pointer pointer;
+       int has_pointer;
        struct wl_keyboard keyboard;
+       int has_keyboard;
        struct wl_touch touch;
+       int has_touch;
+
        struct weston_compositor *compositor;
        struct weston_surface *sprite;
        struct weston_surface *drag_surface;
@@ -628,6 +632,12 @@ weston_output_destroy(struct weston_output *output);
 
 void
 weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec);
+void
+weston_seat_init_pointer(struct weston_seat *seat);
+void
+weston_seat_init_keyboard(struct weston_seat *seat);
+void
+weston_seat_init_touch(struct weston_seat *seat);
 
 void
 weston_seat_release(struct weston_seat *seat);
diff --git a/src/evdev.c b/src/evdev.c
index a9c132c..23faaa6 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -440,6 +440,14 @@ evdev_configure_device(struct evdev_input_device *device)
        if (has_abs && !has_key)
                return -1;
 
+       if ((device->caps &
+            (EVDEV_MOTION_ABS | EVDEV_MOTION_REL | EVDEV_BUTTON)))
+               weston_seat_init_pointer(&device->master->base);
+       if ((device->caps & EVDEV_KEYBOARD))
+               weston_seat_init_keyboard(&device->master->base);
+       if ((device->caps & EVDEV_TOUCH))
+               weston_seat_init_touch(&device->master->base);
+
        return 0;
 }
 
-- 
1.7.10

_______________________________________________
wayland-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to