Add touch support for wl_shell_surface_move
diff --git a/clients/calibrator.c b/clients/calibrator.c
index 781475e..783cdec 100644
--- a/clients/calibrator.c
+++ b/clients/calibrator.c
@@ -163,8 +163,8 @@
 }
 
 static void
-touch_handler(struct widget *widget, uint32_t serial, uint32_t time,
-	      int32_t id, float x, float y, void *data)
+touch_handler(struct widget *widget, struct input *input, uint32_t serial,
+	      uint32_t time, int32_t id, float x, float y, void *data)
 {
 	struct calibrator *calibrator = data;
 
diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index 40c2781..319382d 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -322,8 +322,8 @@
 }
 
 static void
-panel_launcher_touch_down_handler(struct widget *widget, uint32_t serial,
-				  uint32_t time, int32_t id,
+panel_launcher_touch_down_handler(struct widget *widget, struct input *input,
+				  uint32_t serial, uint32_t time, int32_t id,
 				  float x, float y, void *data)
 {
 	struct panel_launcher *launcher;
@@ -334,8 +334,9 @@
 }
 
 static void
-panel_launcher_touch_up_handler(struct widget *widget, uint32_t serial,
-				uint32_t time, int32_t id, void *data)
+panel_launcher_touch_up_handler(struct widget *widget, struct input *input,
+				uint32_t serial, uint32_t time, int32_t id, 
+				void *data)
 {
 	struct panel_launcher *launcher;
 
diff --git a/clients/flower.c b/clients/flower.c
index b31d513..825c833 100644
--- a/clients/flower.c
+++ b/clients/flower.c
@@ -152,6 +152,16 @@
 	}
 }
 
+static void
+touch_down_handler(struct widget *widget, struct input *input, 
+		   uint32_t serial, uint32_t time, int32_t id, 
+		   float x, float y, void *data)
+{
+	struct flower *flower = data;
+	window_touch_move(flower->window, input, 
+			  display_get_serial(flower->display));
+}
+
 int main(int argc, char *argv[])
 {
 	struct flower flower;
@@ -178,6 +188,7 @@
 	widget_set_redraw_handler(flower.widget, redraw_handler);
 	widget_set_button_handler(flower.widget, button_handler);
 	widget_set_default_cursor(flower.widget, CURSOR_HAND1);
+	widget_set_touch_down_handler(flower.widget, touch_down_handler);
 
 	window_schedule_resize(flower.window, flower.width, flower.height);
 
diff --git a/clients/fullscreen.c b/clients/fullscreen.c
index bea1a15..72e2c81 100644
--- a/clients/fullscreen.c
+++ b/clients/fullscreen.c
@@ -278,6 +278,16 @@
 }
 
 static void
+touch_handler(struct widget *widget, struct input *input, 
+		   uint32_t serial, uint32_t time, int32_t id, 
+		   float x, float y, void *data)
+{
+	struct fullscreen *fullscreen = data;
+	window_touch_move(fullscreen->window, input, 
+			  display_get_serial(fullscreen->display));
+}
+
+static void
 usage(int error_code)
 {
 	fprintf(stderr, "Usage: fullscreen [OPTIONS]\n\n"
@@ -340,6 +350,8 @@
 	widget_set_button_handler(fullscreen.widget, button_handler);
 	widget_set_motion_handler(fullscreen.widget, motion_handler);
 
+	widget_set_touch_down_handler(fullscreen.widget, touch_handler);
+
 	window_set_key_handler(fullscreen.window, key_handler);
 	window_set_fullscreen_handler(fullscreen.window, fullscreen_handler);
 
diff --git a/clients/simple-egl.c b/clients/simple-egl.c
index 4eeba02..a557fca 100644
--- a/clients/simple-egl.c
+++ b/clients/simple-egl.c
@@ -55,6 +55,7 @@
 	struct wl_shell *shell;
 	struct wl_seat *seat;
 	struct wl_pointer *pointer;
+	struct wl_touch *touch;
 	struct wl_keyboard *keyboard;
 	struct wl_shm *shm;
 	struct wl_cursor_theme *cursor_theme;
@@ -529,6 +530,46 @@
 };
 
 static void
+touch_handle_down(void *data, struct wl_touch *wl_touch,
+		  uint32_t serial, uint32_t time, struct wl_surface *surface,
+		  int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
+{
+	struct display *d = (struct display *)data;
+
+	wl_shell_surface_move(d->window->shell_surface, d->seat, serial);
+}
+
+static void
+touch_handle_up(void *data, struct wl_touch *wl_touch,
+		uint32_t serial, uint32_t time, int32_t id)
+{
+}
+
+static void
+touch_handle_motion(void *data, struct wl_touch *wl_touch,
+		    uint32_t time, int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
+{
+}
+
+static void
+touch_handle_frame(void *data, struct wl_touch *wl_touch)
+{
+}
+
+static void
+touch_handle_cancel(void *data, struct wl_touch *wl_touch)
+{
+}
+
+static const struct wl_touch_listener touch_listener = {
+	touch_handle_down,
+	touch_handle_up,
+	touch_handle_motion,
+	touch_handle_frame,
+	touch_handle_cancel,
+};
+
+static void
 keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
 		       uint32_t format, int fd, uint32_t size)
 {
@@ -597,6 +638,15 @@
 		wl_keyboard_destroy(d->keyboard);
 		d->keyboard = NULL;
 	}
+
+	if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !d->touch) {
+		d->touch = wl_seat_get_touch(seat);
+		wl_touch_set_user_data(d->touch, d);
+		wl_touch_add_listener(d->touch, &touch_listener, d);
+	} else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && d->touch) {
+		wl_touch_destroy(d->touch);
+		d->touch = NULL;
+	}
 }
 
 static const struct wl_seat_listener seat_listener = {
diff --git a/clients/smoke.c b/clients/smoke.c
index 6b55797..dd5f4bd 100644
--- a/clients/smoke.c
+++ b/clients/smoke.c
@@ -267,8 +267,8 @@
 }
 
 static void
