Skip to content
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

Is there any way to add touch swipe gestures to mpv? #6434

Open
sprite-1 opened this issue Jan 11, 2019 · 10 comments
Open

Is there any way to add touch swipe gestures to mpv? #6434

sprite-1 opened this issue Jan 11, 2019 · 10 comments

Comments

@sprite-1
Copy link

mpv version and platform

Windows 10, The latest build from https://mpv.srsfckn.biz/

Reproduction steps

Open a video and try to swipe.

Expected behavior

Some navigation happens

Actual behavior

Nothing

I just want to know if there's a way to configure MPV to recognize swipe gestures for example swiping up and down to adjust the volume and swipe left and right to navigate forward and backward in the playback.

@haasn
Copy link
Member

haasn commented Jan 11, 2019

It's not possible out of the box. But it's not impossible, either. A user script has access to all of the information it would need to implement a gesture recognition system.

@sprite-1
Copy link
Author

When you say user script, are you talking about input.conf? I have it configured along with mpv.conf but I can't find any info about mapping up touch gestures

@haasn
Copy link
Member

haasn commented Jan 11, 2019

No, I meant a lua script that tracks mouse movement and performs gesture recognition.

@sprite-1
Copy link
Author

Oh. I have zero clue how to use that so I guess I'll just wait in case it ever gets approved and gets implemented in the future.

@imufly
Copy link

imufly commented Jul 14, 2020

require 'mp.options'

local options = {
step = 5,
}

read_options(options,'touchscreen-seek')

function touch_seek()
local pos = get_mouse_area()
local step = options.step

if pos == 'left' then
mp.commandv('seek', -1*step)
elseif pos == 'right' then
mp.commandv('seek', step)
else
toggle_fullscreen()
end

end

function get_mouse_area()
local mouse_x,mouse_y = mp.get_mouse_pos()
local winX,winY = mp.get_property('osd-width'), mp.get_property('osd-height')

if mouse_x < winX/3 then
return 'left'
elseif mouse_x < winX/3*2 then
return 'middle'
else
return 'right'
end

end

function toggle_fullscreen()
local screen_stat = mp.get_property('fullscreen')

if screen_stat == 'yes' then
screen_stat = 'no'
else
screen_stat = 'yes'
end

mp.set_property('fullscreen', screen_stat)

end

mp.add_key_binding(nil, "touchscreen-seek", touch_seek)
mp.msg.info("Loaded touchscreen-seek Lua flavor")

@imufly
Copy link

imufly commented Jul 14, 2020

require 'mp.options'

local options = {
step = 5,
}

read_options(options,'touchscreen-seek')

function touch_seek()
local pos = get_mouse_area()
local step = options.step

if pos == 'left' then
mp.commandv('seek', -1*step)
elseif pos == 'right' then
mp.commandv('seek', step)
else
toggle_fullscreen()
end

end

function get_mouse_area()
local mouse_x,mouse_y = mp.get_mouse_pos()
local winX,winY = mp.get_property('osd-width'), mp.get_property('osd-height')

if mouse_x < winX/3 then
return 'left'
elseif mouse_x < winX/3*2 then
return 'middle'
else
return 'right'
end

end

function toggle_fullscreen()
local screen_stat = mp.get_property('fullscreen')

if screen_stat == 'yes' then
screen_stat = 'no'
else
screen_stat = 'yes'
end

mp.set_property('fullscreen', screen_stat)

end

mp.add_key_binding(nil, "touchscreen-seek", touch_seek)
mp.msg.info("Loaded touchscreen-seek Lua flavor")

I have the same requirement to play on a Windows tablet.
I wrote a script to support double tap to seek.
Double tap on left to seek backward and on right to seek forward.

Copy and store as scripts/touchscreen-seek.lua

Step value can be defined in script-opts/touchscreen-seek.conf, the default value is 5s.
step = 5

Define in input.conf
MBTN_LEFT_DBL script-binding touchscreen-seek

Hope it can help you.
@sprite-1

@keni7385
Copy link

Hi, thanks @imufly for your script!
I'm running mpv as video player in postmarketOS over a pinephone. I open every video already in fullscreen, so I found handy to have the middle double tap triggering a pause/resume toggle.

Instead of calling toggle_fullscreen() in the else branch of touch_seek() , I call the function toggle_pause(). The code:

function toggle_pause()
  local pause = mp.get_property_native("pause")
  mp.set_property_native("pause", not pause)
end

@groszdaniel
Copy link

A user script has access to all of the information it would need to implement a gesture recognition system.

Is there a way to distinguish between mouse and touchscreen events, or handle multiple fingers?

Looking at the OSC source code, it handles mouse events through input events like MOUSE_BTN* and MOUSE_MOVE. Currently there are no separate input keys for touch events, but the same mouse events are sent for touches as well.

In order to be able to properly handle touchscreen gestures from Lua scripts, we would need:

  • A way to distinguish between mouse and touch events. For instance, mouse dragging should continue to drag the window, while touch swipes may be used to seek or change the volume.
  • Access the number and location of fingers in the event handler.

A conventional way to implement this is to send separate events for touches (perhaps even depending on the number of fingers). Probably mouse events should also be sent so as not to break legacy configurations. Touch event handlers should be able to say whether to suppress the synthesized mouse events.

A simpler way would be to always send mouse events, but have a way for the event handler to access whether the event was actually generated by a mouse or a touchscreen, and in the latter case access the number and position of the fingers.

@camoz
Copy link

camoz commented Jun 23, 2022

Found a user script that does something similar and wanted to share it here: https://github.com/omeryagmurlu/mpv-gestures

@na-na-hi
Copy link
Contributor

na-na-hi commented May 1, 2024

Is there a way to distinguish between mouse and touchscreen events, or handle multiple fingers?

#14003

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants