input: Move surface picking into the pointer grab focus callback

Currently the core input code does surface picking before calling into
the focus callback of the current grab.  Not all grabs need to pick a
surface however, so we're doing work we don't have to in those cases.

For example, the shell move and resize grabs don't need to pick and the
default grab in implicit grab mode doesn't either.

With this change, the pointer grab mechanism is now very simple:
the focus callback is called whenever the pointer may have a new focus,
the motion callback is called whenever the pointer moves and
the button callback whenever a button is pressed or released.
diff --git a/src/input.c b/src/input.c
index d23d78b..129593f 100644
--- a/src/input.c
+++ b/src/input.c
@@ -47,20 +47,12 @@
 weston_seat_repick(struct weston_seat *seat)
 {
 	const struct weston_pointer_grab_interface *interface;
-	struct weston_surface *surface;
-	struct weston_pointer *pointer = seat->pointer;
-	wl_fixed_t sx, sy;
 
-	if (!pointer)
+	if (seat->pointer == NULL)
 		return;
 
-	surface = weston_compositor_pick_surface(seat->compositor,
-						 pointer->x,
-						 pointer->y,
-						 &sx, &sy);
-
-	interface = pointer->grab->interface;
-	interface->focus(pointer->grab, surface, sx, sy);
+	interface = seat->pointer->grab->interface;
+	interface->focus(seat->pointer->grab);
 }
 
 static void
@@ -105,16 +97,21 @@
 }
 
 static void
-default_grab_focus(struct weston_pointer_grab *grab,
-		   struct weston_surface *surface, wl_fixed_t x, wl_fixed_t y)
+default_grab_focus(struct weston_pointer_grab *grab)
 {
 	struct weston_pointer *pointer = grab->pointer;
+	struct weston_surface *surface;
+	wl_fixed_t sx, sy;
 
 	if (pointer->button_count > 0)
 		return;
 
+	surface = weston_compositor_pick_surface(pointer->seat->compositor,
+						 pointer->x, pointer->y,
+						 &sx, &sy);
+
 	if (pointer->focus != surface)
-		weston_pointer_set_focus(pointer, surface, x, y);
+		weston_pointer_set_focus(pointer, surface, sx, sy);
 }
 
 static void
@@ -537,37 +534,21 @@
 			  struct weston_pointer_grab *grab)
 {
 	const struct weston_pointer_grab_interface *interface;
-	struct weston_compositor *compositor = pointer->seat->compositor;
-	struct weston_surface *surface;
-	wl_fixed_t sx, sy;
 
 	pointer->grab = grab;
 	interface = pointer->grab->interface;
 	grab->pointer = pointer;
-
-	surface = weston_compositor_pick_surface(compositor,
-						 pointer->x, pointer->y,
-						 &sx, &sy);
-
-	if (surface)
-		interface->focus(pointer->grab, surface, sx, sy);
+	interface->focus(pointer->grab);
 }
 
 WL_EXPORT void
 weston_pointer_end_grab(struct weston_pointer *pointer)
 {
 	const struct weston_pointer_grab_interface *interface;
-	struct weston_compositor *compositor = pointer->seat->compositor;
-	struct weston_surface *surface;
-	wl_fixed_t sx, sy;
-
-	surface = weston_compositor_pick_surface(compositor,
-						 pointer->x, pointer->y,
-						 &sx, &sy);
 
 	pointer->grab = &pointer->default_grab;
 	interface = pointer->grab->interface;
-	interface->focus(pointer->grab, surface, sx, sy);
+	interface->focus(pointer->grab);
 }
 
 WL_EXPORT void
@@ -641,8 +622,6 @@
 						   ix, iy, NULL))
 			weston_output_update_zoom(output, ZOOM_FOCUS_POINTER);
 
-	weston_seat_repick(seat);
-
 	if (pointer->sprite) {
 		weston_surface_set_position(pointer->sprite,
 					    ix - pointer->hotspot_x,
@@ -664,6 +643,7 @@
 	move_pointer(seat, pointer->x + dx, pointer->y + dy);
 
 	interface = pointer->grab->interface;
+	interface->focus(pointer->grab);
 	interface->motion(pointer->grab, time);
 }
 
@@ -680,6 +660,7 @@
 	move_pointer(seat, x, y);
 
 	interface = pointer->grab->interface;
+	interface->focus(pointer->grab);
 	interface->motion(pointer->grab, time);
 }