[PATCH weston v2 1/2] input: set the focus to NULL when the focus's resource is destroyed
Giulio Camuffo
giuliocamuffo at gmail.com
Wed Nov 20 07:47:40 PST 2013
with the surface ref-count feature a surface may live on after its
resource was destroyed. so listen for the resource destroy signal
and set the focus to NULL.
---
v2: rebased on top of master
src/compositor.h | 5 +++-
src/input.c | 75 ++++++++++++++++++++++++++++++++++++++++++++------------
2 files changed, 63 insertions(+), 17 deletions(-)
diff --git a/src/compositor.h b/src/compositor.h
index b84289a..7a66aed 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -308,7 +308,8 @@ struct weston_pointer {
struct wl_list focus_resource_list;
struct weston_view *focus;
uint32_t focus_serial;
- struct wl_listener focus_listener;
+ struct wl_listener view_focus_listener;
+ struct wl_listener resource_focus_listener;
struct wl_signal focus_signal;
struct wl_signal motion_signal;
@@ -334,6 +335,7 @@ struct weston_touch {
struct wl_list resource_list;
struct wl_list focus_resource_list;
struct weston_view *focus;
+ struct wl_listener resource_focus_listener;
uint32_t focus_serial;
struct wl_signal focus_signal;
@@ -435,6 +437,7 @@ struct weston_keyboard {
struct wl_list resource_list;
struct wl_list focus_resource_list;
struct weston_surface *focus;
+ struct wl_listener resource_focus_listener;
uint32_t focus_serial;
struct wl_signal focus_signal;
diff --git a/src/input.c b/src/input.c
index e285c59..6db4b05 100644
--- a/src/input.c
+++ b/src/input.c
@@ -71,6 +71,33 @@ weston_compositor_idle_release(struct weston_compositor *compositor)
}
static void
+pointer_focus_resource_destroyed(struct wl_listener *listener, void *data)
+{
+ struct weston_pointer *pointer =
+ container_of(listener, struct weston_pointer, resource_focus_listener);
+
+ weston_pointer_set_focus(pointer, NULL, 0, 0);
+}
+
+static void
+keyboard_focus_resource_destroyed(struct wl_listener *listener, void *data)
+{
+ struct weston_keyboard *keyboard =
+ container_of(listener, struct weston_keyboard, resource_focus_listener);
+
+ weston_keyboard_set_focus(keyboard, NULL);
+}
+
+static void
+touch_focus_resource_destroyed(struct wl_listener *listener, void *data)
+{
+ struct weston_touch *touch =
+ container_of(listener, struct weston_touch, resource_focus_listener);
+
+ weston_touch_set_focus(touch->seat, NULL);
+}
+
+static void
move_resources(struct wl_list *destination, struct wl_list *source)
{
wl_list_insert_list(destination, source);
@@ -394,11 +421,13 @@ weston_pointer_create(struct weston_seat *seat)
wl_list_init(&pointer->focus_resource_list);
weston_pointer_set_default_grab(pointer,
seat->compositor->default_pointer_grab);
+ wl_list_init(&pointer->resource_focus_listener.link);
+ pointer->resource_focus_listener.notify = pointer_focus_resource_destroyed;
pointer->default_grab.pointer = pointer;
pointer->grab = &pointer->default_grab;
wl_signal_init(&pointer->motion_signal);
wl_signal_init(&pointer->focus_signal);
- wl_list_init(&pointer->focus_listener.link);
+ wl_list_init(&pointer->view_focus_listener.link);
pointer->sprite_destroy_listener.notify = pointer_handle_sprite_destroy;
@@ -416,7 +445,8 @@ weston_pointer_destroy(struct weston_pointer *pointer)
pointer_unmap_sprite(pointer);
/* XXX: What about pointer->resource_list? */
-
+ wl_list_remove(&pointer->resource_focus_listener.link);
+ wl_list_remove(&pointer->view_focus_listener.link);
free(pointer);
}
@@ -442,6 +472,8 @@ weston_keyboard_create(void)
wl_list_init(&keyboard->resource_list);
wl_list_init(&keyboard->focus_resource_list);
+ wl_list_init(&keyboard->resource_focus_listener.link);
+ keyboard->resource_focus_listener.notify = keyboard_focus_resource_destroyed;
wl_array_init(&keyboard->keys);
keyboard->default_grab.interface = &default_keyboard_grab_interface;
keyboard->default_grab.keyboard = keyboard;
@@ -457,6 +489,7 @@ weston_keyboard_destroy(struct weston_keyboard *keyboard)
/* XXX: What about keyboard->resource_list? */
wl_array_release(&keyboard->keys);
+ wl_list_remove(&keyboard->resource_focus_listener.link);
free(keyboard);
}
@@ -471,6 +504,8 @@ weston_touch_create(void)
wl_list_init(&touch->resource_list);
wl_list_init(&touch->focus_resource_list);
+ wl_list_init(&touch->resource_focus_listener.link);
+ touch->resource_focus_listener.notify = touch_focus_resource_destroyed;
touch->default_grab.interface = &default_touch_grab_interface;
touch->default_grab.touch = touch;
touch->grab = &touch->default_grab;
@@ -484,6 +519,7 @@ weston_touch_destroy(struct weston_touch *touch)
{
/* XXX: What about touch->resource_list? */
+ wl_list_remove(&touch->resource_focus_listener.link);
free(touch);
}
@@ -506,20 +542,14 @@ seat_send_updated_caps(struct weston_seat *seat)
}
static void
-destroy_pointer_focus(struct wl_listener *listener, void *data)
+pointer_focus_view_destroyed(struct wl_listener *listener, void *data)
{
struct weston_pointer *pointer;
pointer = container_of(listener, struct weston_pointer,
- focus_listener);
-
- pointer->focus = NULL;
- move_resources(&pointer->resource_list, &pointer->focus_resource_list);
-
- wl_list_remove(&pointer->focus_listener.link);
- wl_list_init(&pointer->focus_listener.link);
+ view_focus_listener);
- wl_signal_emit(&pointer->focus_signal, pointer);
+ weston_pointer_set_focus(pointer, NULL, 0, 0);
}
WL_EXPORT void
@@ -548,6 +578,8 @@ weston_pointer_set_focus(struct weston_pointer *pointer,
pointer->focus->surface->resource);
}
+ wl_list_remove(&pointer->resource_focus_listener.link);
+ wl_list_init(&pointer->resource_focus_listener.link);
move_resources(&pointer->resource_list, focus_resource_list);
}
@@ -576,16 +608,18 @@ weston_pointer_set_focus(struct weston_pointer *pointer,
}
pointer->focus_serial = serial;
+ wl_resource_add_destroy_listener(view->surface->resource,
+ &pointer->resource_focus_listener);
}
- if (!wl_list_empty(&pointer->focus_listener.link)) {
- wl_list_remove(&pointer->focus_listener.link);
- wl_list_init(&pointer->focus_listener.link);
+ if (!wl_list_empty(&pointer->view_focus_listener.link)) {
+ wl_list_remove(&pointer->view_focus_listener.link);
+ wl_list_init(&pointer->view_focus_listener.link);
}
pointer->focus = view;
- pointer->focus_listener.notify = destroy_pointer_focus;
+ pointer->view_focus_listener.notify = pointer_focus_view_destroyed;
if (view)
- wl_signal_add(&view->destroy_signal, &pointer->focus_listener);
+ wl_signal_add(&view->destroy_signal, &pointer->view_focus_listener);
wl_signal_emit(&pointer->focus_signal, pointer);
}
@@ -622,6 +656,8 @@ weston_keyboard_set_focus(struct weston_keyboard *keyboard,
wl_keyboard_send_leave(resource, serial,
keyboard->focus->resource);
}
+ wl_list_remove(&keyboard->resource_focus_listener.link);
+ wl_list_init(&keyboard->resource_focus_listener.link);
move_resources(&keyboard->resource_list, focus_resource_list);
}
@@ -640,6 +676,8 @@ weston_keyboard_set_focus(struct weston_keyboard *keyboard,
surface,
serial);
keyboard->focus_serial = serial;
+ wl_resource_add_destroy_listener(surface->resource,
+ &keyboard->resource_focus_listener);
}
keyboard->focus = surface;
@@ -1258,6 +1296,9 @@ weston_touch_set_focus(struct weston_seat *seat, struct weston_view *view)
return;
}
+ wl_list_remove(&seat->touch->resource_focus_listener.link);
+ wl_list_init(&seat->touch->resource_focus_listener.link);
+
if (!wl_list_empty(focus_resource_list)) {
move_resources(&seat->touch->resource_list,
focus_resource_list);
@@ -1269,6 +1310,8 @@ weston_touch_set_focus(struct weston_seat *seat, struct weston_view *view)
move_resources_for_client(focus_resource_list,
&seat->touch->resource_list,
surface_client);
+ wl_resource_add_destroy_listener(view->surface->resource,
+ &seat->touch->resource_focus_listener);
}
seat->touch->focus = view;
}
--
1.8.4.2
More information about the wayland-devel
mailing list