From d7f93a3a69eb410206a29d756d841376c96a59a5 Mon Sep 17 00:00:00 2001 From: fwsmit Date: Wed, 6 Jan 2021 20:47:41 +0100 Subject: [PATCH] Wayland: added basic touch support Copy pasted from mako. I could not test. --- docs/dunst.5.pod | 3 ++- src/input.c | 4 ++++ src/wayland/wl.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/docs/dunst.5.pod b/docs/dunst.5.pod index aff803b..4b6ed81 100644 --- a/docs/dunst.5.pod +++ b/docs/dunst.5.pod @@ -516,7 +516,8 @@ automatically lowered to half of the notification height if it exceeds it. =item B (values: [none/do_action/close_current/close_all]) -Defines action of mouse click. +Defines action of mouse click. A touch input in Wayland acts as a mouse left +click. =over 4 diff --git a/src/input.c b/src/input.c index 22b2ecb..1495e4d 100644 --- a/src/input.c +++ b/src/input.c @@ -25,6 +25,10 @@ void input_handle_click(unsigned int button, bool button_down, int mouse_x, int case BTN_RIGHT: acts = settings.mouse_right_click; break; + case BTN_TOUCH: + // TODO Add separate action for touch + acts = settings.mouse_left_click; + break; default: LOG_W("Unsupported mouse button: '%d'", button); return; diff --git a/src/wayland/wl.c b/src/wayland/wl.c index 9b3f412..74b501e 100644 --- a/src/wayland/wl.c +++ b/src/wayland/wl.c @@ -30,6 +30,8 @@ #include "../input.h" #include "libgwater-wayland.h" +#define MAX_TOUCHPOINTS 10 + struct window_wl { cairo_surface_t *c_surface; cairo_t * c_ctx; @@ -64,6 +66,13 @@ struct wl_ctx { int32_t x, y; } pointer; + struct { + struct wl_touch *wl_touch; + struct { + int32_t x, y; + } pts[MAX_TOUCHPOINTS]; + } touch; + struct dimensions cur_dim; int32_t width, height; @@ -144,7 +153,36 @@ static void destroy_output(struct dunst_output *output) { free(output); } -// FIXME: Snipped touch handling +static void touch_handle_motion(void *data, struct wl_touch *wl_touch, + uint32_t time, int32_t id, + wl_fixed_t surface_x, wl_fixed_t surface_y) { + if (id >= MAX_TOUCHPOINTS) { + return; + } + ctx.touch.pts[id].x = wl_fixed_to_int(surface_x); + ctx.touch.pts[id].y = wl_fixed_to_int(surface_y); +} + +static void touch_handle_down(void *data, struct wl_touch *wl_touch, + uint32_t serial, uint32_t time, struct wl_surface *sfc, int32_t id, + wl_fixed_t surface_x, wl_fixed_t surface_y) { + if (id >= MAX_TOUCHPOINTS) { + return; + } + ctx.touch.pts[id].x = wl_fixed_to_int(surface_x); + ctx.touch.pts[id].y = wl_fixed_to_int(surface_y); +} + +static void touch_handle_up(void *data, struct wl_touch *wl_touch, + uint32_t serial, uint32_t time, int32_t id) { + if (id >= MAX_TOUCHPOINTS) { + return; + } + input_handle_click(BTN_TOUCH, false, + ctx.touch.pts[id].x, ctx.touch.pts[id].y); + +} + static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { ctx.pointer.x = wl_fixed_to_int(surface_x); @@ -165,7 +203,15 @@ static const struct wl_pointer_listener pointer_listener = { .axis = noop, }; -// FIXME snipped touch listener +static const struct wl_touch_listener touch_listener = { + .down = touch_handle_down, + .up = touch_handle_up, + .motion = touch_handle_motion, + .frame = noop, + .cancel = noop, + .shape = noop, + .orientation = noop, +}; static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, uint32_t capabilities) { @@ -180,6 +226,15 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, &pointer_listener, ctx.seat); LOG_I("Adding pointer"); } + if (ctx.touch.wl_touch != NULL) { + wl_touch_release(ctx.touch.wl_touch); + ctx.touch.wl_touch = NULL; + } + if (capabilities & WL_SEAT_CAPABILITY_TOUCH) { + ctx.touch.wl_touch = wl_seat_get_touch(wl_seat); + wl_touch_add_listener(ctx.touch.wl_touch, + &touch_listener, ctx.seat); + } } static const struct wl_seat_listener seat_listener = {