-touch_motion_handler(struct widget *widget, uint32_t time,
-		     int32_t id, float x, float y, void *data)
+touch_motion_handler(struct widget *widget, struct input *input,
+		     uint32_t time, int32_t id, float x, float y, void *data)
 {
 	smoke_motion_handler(data, x, y);
 }
diff --git a/clients/transformed.c b/clients/transformed.c
index e8d817d..54212dd 100644
--- a/clients/transformed.c
+++ b/clients/transformed.c
@@ -222,6 +222,16 @@
 }
 
 static void
+touch_handler(struct widget *widget, struct input *input, 
+		   uint32_t serial, uint32_t time, int32_t id, 
+		   float x, float y, void *data)
+{
+	struct transformed *transformed = data;
+	window_touch_move(transformed->window, input, 
+			  display_get_serial(transformed->display));
+}
+
+static void
 usage(int error_code)
 {
 	fprintf(stderr, "Usage: transformed [OPTIONS]\n\n"
@@ -287,6 +297,8 @@
 	widget_set_redraw_handler(transformed.widget, redraw_handler);
 	widget_set_button_handler(transformed.widget, button_handler);
 
+	widget_set_touch_down_handler(transformed.widget, touch_handler);
+
 	window_set_key_handler(transformed.window, key_handler);
 	window_set_fullscreen_handler(transformed.window, fullscreen_handler);
 	window_set_output_handler(transformed.window, output_handler);
diff --git a/clients/window.c b/clients/window.c
index 84d3e73..cee436c 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -1552,7 +1552,9 @@
 
 	wl_list_remove(&window->redraw_task.link);
 
-	wl_list_for_each(input, &display->input_list, link) {
+	wl_list_for_each(input, &display->input_list, link) {	  
+		if (input->touch_focus == window)
+			input->touch_focus = NULL;
 		if (input->pointer_focus == window)
 			input->pointer_focus = NULL;
 		if (input->keyboard_focus == window)
@@ -2353,8 +2355,8 @@
 }
 
 static void
-frame_button_touch_down_handler(struct widget *widget, uint32_t serial,
-				uint32_t time, int32_t id,
+frame_button_touch_down_handler(struct widget *widget, struct input *input,
+				uint32_t serial, uint32_t time, int32_t id,
 				float x, float y, void *data)
 {
 	struct frame_button *frame_button = data;
@@ -2692,6 +2694,19 @@
 	}
 }
 
+static void 
+frame_touch_down_handler(struct widget *widget, struct input *input,
+			 uint32_t serial, uint32_t time, int32_t id,
+			 float x, float y, void *data)
+{
+	struct window *window = widget->window;
+	struct display *display = window->display;
+	
+	wl_shell_surface_move(window->shell_surface,
+			      input_get_seat(input),
+			      display->serial);
+}
+
 struct widget *
 frame_create(struct window *window, void *data)
 {
@@ -2706,6 +2721,7 @@
 	widget_set_enter_handler(frame->widget, frame_enter_handler);
 	widget_set_motion_handler(frame->widget, frame_motion_handler);
 	widget_set_button_handler(frame->widget, frame_button_handler);
+	widget_set_touch_down_handler(frame->widget, frame_touch_down_handler);
 
 	/* Create empty list for frame buttons */
 	wl_list_init(&frame->buttons_list);
@@ -3207,8 +3223,7 @@
 	float sx = wl_fixed_to_double(x_w);
 	float sy = wl_fixed_to_double(y_w);
 
-	DBG("touch_handle_down: %i %i\n", id, wl_list_length(&input->touch_point_list));
-
+	input->display->serial = serial;
 	input->touch_focus = wl_surface_get_user_data(surface);
 	if (!input->touch_focus) {
 		DBG("Failed to find to touch focus for surface %p\n", surface);
@@ -3226,8 +3241,8 @@
 			wl_list_insert(&input->touch_point_list, &tp->link);
 
 			if (widget->touch_down_handler)
-				(*widget->touch_down_handler)(widget, serial,
-							      time, id,
+				(*widget->touch_down_handler)(widget, input, 
+							      serial, time, id,
 							      sx, sy,
 							      widget->user_data);
 		}
@@ -3241,8 +3256,6 @@
 	struct input *input = data;
 	struct touch_point *tp, *tmp;
 
-	DBG("touch_handle_up: %i %i\n", id, wl_list_length(&input->touch_point_list));
-
 	if (!input->touch_focus) {
 		DBG("No touch focus found for touch up event!\n");
 		return;
@@ -3253,7 +3266,7 @@
 			continue;
 
 		if (tp->widget->touch_up_handler)
-			(*tp->widget->touch_up_handler)(tp->widget, serial,
+			(*tp->widget->touch_up_handler)(tp->widget, input, serial,
 							time, id,
 							tp->widget->user_data);
 
@@ -3285,7 +3298,7 @@
 			continue;
 
 		if (tp->widget->touch_motion_handler)
-			(*tp->widget->touch_motion_handler)(tp->widget, time,
+			(*tp->widget->touch_motion_handler)(tp->widget, input, time,
 							    id, sx, sy,
 							    tp->widget->user_data);
 		return;
@@ -3307,7 +3320,8 @@
 
 	wl_list_for_each_safe(tp, tmp, &input->touch_point_list, link) {
 		if (tp->widget->touch_frame_handler)
-			(*tp->widget->touch_frame_handler)(tp->widget, tp->widget->user_data);
+			(*tp->widget->touch_frame_handler)(tp->widget, input, 
+							   tp->widget->user_data);
 
 		wl_list_remove(&tp->link);
 		free(tp);
@@ -3329,7 +3343,8 @@
 
 	wl_list_for_each_safe(tp, tmp, &input->touch_point_list, link) {
 		if (tp->widget->touch_cancel_handler)
-			(*tp->widget->touch_cancel_handler)(tp->widget, tp->widget->user_data);
+			(*tp->widget->touch_cancel_handler)(tp->widget, input,
+							    tp->widget->user_data);
 
 		wl_list_remove(&tp->link);
 		free(tp);
@@ -3813,6 +3828,16 @@
 	wl_shell_surface_move(window->shell_surface, input->seat, serial);
 }
 
+void
+window_touch_move(struct window *window, struct input *input, uint32_t serial)
+{
+	if (!window->shell_surface)
+		return;
+
+	wl_shell_surface_move(window->shell_surface, input->seat, 
+			      window->display->serial);
+}
+
 static void
 surface_set_synchronized(struct surface *surface)
 {
@@ -4920,6 +4945,7 @@
 	input = xzalloc(sizeof *input);
 	input->display = d;
 	input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface, 1);
+	input->touch_focus = NULL;
 	input->pointer_focus = NULL;
 	input->keyboard_focus = NULL;
 	wl_list_init(&input->touch_point_list);
diff --git a/clients/window.h b/clients/window.h
index 1646d5a..a2bab90 100644
--- a/clients/window.h
+++ b/clients/window.h
@@ -236,6 +236,7 @@
 					enum wl_pointer_button_state state,
 					void *data);
 typedef void (*widget_touch_down_handler_t)(struct widget *widget,
+					    struct input *input,
 					    uint32_t serial,
 					    uint32_t time,
 					    int32_t id,
@@ -243,18 +244,22 @@
 					    float y,
 					    void *data);
 typedef void (*widget_touch_up_handler_t)(struct widget *widget,
+					  struct input *input,
 					  uint32_t serial,
 					  uint32_t time,
 					  int32_t id,
 					  void *data);
 typedef void (*widget_touch_motion_handler_t)(struct widget *widget,
+					      struct input *input,
 					      uint32_t time,
 					      int32_t id,
 					      float x,
 					      float y,
 					      void *data);
-typedef void (*widget_touch_frame_handler_t)(struct widget *widget,void *data);
-typedef void (*widget_touch_cancel_handler_t)(struct widget *widget, void *data);
+typedef void (*widget_touch_frame_handler_t)(struct widget *widget, 
+					     struct input *input, void *data);
+typedef void (*widget_touch_cancel_handler_t)(struct widget *widget, 
+					      struct input *input, void *data);
 typedef void (*widget_axis_handler_t)(struct widget *widget,
 				      struct input *input, uint32_t time,
 				      uint32_t axis,
@@ -324,6 +329,8 @@
 void
 window_move(struct window *window, struct input *input, uint32_t time);
 void
+window_touch_move(struct window *window, struct input *input, uint32_t time);
+void
 window_get_allocation(struct window *window, struct rectangle *allocation);
 void
 window_schedule_redraw(struct window *window);