<div dir="ltr">I was wondering why you didn't move the pointer / keyboard fields to the seat, before noticing that they were unused. It might make sense to have a prereq patch that removes those unused fields.<br><br>This patch looks good, though.<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 7, 2014 at 4:57 AM, Ander Conselvan de Oliveira <span dir="ltr"><<a href="mailto:conselvan2@gmail.com" target="_blank">conselvan2@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Ander Conselvan de Oliveira <<a href="mailto:ander.conselvan.de.oliveira@intel.com">ander.conselvan.de.oliveira@intel.com</a>><br>
<br>
If simple-touch ran on a compositor with multiple seats, and the first<br>
one happened to have the touch capability while the second one didn't,<br>
the handler for seat capabilities would destroy the wl_touch device it<br>
created on the first call for the first seat when it was called a again<br>
for the second seat that has not touch capabilities.<br>
<br>
Fix this problem by creating a separate struct for each seat.<br>
<br>
<a href="https://bugs.freedesktop.org/show_bug.cgi?id=78365" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=78365</a><br>
---<br>
clients/simple-touch.c | 48 +++++++++++++++++++++++++++++++++---------------<br>
1 file changed, 33 insertions(+), 15 deletions(-)<br>
<br>
diff --git a/clients/simple-touch.c b/clients/simple-touch.c<br>
index b5a84d7..d8439ac 100644<br>
--- a/clients/simple-touch.c<br>
+++ b/clients/simple-touch.c<br>
@@ -36,14 +36,18 @@<br>
<br>
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])<br>
<br>
+struct seat {<br>
+ struct touch *touch;<br>
+ struct wl_seat *seat;<br>
+ struct wl_touch *wl_touch;<br>
+};<br>
+<br>
struct touch {<br>
struct wl_display *display;<br>
struct wl_registry *registry;<br>
struct wl_compositor *compositor;<br>
struct wl_shell *shell;<br>
struct wl_shm *shm;<br>
- struct wl_seat *seat;<br>
- struct wl_touch *wl_touch;<br>
struct wl_pointer *pointer;<br>
struct wl_keyboard *keyboard;<br>
struct wl_surface *surface;<br>
@@ -199,18 +203,19 @@ static const struct wl_touch_listener touch_listener = {<br>
};<br>
<br>
static void<br>
-seat_handle_capabilities(void *data, struct wl_seat *seat,<br>
+seat_handle_capabilities(void *data, struct wl_seat *wl_seat,<br>
enum wl_seat_capability caps)<br>
{<br>
- struct touch *touch = data;<br>
-<br>
- if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !touch->wl_touch) {<br>
- touch->wl_touch = wl_seat_get_touch(seat);<br>
- wl_touch_set_user_data(touch->wl_touch, touch);<br>
- wl_touch_add_listener(touch->wl_touch, &touch_listener, touch);<br>
- } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && touch->wl_touch) {<br>
- wl_touch_destroy(touch->wl_touch);<br>
- touch->wl_touch = NULL;<br>
+ struct seat *seat = data;<br>
+ struct touch *touch = seat->touch;<br>
+<br>
+ if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !seat->wl_touch) {<br>
+ seat->wl_touch = wl_seat_get_touch(wl_seat);<br>
+ wl_touch_set_user_data(seat->wl_touch, touch);<br>
+ wl_touch_add_listener(seat->wl_touch, &touch_listener, touch);<br>
+ } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && seat->wl_touch) {<br>
+ wl_touch_destroy(seat->wl_touch);<br>
+ seat->wl_touch = NULL;<br>
}<br>
}<br>
<br>
@@ -219,6 +224,21 @@ static const struct wl_seat_listener seat_listener = {<br>
};<br>
<br>
static void<br>
+add_seat(struct touch *touch, uint32_t name, uint32_t version)<br>
+{<br>
+ struct seat *seat;<br>
+<br>
+ seat = malloc(sizeof *seat);<br>
+ assert(seat);<br>
+<br>
+ seat->touch = touch;<br>
+ seat->wl_touch = NULL;<br>
+ seat->seat = wl_registry_bind(touch->registry, name,<br>
+ &wl_seat_interface, 1);<br>
+ wl_seat_add_listener(seat->seat, &seat_listener, seat);<br>
+}<br>
+<br>
+static void<br>
handle_ping(void *data, struct wl_shell_surface *shell_surface,<br>
uint32_t serial)<br>
{<br>
@@ -261,9 +281,7 @@ handle_global(void *data, struct wl_registry *registry,<br>
&wl_shm_interface, 1);<br>
wl_shm_add_listener(touch->shm, &shm_listener, touch);<br>
} else if (strcmp(interface, "wl_seat") == 0) {<br>
- touch->seat = wl_registry_bind(registry, name,<br>
- &wl_seat_interface, 1);<br>
- wl_seat_add_listener(touch->seat, &seat_listener, touch);<br>
+ add_seat(touch, name, version);<br>
}<br>
}<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
1.8.3.2<br>
<br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br> Jasper<br>
</div>