[PATCH weston 18/19] tablet: Add binding to activate surfaces using the tablet tool

Stephen Chandler Paul thatslyude at gmail.com
Wed Aug 6 16:08:08 PDT 2014


Signed-off-by: Stephen Chandler Paul <thatslyude at gmail.com>
---
 desktop-shell/shell.c | 14 ++++++++++++++
 src/bindings.c        | 37 +++++++++++++++++++++++++++++++++++++
 src/compositor.c      |  1 +
 src/compositor.h      | 16 ++++++++++++++++
 src/input.c           |  7 +++++++
 5 files changed, 75 insertions(+)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 679d011..ba64ae0 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -4935,6 +4935,18 @@ touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data)
 }
 
 static void
+tablet_activate_binding(struct weston_tablet *tablet, uint32_t button,
+			void *data)
+{
+	if (tablet->grab != &tablet->default_grab)
+		return;
+	if (tablet->focus == NULL)
+		return;
+
+	activate_binding(tablet->seat, data, tablet->focus->surface);
+}
+
+static void
 unfocus_all_seats(struct desktop_shell *shell)
 {
 	struct weston_seat *seat, *next;
@@ -6362,6 +6374,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_binding(ec, BTN_TOUCH, 0,
+					     tablet_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 7d30024..e39486a 100644
--- a/src/bindings.c
+++ b/src/bindings.c
@@ -130,6 +130,24 @@ weston_compositor_add_touch_binding(struct weston_compositor *compositor,
 }
 
 WL_EXPORT struct weston_binding *
+weston_compositor_add_tablet_binding(struct weston_compositor *compositor,
+				     uint32_t button, uint32_t modifier,
+				     weston_tablet_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_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,
@@ -357,6 +375,25 @@ weston_compositor_run_touch_binding(struct weston_compositor *compositor,
 	}
 }
 
+WL_EXPORT void
+weston_compositor_run_tablet_binding(struct weston_compositor *compositor,
+				     struct weston_tablet *tablet,
+				     uint32_t button,
+				     enum wl_tablet_button_state state)
+{
+	struct weston_binding *b;
+
+	if (state != WL_TABLET_BUTTON_STATE_PRESSED)
+		return;
+
+	wl_list_for_each(b, &compositor->tablet_binding_list, link) {
+		if (b->modifier == tablet->seat->modifier_state) {
+			weston_tablet_binding_handler_t handler = b->handler;
+			handler(tablet, button, b->data);
+		}
+	}
+}
+
 WL_EXPORT int
 weston_compositor_run_axis_binding(struct weston_compositor *compositor,
 				   struct weston_seat *seat,
diff --git a/src/compositor.c b/src/compositor.c
index 55c959e..44c7910 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -3771,6 +3771,7 @@ weston_compositor_init(struct weston_compositor *ec,
 	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_binding_list);
 	wl_list_init(&ec->axis_binding_list);
 	wl_list_init(&ec->debug_binding_list);
 
diff --git a/src/compositor.h b/src/compositor.h
index 5d49c1d..05c6013 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -739,6 +739,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_binding_list;
 	struct wl_list axis_binding_list;
 	struct wl_list debug_binding_list;
 
@@ -1247,6 +1248,16 @@ weston_compositor_add_touch_binding(struct weston_compositor *compositor,
 				    weston_touch_binding_handler_t binding,
 				    void *data);
 
+typedef void (*weston_tablet_binding_handler_t)(struct weston_tablet *tablet,
+						uint32_t button,
+						void *data);
+struct weston_binding *
+weston_compositor_add_tablet_binding(struct weston_compositor *compositor,
+				     uint32_t button,
+				     enum weston_keyboard_modifier modifier,
+				     weston_tablet_binding_handler_t binding,
+				     void *data);
+
 typedef void (*weston_axis_binding_handler_t)(struct weston_seat *seat,
 					      uint32_t time, uint32_t axis,
 					      wl_fixed_t value, void *data);
@@ -1287,6 +1298,11 @@ void
 weston_compositor_run_touch_binding(struct weston_compositor *compositor,
 				    struct weston_seat *seat, uint32_t time,
 				    int touch_type);
+void
+weston_compositor_run_tablet_binding(struct weston_compositor *compositor,
+				     struct weston_tablet *tablet,
+				     uint32_t button,
+				     enum wl_tablet_button_state state);
 int
 weston_compositor_run_axis_binding(struct weston_compositor *compositor,
 				   struct weston_seat *seat, uint32_t time,
diff --git a/src/input.c b/src/input.c
index b7e7e0b..ee0393d 100644
--- a/src/input.c
+++ b/src/input.c
@@ -30,6 +30,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <limits.h>
+#include <linux/input.h>
 
 #include "../shared/os-compatibility.h"
 #include "compositor.h"
@@ -2021,6 +2022,9 @@ notify_tablet_button(struct weston_tablet *tablet, uint32_t time,
 	}
 
 	tablet->grab_serial = wl_display_next_serial(compositor->wl_display);
+
+	weston_compositor_run_tablet_binding(compositor, tablet, button, state);
+
 	grab->interface->button(grab, time, button, state);
 }
 
@@ -2037,6 +2041,9 @@ notify_tablet_down(struct weston_tablet *tablet, uint32_t time)
 	tablet->grab_x = tablet->x;
 	tablet->grab_y = tablet->y;
 
+	weston_compositor_run_tablet_binding(compositor, tablet, BTN_TOUCH,
+					     WL_TABLET_BUTTON_STATE_PRESSED);
+
 	grab->interface->down(grab, time);
 }
 
-- 
1.8.5.5



More information about the wayland-devel mailing list