Skip to content
New issue

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

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

Already on GitHub? # to your account

Moving window and cycle pause on MBTN_LEFT #7563

Closed
Battler624 opened this issue Mar 28, 2020 · 24 comments · Fixed by #14251
Closed

Moving window and cycle pause on MBTN_LEFT #7563

Battler624 opened this issue Mar 28, 2020 · 24 comments · Fixed by #14251
Labels
core:option-param-conf config, parameters, properties, options, shortcuts scripting

Comments

@Battler624
Copy link

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?

@snylonue
Copy link

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.

@Battler624
Copy link
Author

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

@c02y
Copy link

c02y commented Feb 15, 2021

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.

@jimmy-1000
Copy link

jimmy-1000 commented Feb 17, 2021

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

@c02y
Copy link

c02y commented Feb 17, 2021

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

@avih
Copy link
Member

avih commented Feb 17, 2021

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.

@Akemi Akemi added core:option-param-conf config, parameters, properties, options, shortcuts scripting labels Apr 29, 2021
@Yoksven
Copy link

Yoksven commented May 25, 2022

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.

@jimmy-1000
Copy link

jimmy-1000 commented Jul 24, 2022

Please somebody create a lua script to resolve this 🙏

@CogentRedTester
Copy link
Contributor

CogentRedTester commented Sep 30, 2022

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

@jimmy-1000
Copy link

jimmy-1000 commented Sep 30, 2022

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)

@kolinger
Copy link

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.

@jimmy-1000
Copy link

jimmy-1000 commented Sep 30, 2022

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
Copy link

jimmy-1000 commented Sep 30, 2022

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
Copy link

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

@CogentRedTester
Copy link
Contributor

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
Copy link
Contributor

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?

@jimmy-1000
Copy link

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.

@CogentRedTester
Copy link
Contributor

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.

@jimmy-1000
Copy link

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.

@geextahslex
Copy link

geextahslex commented Sep 2, 2023

@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
Copy link
Contributor

CogentRedTester commented Oct 31, 2023

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

@natural-harmonia-gropius
Copy link
Contributor

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.

@na-na-hi
Copy link
Contributor

Fixed by #14251. MBTN_LEFT will no longer be activated if it starts window dragging, which means it can be bound to any action. Just add the following to input.conf:

MBTN_LEFT cycle pause

@geextahslex
Copy link

@na-na-hi Awesome! Thank you :)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
core:option-param-conf config, parameters, properties, options, shortcuts scripting
Projects
None yet
Development

Successfully merging a pull request may close this issue.