Always reset keyboard and pointer focus
authorDaniel Stone <daniel@fooishbar.org>
Wed, 30 May 2012 15:31:46 +0000 (16:31 +0100)
committerKristian Høgsberg <krh@bitplanet.net>
Thu, 31 May 2012 18:01:29 +0000 (14:01 -0400)
If wl_pointer_set_focus or wl_keyboard_set_focus have been called before
a listener has been established for that seat and client combination,
the focus window will be set but the focus resource will be NULL.  This
changes these functions to always attempt to search for the relevant
focus resource, allowing the resource to be set by calling
wl_keyboard_set_focus and wl_pointer_set_focus again when a listener has
been established.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
src/wayland-server.c

index 256c553..d4a70cf 100644 (file)
@@ -704,11 +704,8 @@ wl_pointer_set_focus(struct wl_pointer *pointer, struct wl_surface *surface,
        struct wl_resource *resource;
        uint32_t serial;
 
-       if (pointer->focus == surface)
-               return;
-
        resource = pointer->focus_resource;
-       if (resource) {
+       if (resource && pointer->focus != surface) {
                serial = wl_display_next_serial(resource->client->display);
                wl_pointer_send_leave(resource, serial,
                                      &pointer->focus->resource);
@@ -717,7 +714,9 @@ wl_pointer_set_focus(struct wl_pointer *pointer, struct wl_surface *surface,
 
        resource = find_resource_for_surface(&pointer->resource_list,
                                             surface);
-       if (resource) {
+       if (resource &&
+           (pointer->focus != surface ||
+            pointer->focus_resource != resource)) {
                serial = wl_display_next_serial(resource->client->display);
                wl_pointer_send_enter(resource, serial, &surface->resource,
                                      sx, sy);
@@ -737,10 +736,7 @@ wl_keyboard_set_focus(struct wl_keyboard *keyboard, struct wl_surface *surface)
        struct wl_resource *resource;
        uint32_t serial;
 
-       if (keyboard->focus == surface)
-               return;
-
-       if (keyboard->focus_resource) {
+       if (keyboard->focus_resource && keyboard->focus != surface) {
                resource = keyboard->focus_resource;
                serial = wl_display_next_serial(resource->client->display);
                wl_keyboard_send_leave(resource, serial,
@@ -750,7 +746,9 @@ wl_keyboard_set_focus(struct wl_keyboard *keyboard, struct wl_surface *surface)
 
        resource = find_resource_for_surface(&keyboard->resource_list,
                                             surface);
-       if (resource) {
+       if (resource &&
+           (keyboard->focus != surface ||
+            keyboard->focus_resource != resource)) {
                serial = wl_display_next_serial(resource->client->display);
                wl_keyboard_send_enter(resource, serial, &surface->resource,
                                       &keyboard->keys);