-
Notifications
You must be signed in to change notification settings - Fork 61
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
fix: options.click_threshold #309
fix: options.click_threshold #309
Conversation
fbccb37
to
77bfd76
Compare
Deprecates `pause_on_click_shorter_than`.
Nope... 3a759d2.mp4pr.mp4 |
When I set it to I fail to see the problem. |
The previous : click → execute the command 1000ms later |
Why doesn't this respect |
These very odd patterns lead "double click" to double "double click" for me.
|
This is way more code than I'm willing to dedicate to this feature. It also doesn't solve the main issue the old one had: it doesn't filter out down->drag->up as not a click. I've searched the docs, tried some stuff too, and also asked on IRC, and afaik there's no way to detect window dragging, so this seems unsolvable. We should then just simplify/improve the old implementation. Here's what I came up with: -- Click detection
if options.click_threshold > 0 then
-- Executes custom command for clicks shorter than `options.click_threshold`
-- while filtering out double clicks.
local click_time = options.click_threshold / 1000
local doubleclick_time = mp.get_property_native('input-doubleclick-time') / 1000
local last_down, last_up = 0, 0
local click_timer = mp.add_timeout(math.max(click_time, doubleclick_time), function()
if last_up > last_down and last_up - last_down < click_time then mp.command(options.click_command) end
end)
click_timer:kill()
mp.set_key_bindings({{'mbtn_left',
function() last_up = mp.get_time() end,
function()
last_down = mp.get_time()
if click_timer:is_enabled() then click_timer:kill() else click_timer:resume() end
end,
},}, 'mouse_movement', 'force')
mp.enable_key_bindings('mouse_movement', 'allow-vo-dragging+allow-hide-cursor')
end If you don't see anything wrong with it just paste it there and lets be done with it. (I prefer |
Oh and I guess add a |
It makes things complicated and doesn't solve the problem, sorry |
b623400
to
9c5af51
Compare
Now it does.
It sure does for me. Maybe you didn't drag enough? Currently it filters out drags of 30px or more, but I can reduce the distance if that's too much for you.
Look at the code, there is a
Alright, it's forced now.
How do you even start with a button up? |
After a |
Hm? It doesn't work for me at all (win 10). The |
Well I can't test it on windows, and I had expected that those events will behave the same on every platform. fullscreen.mp4windowed.mp4As you can see, in windowed mode I get the up event very shortly after the down event because of the window dragging, but in fullscreen I get the up event when the mouse button actually gets released.
I can't get it to not register single clicks in windowed mode. Do we even want to register single clicks in windowed mode? Imo only registering single clicks when the window can't be dragged (e.g. fullscreen) is fine. Otherwise it will lead to unintentional clicks when dragging the window. |
for me (win11) in windowed mode, It stopped when dragging. mp.observe_property('mouse-pos', 'native', function(_, mouse)
print(mouse.hover, mouse.x, mouse.y)
end) |
I see. Does it work fine now after my last change? For me it behaves as expected.
Yes in windowed mode, but not in fullscreen. That's why detecting window dragging is important. |
I've made the gist into it's own repository now https://github.com/christoph-heinrich/mpv-pointer-event |
Just tested it on a touch device (also kwin wayland) and input handling has to change a bit to be able to handle touch... |
The issue is that there is no way to do so afaik. Neither
Hm? Why would you expect
Yes, that's the limitation of the current environment. User has to drag for at least |
Time based. If down and up event are too close together, it's because window dragging has started. We can reduce the 20ms if you think they are too long, but I don't think it's possible to actually click so fast with your mouse to achieve a less then 20ms duration between those two events. Also hover goes to false right after, but I think time based is enough.
Because of window dragging 😉. Also with "can't get it to not register single clicks" I mean that no matter how long I press the button, it still executes the command in windowed mode. |
I'll repeat, there are no additional events triggered by dragging on windows.
There's a single
Are you sure you pasted the snippet properly? It works fine for me in both fullscreen or windowed, and I don't see any reason why it shouldn't. There is no special handling for the two. |
It's because I get an up event shortly after the down event in windowed mode. Events being fired differently on different platforms seems like a problem on the mpv side, maybe we should open an issue over there? |
Oh, yeah that needs to be filtered out then. But the point stands: we can't detect drags. So I guess just take my snippet, and add the 20ms check to up handler to filter out the noise. The main reason why I want this as part of uosc is to allow people to drag and pause video with primary mouse button, so that they can open menu with the secondary, as that is the convention everywhere. |
9c5af51
to
b91b4d0
Compare
Adding it to the timer required fewer changes and has the same effect. Btw touch input support in uosc is pretty bad and I have no idea how to fix it... the problem is that the down event happens before the move event, and since we're only binding the mouse button when it's over an element, that gets missed and it looks like the mouse moved... Edit: Switching to |
It's a stripped down version of https://gist.github.com/christoph-heinrich/a3e7fdf1ed24e8625f5f9934ebe1313a
Clicks are only registered when the window can't be dragged around. I don't know if that is how you want it to behave, but with window dragging also being left click, it's ambiguous how it should behave.
Also dragging when the window is currently not dragable is also filtered out with a threshold.