mpv
mpv copied to clipboard
Moving window and cycle pause on MBTN_LEFT
I am wondering if it is possible to make MPV realist that if i'm dragging to window (to move it using left mouse button) it would not cycle pause if I have that action on left mouse button?
This is not a good solution but you can drag the title. Now I know why mpv's default key binding to cycle pause is right click.
This is not a good solution but you can drag the title. Now I know why mpv's default key binding to cycle pause is right click.
Its possible on other players but not on mpv. :(
It's very annoying that every time I try to move/drag my window using left-click and drag it, it pauses the video, I disabled titlebar, so when it is playing a video, the title bar and osc/osd are hidden, when I try to move my point, they will be displayed, I tried to click and drag anywhere in the video or the title bar(not the normal titlebar like a browser, but the titlebar from mpv itself), it pauses anyway.
It seems mpv cannot distinguish left-click from left-click-drag.
I had the same problem when I did this for left-mouse-key (this is standard in other players like Battler624 said)
@jimmy-1000 Yeah, now I use left-mouse-key to click-and-drag the window, and right-mouse-key or SPACE key to pause/play the video, just a workaround. But left-mouse-key to pause/play the video is like a habit from other video players.
I think that currently mpv doesn't suppress the click binding (MBTL_LEFT) if drag was performed at the same mouse-down action. From a quick look at the code it seems that drag is implemented at each VO independently, and that mpv itself is unaware of drag taking place.
As far as I can tell, it's not something which can be implemented at the core/central input handler, so I think a solution would need touching the code at every VO which supports drag - either that the VO informs the core that drag is taking place (and ends) and the core will then suppress the following mouse-up, or that the VO itself will suppress the mouse-up input if drag took place at the same mouse-down action.
I'm not sure which approach would be better, or if there are other approaches, or the kinds of gotchas which this system will have.
Bottom line - it needs to be coded, and as far as I can tell it's not a trivial thing which can be handled centrally.
Yeah. I also wish there was this kind of behavior, or at the very least a way to shortcut "drag window" to right mouse click (or middle), instead of the left one, so the left click could be used just for pausing. Maybe I've missed it, but from everything I've read, I don't think there is a "drag window" action to map to shortcuts.
Please somebody create a lua script to resolve this 🙏
This script I threw together seems to do it. It only toggles pause if the left click was held down for less than 0.2 seconds. You may want to increase that depending on your click speed, but it seemed pretty reliable for me.
local mp = require 'mp'
-- the coroutine will yield after the clickdown event and resume after the clickup event
local main = coroutine.wrap(function()
while true do
local time = mp.get_time()
coroutine.yield()
if (mp.get_time() - time) < 0.2 then
mp.set_property_bool('pause', not mp.get_property_bool('pause'))
end
-- wait until the next mousedown event
coroutine.yield()
end
end)
-- complex ensures the main function will be called for separate click down/up events
mp.add_key_binding("MBTN_LEFT", "pause-or-drag", main, {complex = true})
Edit: added a missing yield
This script I threw together seems to do it. It only toggles pause if the left click was held down for less than 0.2 seconds. You may want to increase that depending on your click speed, but it seemed pretty reliable for me. ...
It doesn't work for me. If I move the mpv window, it plays or pauses. (Using MBTN_LEFT cycle pause in input.conf)
You need to remove MBTN_LEFT binding, leave it without any bind. Also remove --no-window-dragging
if you have it in config or CLI. Script works well for me.
You need to remove MBTN_LEFT binding, leave it without any bind. Also remove
--no-window-dragging
if you have it in config or CLI. Script works well for me.
It doesn't work either.
I'm doing more tests, and found something interesting, sometimes it works, and sometimes it doesn't' work and I don't know why.
Update: There is a conflict with progressbar.lua. I need to solve this.
You can add MBTN_LEFT script-binding pause-or-drag
to input.conf
to set the binding manually. I don't know if that would break scripts that use left click.
Actually I didn't check how it interacts with the OSC, could someone maybe try toggling mute from the bottom bar and check if the pause toggles as well?
You can add
MBTN_LEFT script-binding pause-or-drag
toinput.conf
to set the binding manually. I don't know if that would break scripts that use left click.
It works !! Thanks a lot for your script and help. Can you tell me what is the function of pause-or-drag? By the way, toggling mute works correct.
what is the function of pause-or-drag?
It's the name of the keybind that is created in the last line of the script.
what is the function of pause-or-drag?
It's the name of the keybind that is created in the last line of the script.
Ahh, you created this function in your script.
@CogentRedTester it still works, amazing! Not all heroes wear capes. Thank you
This should be implemented into mpv, I changed the reaction down to "0.1". Still annoying in September 2023...
I was thinking maybe there is a way to make something like this "if button is pressed then [check/wait for mouse movement x/y axis (as this would suggest you are moving the window)] if yes then apply (don't pause), if not than ignore (pause)" This way we wouldn't depend on reaction time, which isn't always perfect.
@CogentRedTester it still works, amazing! Not all heroes wear capes. Thank you
This should be implemented into mpv, I changed the reaction down to "0.1". Still annoying in September 2023...
I was thinking maybe there is a way to make something like this "if button is pressed then [check/wait for mouse movement x/y axis (as this would suggest you are moving the window)] if yes then apply (don't pause), if not than ignore (pause)" This way we wouldn't depend on reaction time, which isn't always perfect.
The difficulty with detecting mouse movements is that mpv calculates the x and y position of the mouse relative to the top left corner of the mpv window. When you drag the mpv window, the window moves in sync with the mouse, and hence the relative position of the mouse remains the same.
Edit: if anyone has a solution please let me know.
You could also try this https://github.com/natural-harmonia-gropius/input-event The first example would make pause be ignored when dragging unless you drag and release really quick.
if anyone has a solution please let me know.
I have heard window-position
is readable on some system but Windows, not confirmed by myself.