Add a touch binding to activate a surface
Adds a new binding type for touch events via the new function
weston_compositor_add_touch_binding. The binding can only be added for
a touch down with the first finger. The shell now uses this to install
a binding to activate the current surface.
diff --git a/src/bindings.c b/src/bindings.c
index f6ec9ea..03c9238 100644
--- a/src/bindings.c
+++ b/src/bindings.c
@@ -94,6 +94,24 @@
}
WL_EXPORT struct weston_binding *
+weston_compositor_add_touch_binding(struct weston_compositor *compositor,
+ uint32_t modifier,
+ weston_touch_binding_handler_t handler,
+ void *data)
+{
+ struct weston_binding *binding;
+
+ binding = weston_compositor_add_binding(compositor, 0, 0, 0,
+ modifier, handler, data);
+ if (binding == NULL)
+ return NULL;
+
+ wl_list_insert(compositor->touch_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,
@@ -253,6 +271,24 @@
}
}
+WL_EXPORT void
+weston_compositor_run_touch_binding(struct weston_compositor *compositor,
+ struct weston_seat *seat, uint32_t time,
+ int touch_type)
+{
+ struct weston_binding *b;
+
+ if (seat->num_tp != 1 || touch_type != WL_TOUCH_DOWN)
+ return;
+
+ wl_list_for_each(b, &compositor->touch_binding_list, link) {
+ if (b->modifier == seat->modifier_state) {
+ weston_touch_binding_handler_t handler = b->handler;
+ handler(seat, time, 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 376ddfd..a89d2a9 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -3012,6 +3012,7 @@
wl_list_init(&ec->output_list);
wl_list_init(&ec->key_binding_list);
wl_list_init(&ec->button_binding_list);
+ wl_list_init(&ec->touch_binding_list);
wl_list_init(&ec->axis_binding_list);
wl_list_init(&ec->debug_binding_list);
@@ -3072,6 +3073,7 @@
weston_binding_list_destroy_all(&ec->key_binding_list);
weston_binding_list_destroy_all(&ec->button_binding_list);
+ weston_binding_list_destroy_all(&ec->touch_binding_list);
weston_binding_list_destroy_all(&ec->axis_binding_list);
weston_binding_list_destroy_all(&ec->debug_binding_list);
diff --git a/src/compositor.h b/src/compositor.h
index a19d966..6199b01 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -574,6 +574,7 @@
struct wl_list plane_list;
struct wl_list key_binding_list;
struct wl_list button_binding_list;
+ struct wl_list touch_binding_list;
struct wl_list axis_binding_list;
struct wl_list debug_binding_list;
@@ -983,6 +984,15 @@
weston_button_binding_handler_t binding,
void *data);
+typedef void (*weston_touch_binding_handler_t)(struct weston_seat *seat,
+ uint32_t time,
+ void *data);
+struct weston_binding *
+weston_compositor_add_touch_binding(struct weston_compositor *compositor,
+ enum weston_keyboard_modifier modifier,
+ weston_touch_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);
@@ -1013,6 +1023,10 @@
struct weston_seat *seat, uint32_t time,
uint32_t button,
enum wl_pointer_button_state value);
+void
+weston_compositor_run_touch_binding(struct weston_compositor *compositor,
+ struct weston_seat *seat, uint32_t time,
+ int touch_type);
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 a994fb9..436b36c 100644
--- a/src/input.c
+++ b/src/input.c
@@ -1144,6 +1144,8 @@
weston_touch_set_focus(seat, NULL);
break;
}
+
+ weston_compositor_run_touch_binding(ec, seat, time, touch_type);
}
static void
diff --git a/src/shell.c b/src/shell.c
index f033e8c..4a0c122 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -3124,15 +3124,12 @@
}
static void
-click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
- void *data)
+activate_binding(struct weston_seat *seat,
+ struct desktop_shell *shell,
+ struct weston_surface *focus)
{
- struct weston_seat *ws = (struct weston_seat *) seat;
- struct desktop_shell *shell = data;
- struct weston_surface *focus;
struct weston_surface *main_surface;
- focus = (struct weston_surface *) seat->pointer->focus;
if (!focus)
return;
@@ -3143,8 +3140,28 @@
if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE)
return;
- if (seat->pointer->grab == &seat->pointer->default_grab)
- activate(shell, focus, ws);
+ activate(shell, focus, seat);
+}
+
+static void
+click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
+ void *data)
+{
+ if (seat->pointer->grab != &seat->pointer->default_grab)
+ return;
+
+ activate_binding(seat, data,
+ (struct weston_surface *) seat->pointer->focus);
+}
+
+static void
+touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data)
+{
+ if (seat->touch->grab != &seat->touch->default_grab)
+ return;
+
+ activate_binding(seat, data,
+ (struct weston_surface *) seat->touch->focus);
}
static void
@@ -4496,6 +4513,9 @@
weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
click_to_activate_binding,
shell);
+ weston_compositor_add_touch_binding(ec, 0,
+ touch_to_activate_binding,
+ shell);
weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
MODIFIER_SUPER | MODIFIER_ALT,
surface_opacity_binding, NULL);