Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "cmd.h"

#define MAX_TOUCH_POINTS 10

struct input_ctx;
struct mp_log;

Expand Down
1 change: 0 additions & 1 deletion player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -3117,7 +3117,6 @@ static int get_touch_pos(int item, int action, void *arg, void *ctx)
return r;
}

#define MAX_TOUCH_POINTS 10
static int mp_property_touch_pos(void *ctx, struct m_property *prop,
int action, void *arg)
{
Expand Down
53 changes: 44 additions & 9 deletions video/out/wayland_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,10 @@ static void touch_handle_down(void *data, struct wl_touch *wl_touch,
struct vo_wayland_state *wl = s->wl;
s->last_serial = serial;
// Note: the position should still be saved here for VO dragging handling.
wl->mouse_x = handle_round(wl->scaling, wl_fixed_to_int(x_w));
wl->mouse_y = handle_round(wl->scaling, wl_fixed_to_int(y_w));
int x = handle_round(wl->scaling, wl_fixed_to_int(x_w));
int y = handle_round(wl->scaling, wl_fixed_to_int(y_w));
wl->mouse_x = x;
wl->mouse_y = y;

enum xdg_toplevel_resize_edge edge;
if (!mp_input_test_dragging(wl->vo->input_ctx, wl->mouse_x, wl->mouse_y) &&
Expand All @@ -544,8 +546,13 @@ static void touch_handle_down(void *data, struct wl_touch *wl_touch,
s->pointer_button_serial = serial;
wl->last_button_seat = s;
}

mp_input_add_touch_point(wl->vo->input_ctx, id, wl->mouse_x, wl->mouse_y);
MP_TARRAY_APPEND(wl, wl->touch_events, wl->num_touch_events,
(struct pending_touch_event){
.type = TOUCH_DOWN,
.id = id,
.mouse_x = x,
.mouse_y = y,
});
}

static void touch_handle_up(void *data, struct wl_touch *wl_touch,
Expand All @@ -554,8 +561,12 @@ static void touch_handle_up(void *data, struct wl_touch *wl_touch,
struct vo_wayland_seat *s = data;
struct vo_wayland_state *wl = s->wl;
s->last_serial = serial;
mp_input_remove_touch_point(wl->vo->input_ctx, id);
wl->last_button_seat = NULL;
MP_TARRAY_APPEND(wl, wl->touch_events, wl->num_touch_events,
(struct pending_touch_event){
.type = TOUCH_UP,
.id = id,
});
}

static void touch_handle_motion(void *data, struct wl_touch *wl_touch,
Expand All @@ -564,20 +575,44 @@ static void touch_handle_motion(void *data, struct wl_touch *wl_touch,
struct vo_wayland_seat *s = data;
struct vo_wayland_state *wl = s->wl;

wl->mouse_x = handle_round(wl->scaling, wl_fixed_to_int(x_w));
wl->mouse_y = handle_round(wl->scaling, wl_fixed_to_int(y_w));

mp_input_update_touch_point(wl->vo->input_ctx, id, wl->mouse_x, wl->mouse_y);
int x = handle_round(wl->scaling, wl_fixed_to_int(x_w));
int y = handle_round(wl->scaling, wl_fixed_to_int(y_w));
MP_TARRAY_APPEND(wl, wl->touch_events, wl->num_touch_events,
(struct pending_touch_event){
.type = TOUCH_MOTION,
.id = id,
.mouse_x = x,
.mouse_y = y,
});
}

static void touch_handle_frame(void *data, struct wl_touch *wl_touch)
{
struct vo_wayland_seat *s = data;
struct vo_wayland_state *wl = s->wl;

for (int i = 0; i < wl->num_touch_events; i++) {
struct pending_touch_event *e = &wl->touch_events[i];
switch (e->type) {
case TOUCH_DOWN:
mp_input_add_touch_point(wl->vo->input_ctx, e->id, e->mouse_x, e->mouse_y);
break;
case TOUCH_UP:
mp_input_remove_touch_point(wl->vo->input_ctx, e->id);
break;
case TOUCH_MOTION:
mp_input_update_touch_point(wl->vo->input_ctx, e->id, e->mouse_x, e->mouse_y);
break;
}
}
wl->num_touch_events = 0;
}

static void touch_handle_cancel(void *data, struct wl_touch *wl_touch)
{
struct vo_wayland_seat *s = data;
struct vo_wayland_state *wl = s->wl;
wl->num_touch_events = 0;
mp_input_put_key(wl->vo->input_ctx, MP_TOUCH_RELEASE_ALL);
}

Expand Down
17 changes: 17 additions & 0 deletions video/out/wayland_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ struct vo_wayland_seat;
struct vo_wayland_tranche;
struct vo_wayland_data_offer;

enum touch_event_type {
TOUCH_DOWN,
TOUCH_UP,
TOUCH_MOTION,
};

struct pending_touch_event {
enum touch_event_type type;
int32_t id;
int mouse_x;
int mouse_y;
Comment on lines +42 to +43
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be int x, y;, fingers are not mouse.

};

struct drm_format {
uint32_t format;
uint64_t modifier;
Expand Down Expand Up @@ -197,6 +210,10 @@ struct vo_wayland_state {
bool cursor_visible;
int allocated_cursor_scale;
struct vo_wayland_seat *last_button_seat;

/* Touch */
struct pending_touch_event *touch_events;
int num_touch_events;
};

bool vo_wayland_check_visible(struct vo *vo);
Expand Down
Loading