mpv icon indicating copy to clipboard operation
mpv copied to clipboard

Moving window and cycle pause on MBTN_LEFT

Open Battler624 opened this issue 4 years ago • 8 comments

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?

Battler624 avatar Mar 28 '20 00:03 Battler624

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.

snylonue avatar Mar 28 '20 06:03 snylonue

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. :(

Battler624 avatar Apr 02 '20 16:04 Battler624

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.

c02y avatar Feb 15 '21 17:02 c02y

I had the same problem when I did this for left-mouse-key (this is standard in other players like Battler624 said)

jimmy-1000 avatar Feb 17 '21 02:02 jimmy-1000

@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.

c02y avatar Feb 17 '21 03:02 c02y

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.

avih avatar Feb 17 '21 10:02 avih

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.

Yoksven avatar May 25 '22 10:05 Yoksven

Please somebody create a lua script to resolve this 🙏

jimmy-1000 avatar Jul 24 '22 14:07 jimmy-1000

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

CogentRedTester avatar Sep 30 '22 05:09 CogentRedTester

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)

jimmy-1000 avatar Sep 30 '22 20:09 jimmy-1000

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.

kolinger avatar Sep 30 '22 20:09 kolinger

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.

jimmy-1000 avatar Sep 30 '22 20:09 jimmy-1000

I'm doing more tests, and found something interesting, sometimes it works, and sometimes it doesn't' work and I don't know why.

jimmy-1000 avatar Sep 30 '22 22:09 jimmy-1000

Update: There is a conflict with progressbar.lua. I need to solve this.

jimmy-1000 avatar Sep 30 '22 22:09 jimmy-1000

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.

CogentRedTester avatar Sep 30 '22 23:09 CogentRedTester

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?

CogentRedTester avatar Sep 30 '22 23:09 CogentRedTester

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.

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.

jimmy-1000 avatar Sep 30 '22 23:09 jimmy-1000

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.

CogentRedTester avatar Oct 01 '22 00:10 CogentRedTester

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.

jimmy-1000 avatar Oct 01 '22 02:10 jimmy-1000

@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.

geextahslex avatar Sep 02 '23 15:09 geextahslex

@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.

CogentRedTester avatar Oct 31 '23 08:10 CogentRedTester

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.