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

Peter Hutterer peter.hutterer at who-t.net
Thu Nov 5 20:31:19 PST 2015


From: Stephen Chandler Paul <thatslyude at gmail.com>

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

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 5b604a5..d70f48f 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -5406,6 +5406,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;
@@ -6688,6 +6700,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/src/bindings.c b/src/bindings.c
index 234c034..a3c142d 100644
--- a/src/bindings.c
+++ b/src/bindings.c
@@ -135,6 +135,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,
@@ -387,7 +405,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_tool1_button_state state)
+{
+	struct weston_binding *b;
+
+	if (state != ZWP_TABLET_TOOL1_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, uint32_t axis,
diff --git a/src/compositor.c b/src/compositor.c
index 7777291..652872b 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -4522,6 +4522,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/src/compositor.h b/src/compositor.h
index 4da6bc5..8cc3cee 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -821,6 +821,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;
 
@@ -1401,6 +1402,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, uint32_t axis,
 					      wl_fixed_t value, void *data);
@@ -1446,6 +1457,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_tool1_button_state state);
 int
 weston_compositor_run_axis_binding(struct weston_compositor *compositor,
 				   struct weston_pointer *pointer, uint32_t time,
diff --git a/src/input.c b/src/input.c
index 145defd..b4e6c14 100644
--- a/src/input.c
+++ b/src/input.c
@@ -33,6 +33,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <limits.h>
+#include <linux/input.h>
 
 #include "shared/helpers.h"
 #include "shared/os-compatibility.h"
@@ -2345,6 +2346,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);
 }
 
@@ -2362,6 +2366,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_TOOL1_BUTTON_STATE_PRESSED);
 	 grab->interface->down(grab, time);
 }
 
-- 
2.4.3



More information about the wayland-devel mailing list