Wayland: added basic touch support

Copy pasted from mako. I could not test.
This commit is contained in:
fwsmit 2021-01-06 20:47:41 +01:00
parent 814e620247
commit d7f93a3a69
3 changed files with 63 additions and 3 deletions

View File

@ -516,7 +516,8 @@ automatically lowered to half of the notification height if it exceeds it.
=item B<mouse_left/middle/right_click> (values: [none/do_action/close_current/close_all]) =item B<mouse_left/middle/right_click> (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 =over 4

View File

@ -25,6 +25,10 @@ void input_handle_click(unsigned int button, bool button_down, int mouse_x, int
case BTN_RIGHT: case BTN_RIGHT:
acts = settings.mouse_right_click; acts = settings.mouse_right_click;
break; break;
case BTN_TOUCH:
// TODO Add separate action for touch
acts = settings.mouse_left_click;
break;
default: default:
LOG_W("Unsupported mouse button: '%d'", button); LOG_W("Unsupported mouse button: '%d'", button);
return; return;

View File

@ -30,6 +30,8 @@
#include "../input.h" #include "../input.h"
#include "libgwater-wayland.h" #include "libgwater-wayland.h"
#define MAX_TOUCHPOINTS 10
struct window_wl { struct window_wl {
cairo_surface_t *c_surface; cairo_surface_t *c_surface;
cairo_t * c_ctx; cairo_t * c_ctx;
@ -64,6 +66,13 @@ struct wl_ctx {
int32_t x, y; int32_t x, y;
} pointer; } pointer;
struct {
struct wl_touch *wl_touch;
struct {
int32_t x, y;
} pts[MAX_TOUCHPOINTS];
} touch;
struct dimensions cur_dim; struct dimensions cur_dim;
int32_t width, height; int32_t width, height;
@ -144,7 +153,36 @@ static void destroy_output(struct dunst_output *output) {
free(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, 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) { uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
ctx.pointer.x = wl_fixed_to_int(surface_x); ctx.pointer.x = wl_fixed_to_int(surface_x);
@ -165,7 +203,15 @@ static const struct wl_pointer_listener pointer_listener = {
.axis = noop, .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, static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
uint32_t capabilities) { uint32_t capabilities) {
@ -180,6 +226,15 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
&pointer_listener, ctx.seat); &pointer_listener, ctx.seat);
LOG_I("Adding pointer"); 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 = { static const struct wl_seat_listener seat_listener = {