[PATCH weston v3 11/17] tablet: Add binding to activate surfaces using the tablet tool

Maniraj Devadoss Maniraj.Devadoss at in.bosch.com
Tue Dec 19 08:33:36 UTC 2017


From: Lyude Paul <thatslyude at gmail.com>

Co-authored-by: Peter Hutterer <peter.hutterer at who-t.net>
Signed-off-by: Lyude Paul <thatslyude at gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
Signed-off-by: Bastian Farkas <bfarkas at de.adit-jv.com>
---
 desktop-shell/shell.c  | 14 ++++++++++++++
 libweston/bindings.c   | 39 ++++++++++++++++++++++++++++++++++++++-
 libweston/compositor.c |  1 +
 libweston/compositor.h | 16 ++++++++++++++++
 libweston/input.c      |  6 ++++++
 5 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index c34dd9e..54ee4a2 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -4033,6 +4033,18 @@ touch_to_activate_binding(struct weston_touch *touch, uint32_t time,
 }
 
 static void
+tablet_tool_activate_binding(struct weston_tablet_tool *tool,
+			     uint32_t button, void *data)
+{
+	if (tool->grab != &tool->default_grab)
+		return;
+	if (tool->focus == NULL)
+		return;
+
+	activate_binding(tool->seat, data, tool->focus);
+}
+
+static void
 unfocus_all_seats(struct desktop_shell *shell)
 {
 	struct weston_seat *seat, *next;
@@ -5101,6 +5113,8 @@ shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
 	weston_compositor_add_touch_binding(ec, 0,
 					    touch_to_activate_binding,
 					    shell);
+	weston_compositor_add_tablet_tool_binding(ec, BTN_TOUCH, 0,
+						  tablet_tool_activate_binding, shell);
 	weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
 				           MODIFIER_SUPER | MODIFIER_ALT,
 				           surface_opacity_binding, NULL);
diff --git a/libweston/bindings.c b/libweston/bindings.c
index 2136652..7627dff 100644
--- a/libweston/bindings.c
+++ b/libweston/bindings.c
@@ -136,6 +136,24 @@ weston_compositor_add_touch_binding(struct weston_compositor *compositor,
 }
 
 WL_EXPORT struct weston_binding *
+weston_compositor_add_tablet_tool_binding(struct weston_compositor *compositor,
+					  uint32_t button, uint32_t modifier,
+					  weston_tablet_tool_binding_handler_t handler,
+					  void *data)
+{
+	struct weston_binding *binding;
+
+	binding = weston_compositor_add_binding(compositor, 0, button, 0,
+						modifier, handler, data);
+	if (binding == NULL)
+		return NULL;
+
+	wl_list_insert(compositor->tablet_tool_binding_list.prev, &binding->link);
+
+	return binding;
+}
+
+WL_EXPORT struct weston_binding *
 weston_compositor_add_axis_binding(struct weston_compositor *compositor,
 				   uint32_t axis, uint32_t modifier,
 				   weston_axis_binding_handler_t handler,
@@ -388,7 +406,26 @@ weston_compositor_run_touch_binding(struct weston_compositor *compositor,
 	}
 }
 
-int
+WL_EXPORT void
+weston_compositor_run_tablet_tool_binding(struct weston_compositor *compositor,
+					  struct weston_tablet_tool *tool,
+					  uint32_t button,
+					  enum zwp_tablet_tool_v1_button_state state)
+{
+	struct weston_binding *b;
+
+	if (state != ZWP_TABLET_TOOL_V1_BUTTON_STATE_PRESSED)
+		return;
+
+	wl_list_for_each(b, &compositor->tablet_tool_binding_list, link) {
+		if (b->modifier == tool->seat->modifier_state) {
+			weston_tablet_tool_binding_handler_t handler = b->handler;
+			handler(tool, button, b->data);
+		}
+	}
+}
+
+WL_EXPORT int
 weston_compositor_run_axis_binding(struct weston_compositor *compositor,
 				   struct weston_pointer *pointer,
 				   uint32_t time,
diff --git a/libweston/compositor.c b/libweston/compositor.c
index 1c31b20..f69a3e3 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -5125,6 +5125,7 @@ weston_compositor_create(struct wl_display *display, void *user_data)
 	wl_list_init(&ec->modifier_binding_list);
 	wl_list_init(&ec->button_binding_list);
 	wl_list_init(&ec->touch_binding_list);
+	wl_list_init(&ec->tablet_tool_binding_list);
 	wl_list_init(&ec->axis_binding_list);
 	wl_list_init(&ec->debug_binding_list);
 	wl_list_init(&ec->tablet_manager_resource_list);
diff --git a/libweston/compositor.h b/libweston/compositor.h
index 1d58293..90800a7 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -974,6 +974,7 @@ struct weston_compositor {
 	struct wl_list modifier_binding_list;
 	struct wl_list button_binding_list;
 	struct wl_list touch_binding_list;
+	struct wl_list tablet_tool_binding_list;
 	struct wl_list axis_binding_list;
 	struct wl_list debug_binding_list;
 
@@ -1635,6 +1636,16 @@ weston_compositor_add_touch_binding(struct weston_compositor *compositor,
 				    weston_touch_binding_handler_t binding,
 				    void *data);
 
+typedef void (*weston_tablet_tool_binding_handler_t)(struct weston_tablet_tool *tool,
+						     uint32_t button,
+						     void *data);
+struct weston_binding *
+weston_compositor_add_tablet_tool_binding(struct weston_compositor *compositor,
+					  uint32_t button,
+					  enum weston_keyboard_modifier modifier,
+					  weston_tablet_tool_binding_handler_t binding,
+					  void *data);
+
 typedef void (*weston_axis_binding_handler_t)(struct weston_pointer *pointer,
 					      uint32_t time,
 					      struct weston_pointer_axis_event *event,
@@ -1681,6 +1692,11 @@ void
 weston_compositor_run_touch_binding(struct weston_compositor *compositor,
 				    struct weston_touch *touch, uint32_t time,
 				    int touch_type);
+void
+weston_compositor_run_tablet_tool_binding(struct weston_compositor *compositor,
+					  struct weston_tablet_tool *tool,
+					  uint32_t button,
+					  enum zwp_tablet_tool_v1_button_state state);
 int
 weston_compositor_run_axis_binding(struct weston_compositor *compositor,
 				   struct weston_pointer *pointer, uint32_t time,
diff --git a/libweston/input.c b/libweston/input.c
index e1741a7..ecd4c58 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -35,6 +35,7 @@
 #include <values.h>
 #include <fcntl.h>
 #include <limits.h>
+#include <linux/input.h>
 
 #include "shared/helpers.h"
 #include "shared/os-compatibility.h"
@@ -3005,6 +3006,9 @@ notify_tablet_tool_button(struct weston_tablet_tool *tool,
 	}
 
 	tool->grab_serial = wl_display_next_serial(compositor->wl_display);
+
+	weston_compositor_run_tablet_tool_binding(compositor, tool, button, state);
+
 	grab->interface->button(grab, time, button, state);
 }
 
@@ -3022,6 +3026,8 @@ notify_tablet_tool_down(struct weston_tablet_tool *tool,
 	 tool->grab_x = tool->x;
 	 tool->grab_y = tool->y;
 
+	 weston_compositor_run_tablet_tool_binding(compositor, tool, BTN_TOUCH,
+						   ZWP_TABLET_TOOL_V1_BUTTON_STATE_PRESSED);
 	 grab->interface->down(grab, time);
 }
 
-- 
2.7.4



More information about the wayland-devel mailing list