[PATCH] reset touch focus in unmap

wfu michael.fu at linux.intel.com
Tue Jul 23 00:51:06 PDT 2013


From: wfu <michael.fu at intel.com>

otherwise, there will be race condition of visiting invalid surface data
---
 src/compositor.c |    2 ++
 src/compositor.h |    3 +++
 src/input.c      |    8 ++++----
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index e9e1166..ac2de9a 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -988,6 +988,8 @@ weston_surface_unmap(struct weston_surface *surface)
 						 NULL,
 						 wl_fixed_from_int(0),
 						 wl_fixed_from_int(0));
+		if (seat->touch && seat->touch->focus == surface)
+			weston_touch_set_focus(seat, NULL);
 	}
 
 	weston_surface_schedule_repaint(surface);
diff --git a/src/compositor.h b/src/compositor.h
index 84f39e2..92e9e4f 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -371,6 +371,9 @@ weston_touch_create(void);
 void
 weston_touch_destroy(struct weston_touch *touch);
 void
+weston_touch_set_focus(struct weston_seat *seat,
+			  struct weston_surface *surface);
+void
 weston_touch_start_grab(struct weston_touch *device,
 			struct weston_touch_grab *grab);
 void
diff --git a/src/input.c b/src/input.c
index 1887e7f..704ec0d 100644
--- a/src/input.c
+++ b/src/input.c
@@ -983,8 +983,8 @@ notify_keyboard_focus_out(struct weston_seat *seat)
 	weston_keyboard_end_grab(keyboard);
 }
 
-static void
-touch_set_focus(struct weston_seat *seat, struct weston_surface *surface)
+WL_EXPORT void
+weston_touch_set_focus(struct weston_seat *seat, struct weston_surface *surface)
 {
 	struct wl_resource *resource;
 
@@ -1045,7 +1045,7 @@ notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
 		 * until all touch points are up again. */
 		if (seat->num_tp == 1) {
 			es = weston_compositor_pick_surface(ec, x, y, &sx, &sy);
-			touch_set_focus(seat, es);
+			weston_touch_set_focus(seat, es);
 		} else if (touch->focus) {
 			es = (struct weston_surface *) touch->focus;
 			weston_surface_from_global_fixed(es, x, y, &sx, &sy);
@@ -1074,7 +1074,7 @@ notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
 
 		grab->interface->up(grab, time, touch_id);
 		if (seat->num_tp == 0)
-			touch_set_focus(seat, NULL);
+			weston_touch_set_focus(seat, NULL);
 		break;
 	}
 }
-- 
1.7.10.4



More information about the wayland-devel mailing list