<p dir="ltr">Yeah, this is a good idea.<br>
--Jason Ekstrand</p>
<p dir="ltr">Reviewed-By: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
</p>
<div class="gmail_quote">On Dec 6, 2013 5:48 AM, "Giulio Camuffo" <<a href="mailto:giuliocamuffo@gmail.com">giuliocamuffo@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The device may not have a resource for the client yet, but install<br>
the listeners nevertheless.<br>
Fixes <a href="https://bugs.freedesktop.org/show_bug.cgi?id=65726" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=65726</a><br>
---<br>
<br>
v2: add a check on the surface's resource<br>
<br>
 src/input.c | 26 ++++++++++++++------------<br>
 1 file changed, 14 insertions(+), 12 deletions(-)<br>
<br>
diff --git a/src/input.c b/src/input.c<br>
index e2910ea..f4944b6 100644<br>
--- a/src/input.c<br>
+++ b/src/input.c<br>
@@ -620,8 +620,6 @@ weston_pointer_set_focus(struct weston_pointer *pointer,<br>
                                              pointer->focus->surface->resource);<br>
                }<br>
<br>
-               wl_list_remove(&pointer->focus_resource_listener.link);<br>
-               wl_list_init(&pointer->focus_resource_listener.link);<br>
                move_resources(&pointer->resource_list, focus_resource_list);<br>
        }<br>
<br>
@@ -650,18 +648,20 @@ weston_pointer_set_focus(struct weston_pointer *pointer,<br>
                }<br>
<br>
                pointer->focus_serial = serial;<br>
+       }<br>
+<br>
+       wl_list_remove(&pointer->focus_view_listener.link);<br>
+       wl_list_init(&pointer->focus_view_listener.link);<br>
+       wl_list_remove(&pointer->focus_resource_listener.link);<br>
+       wl_list_init(&pointer->focus_resource_listener.link);<br>
+       if (view)<br>
+               wl_signal_add(&view->destroy_signal, &pointer->focus_view_listener);<br>
+       if (view && view->surface->resource)<br>
                wl_resource_add_destroy_listener(view->surface->resource,<br>
                                                 &pointer->focus_resource_listener);<br>
-       }<br>
<br>
-       if (!wl_list_empty(&pointer->focus_view_listener.link)) {<br>
-               wl_list_remove(&pointer->focus_view_listener.link);<br>
-               wl_list_init(&pointer->focus_view_listener.link);<br>
-       }<br>
        pointer->focus = view;<br>
        pointer->focus_view_listener.notify = pointer_focus_view_destroyed;<br>
-       if (view)<br>
-               wl_signal_add(&view->destroy_signal, &pointer->focus_view_listener);<br>
        wl_signal_emit(&pointer->focus_signal, pointer);<br>
 }<br>
<br>
@@ -698,8 +698,6 @@ weston_keyboard_set_focus(struct weston_keyboard *keyboard,<br>
                        wl_keyboard_send_leave(resource, serial,<br>
                                        keyboard->focus->resource);<br>
                }<br>
-               wl_list_remove(&keyboard->focus_resource_listener.link);<br>
-               wl_list_init(&keyboard->focus_resource_listener.link);<br>
                move_resources(&keyboard->resource_list, focus_resource_list);<br>
        }<br>
<br>
@@ -718,9 +716,13 @@ weston_keyboard_set_focus(struct weston_keyboard *keyboard,<br>
                                            surface,<br>
                                            serial);<br>
                keyboard->focus_serial = serial;<br>
+       }<br>
+<br>
+       wl_list_remove(&keyboard->focus_resource_listener.link);<br>
+       wl_list_init(&keyboard->focus_resource_listener.link);<br>
+       if (surface && surface->resource)<br>
                wl_resource_add_destroy_listener(surface->resource,<br>
                                                 &keyboard->focus_resource_listener);<br>
-       }<br>
<br>
        keyboard->focus = surface;<br>
        wl_signal_emit(&keyboard->focus_signal, keyboard);<br>
--<br>
1.8.4.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>
</blockquote></div>