[PATCH weston 4/4] clients: Add pointer gesture support to weston-eventdemo

Carlos Garnacho carlosg at gnome.org
Wed Jul 15 11:06:02 PDT 2015


Just print the output, as with the other events.

Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
---
 clients/eventdemo.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 95 insertions(+), 1 deletion(-)

diff --git a/clients/eventdemo.c b/clients/eventdemo.c
index dc69fd6..0bb349a 100644
--- a/clients/eventdemo.c
+++ b/clients/eventdemo.c
@@ -80,6 +80,12 @@ static int log_axis = 0;
 /** set to log motion events */
 static int log_motion = 0;
 
+/** set to log swipe gesture events */
+static int log_swipe_gesture = 0;
+
+/** set to log pinch gesture events */
+static int log_pinch_gesture = 0;
+
 /**
  * \struct eventdemo
  * \brief Holds all data the program needs per window
@@ -289,6 +295,83 @@ motion_handler(struct widget *widget, struct input *input, uint32_t time,
 	return CURSOR_LEFT_PTR;
 }
 
+static void
+gesture_swipe_begin_handler(struct widget *widget,
+			    struct input *input,
+			    uint32_t time,
+			    uint32_t n_fingers,
+			    void *data)
+{
+	if (log_swipe_gesture) {
+		printf("swipe gesture begin time: %d, fingers: %d\n", time, n_fingers);
+	}
+}
+
+static void
+gesture_swipe_update_handler(struct widget *widget,
+			     struct input *input,
+			     uint32_t time,
+			     float dx,
+			     float dy,
+			     void *data)
+{
+	if (log_swipe_gesture) {
+		printf("swipe gesture update time: %d, dx: %f, dy: %f\n", time, dx, dy);
+	}
+}
+
+static void
+gesture_swipe_end_handler(struct widget *widget,
+			  struct input *input,
+			  uint32_t time,
+			  int32_t cancelled,
+			  void *data)
+{
+	if (log_swipe_gesture) {
+		printf("swipe gesture end time: %d, cancelled: %d\n", time, cancelled);
+	}
+}
+
+static void
+gesture_pinch_begin_handler(struct widget *widget,
+			    struct input *input,
+			    uint32_t time,
+			    uint32_t n_fingers,
+			    void *data)
+{
+	if (log_pinch_gesture) {
+		printf("pinch gesture begin time: %d, fingers: %d\n", time, n_fingers);
+	}
+}
+
+static void
+gesture_pinch_update_handler(struct widget *widget,
+			     struct input *input,
+			     uint32_t time,
+			     float dx,
+			     float dy,
+			     float scale,
+			     float rotation_delta,
+			     void *data)
+{
+	if (log_pinch_gesture) {
+		printf("pinch gesture update time: %d, dx: %f, dy: %f, scale: %f, rotation delta: %f\n",
+		       time, dx, dy, scale, rotation_delta);
+	}
+}
+
+static void
+gesture_pinch_end_handler(struct widget *widget,
+			  struct input *input,
+			  uint32_t time,
+			  int32_t cancelled,
+			  void *data)
+{
+	if (log_pinch_gesture) {
+		printf("pinch gesture end time: %d, cancelled: %d\n", time, cancelled);
+	}
+}
+
 /**
  * \brief Create and initialise a new eventdemo window.
  * The returned eventdemo instance should be destroyed using \c eventdemo_destroy().
@@ -350,6 +433,14 @@ eventdemo_create(struct display *d)
 	/* Set the callback axis handler for the window */
 	widget_set_axis_handler(e->widget, axis_handler);
 
+	/* Set gesture handlers for the window */
+	widget_set_pointer_gesture_swipe_begin_handler (e->widget, gesture_swipe_begin_handler);
+	widget_set_pointer_gesture_swipe_update_handler (e->widget, gesture_swipe_update_handler);
+	widget_set_pointer_gesture_swipe_end_handler (e->widget, gesture_swipe_end_handler);
+	widget_set_pointer_gesture_pinch_begin_handler (e->widget, gesture_pinch_begin_handler);
+	widget_set_pointer_gesture_pinch_update_handler (e->widget, gesture_pinch_update_handler);
+	widget_set_pointer_gesture_pinch_end_handler (e->widget, gesture_pinch_end_handler);
+
 	/* Initial drawing of the window */
 	window_schedule_resize(e->window, width, height);
 
@@ -382,6 +473,8 @@ static const struct weston_option eventdemo_options[] = {
 	{ WESTON_OPTION_BOOLEAN, "log-button", 0, &log_button },
 	{ WESTON_OPTION_BOOLEAN, "log-axis", 0, &log_axis },
 	{ WESTON_OPTION_BOOLEAN, "log-motion", 0, &log_motion },
+	{ WESTON_OPTION_BOOLEAN, "log-swipe-gesture", 0, &log_swipe_gesture },
+	{ WESTON_OPTION_BOOLEAN, "log-pinch-gesture", 0, &log_pinch_gesture },
 };
 
 /**
@@ -419,7 +512,8 @@ main(int argc, char *argv[])
 	if (!log_redraw && !log_resize && !log_focus && !log_key &&
 	    !log_button && !log_axis && !log_motion)
 	  log_redraw = log_resize = log_focus = log_key =
-	    log_button = log_axis = log_motion = 1;
+	    log_button = log_axis = log_motion =
+	    log_swipe_gesture = log_pinch_gesture = 1;
 
 	/* Connect to the display and have the arguments parsed */
 	d = display_create(&argc, argv);
-- 
2.4.3



More information about the wayland-devel mailing list