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

Carlos Garnacho carlosg at gnome.org
Fri Jan 27 15:41:45 UTC 2017


Just print the output, as with the other events.

Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
Reviewed-by: Jonas Ã…dahl <jadahl at gmail.com>
Reviewed-by: Bryce Harrington <bryce at osg.samsung.com>
---
 clients/eventdemo.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 107 insertions(+), 1 deletion(-)

diff --git a/clients/eventdemo.c b/clients/eventdemo.c
index d8eef5b..415b28a 100644
--- a/clients/eventdemo.c
+++ b/clients/eventdemo.c
@@ -82,6 +82,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
@@ -373,6 +379,89 @@ 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().
@@ -441,6 +530,20 @@ eventdemo_create(struct display *d)
 				 axis_stop_handler,
 				 axis_discrete_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);
 
@@ -473,6 +576,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 },
 };
 
 /**
@@ -510,7 +615,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.9.3



More information about the wayland-devel mailing list