Skip to content

wayland: add support for tabel input #16276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions DOCS/interface-changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Interface changes
::

--- mpv 0.41.0 ---
- add `--input-tablet-emulate-mouse` option
--- mpv 0.40.0 ---
- undeprecate list option suffixes that work with multiple items
- add `-del` to string list and keyvalue list options
Expand Down
5 changes: 5 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4526,6 +4526,11 @@ Input
for mouse key bindings and scripts which read mouse positions for platforms
which do not support ``--native-touch=no`` (e.g. Wayland).

``--input-tablet-emulate-mouse=<yes|no>``
Emulate mouse move and button presses for tablet events (default: yes).
This is useful for compatibility for mouse key bindings and scripts which
read mouse positions.

``--input-dragging-deadzone=<N>``
Begin the built-in window dragging when the mouse moves outside a deadzone of
``N`` pixels while the mouse button is being held down (default: 3). This only
Expand Down
36 changes: 36 additions & 0 deletions input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ struct input_ctx {
struct touch_point *touch_points;
int num_touch_points;

// Indicates tablet tools in proximity
bool tablet_tool_in_proximity;

unsigned int mouse_event_counter;

struct mp_input_src *sources[MP_MAX_SOURCES];
Expand Down Expand Up @@ -197,6 +200,7 @@ struct input_opts {
bool allow_win_drag;
bool preprocess_wheel;
bool touch_emulate_mouse;
bool tablet_emulate_mouse;
};

const struct m_sub_options input_config = {
Expand All @@ -219,6 +223,7 @@ const struct m_sub_options input_config = {
{"input-media-keys", OPT_BOOL(use_media_keys)},
{"input-preprocess-wheel", OPT_BOOL(preprocess_wheel)},
{"input-touch-emulate-mouse", OPT_BOOL(touch_emulate_mouse)},
{"input-tablet-emulate-mouse", OPT_BOOL(tablet_emulate_mouse)},
{"input-dragging-deadzone", OPT_INT(dragging_deadzone)},
#if HAVE_SDL2_GAMEPAD
{"input-gamepad", OPT_BOOL(use_gamepad)},
Expand All @@ -243,6 +248,7 @@ const struct m_sub_options input_config = {
.allow_win_drag = true,
.preprocess_wheel = true,
.touch_emulate_mouse = true,
.tablet_emulate_mouse = true,
},
.change_flags = UPDATE_INPUT,
};
Expand Down Expand Up @@ -1066,6 +1072,36 @@ int mp_input_get_touch_pos(struct input_ctx *ictx, int count, int *x, int *y, in
return num_touch_points;
}

void mp_input_set_tablet_tool_in_proximity(struct input_ctx *ictx, bool in_proximity) {
input_lock(ictx);
ictx->tablet_tool_in_proximity = in_proximity;
Copy link
Contributor

Choose a reason for hiding this comment

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

Add locking.

input_unlock(ictx);
}

void mp_input_tablet_tool_down(struct input_ctx *ictx) {
input_lock(ictx);
if (ictx->opts->tablet_emulate_mouse && ictx->tablet_tool_in_proximity) {
feed_key(ictx, MP_MBTN_LEFT | MP_KEY_STATE_DOWN, 1, false);
}
input_unlock(ictx);
}

void mp_input_tablet_tool_up(struct input_ctx *ictx) {
input_lock(ictx);
if (ictx->opts->tablet_emulate_mouse && ictx->tablet_tool_in_proximity) {
feed_key(ictx, MP_MBTN_LEFT | MP_KEY_STATE_UP, 1, false);
}
input_unlock(ictx);
}

void mp_input_tablet_tool_button(struct input_ctx *ictx, int button, int state) {
input_lock(ictx);
if (ictx->opts->tablet_emulate_mouse && ictx->tablet_tool_in_proximity && button) {
feed_key(ictx, button | state, 1, false);
}
input_unlock(ictx);
}

static bool test_mouse(struct input_ctx *ictx, int x, int y, int rej_flags)
{
bool res = false;
Expand Down
6 changes: 6 additions & 0 deletions input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ void mp_input_remove_touch_point(struct input_ctx *ictx, int id);
// identify touch points. Return the current number of touch points.
int mp_input_get_touch_pos(struct input_ctx *ictx, int count, int *xs, int *ys, int *ids);

// Set tablet tool proximity and process tool tip down/up and buttons
void mp_input_set_tablet_tool_in_proximity(struct input_ctx *ictx, bool in_proximity);
void mp_input_tablet_tool_down(struct input_ctx *ictx);
void mp_input_tablet_tool_up(struct input_ctx *ictx);
void mp_input_tablet_tool_button(struct input_ctx *ictx, int button, int state);

// Return whether we want/accept mouse input.
bool mp_input_mouse_enabled(struct input_ctx *ictx);

Expand Down
7 changes: 4 additions & 3 deletions video/out/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ protocols = [[wl_protocol_dir, 'stable/presentation-time/presentation-time.xml']
[wl_protocol_dir, 'staging/content-type/content-type-v1.xml'],
[wl_protocol_dir, 'staging/fractional-scale/fractional-scale-v1.xml'],
[wl_protocol_dir, 'staging/single-pixel-buffer/single-pixel-buffer-v1.xml'],
[wl_protocol_dir, 'staging/xdg-activation/xdg-activation-v1.xml']]
[wl_protocol_dir, 'staging/xdg-activation/xdg-activation-v1.xml'],
# the tablet protocol can be updated to stable once minimum wayland-protocol version is >=1.35
[wl_protocol_dir, 'unstable/tablet/tablet-unstable-v2.xml']]
wl_protocols_source = []
wl_protocols_headers = []

Expand All @@ -19,8 +21,7 @@ foreach v: ['1.32', '1.38', '1.39', '1.41']
endforeach

if features['wayland-protocols-1-32']
protocols += [[wl_protocol_dir, 'staging/cursor-shape/cursor-shape-v1.xml'],
[wl_protocol_dir, 'unstable/tablet/tablet-unstable-v2.xml']] # required by cursor-shape
protocols += [[wl_protocol_dir, 'staging/cursor-shape/cursor-shape-v1.xml']]
endif


Expand Down
Loading