natural-harmonia-gropius / input-event

InputEvent.lua for mpv-player, enhanced input.conf with better, conflict-free, low-latency event mechanism.
MIT License
45 stars 5 forks source link

Remove "Left-click will be ignored for a short time after the focus window" #39

Closed natural-harmonia-gropius closed 9 months ago

natural-harmonia-gropius commented 9 months ago

100ms not always well worked, states based approach should no more race issue.

https://github.com/natural-harmonia-gropius/input-event/blob/239b2fc9c7486b9874e592bb8a95408d17e3c663/inputevent.lua#L445C1-L449C5

and

https://github.com/natural-harmonia-gropius/input-event?tab=readme-ov-file#left-click-will-be-ignored-for-a-short-time-after-the-focus-window

mpv.conf

[background]
profile-cond=not focused and get("current-tracks/video/albumart") == false
profile-restore=copy-equal
script-opts-append=inputevent-configs=input.conf,~~/input.noleft.conf
pause

input.noleft.conf

MBTN_LEFT   ignore  #@click
natural-harmonia-gropius commented 9 months ago

Closed by https://github.com/natural-harmonia-gropius/input-event/commit/4a73dd14c13aa8098569ac67403687dd5c21910a

verygoodlee commented 8 months ago

新版可灵活配置,更优雅了,但是会影响到双击行为。 一般来说设置成 左键单击切换暂停,双击切换全屏,\ 在窗口失焦状态下双击变成了切换暂停了,三击才是切换全屏,体验有些割裂,\ 旧版没这个问题。

natural-harmonia-gropius commented 8 months ago

加回去了

verygoodlee commented 8 months ago

我倒是有个方案,也是用auto profile实现,可以直接在profile-cond里写lua代码调用script-message-to。 实现新版一样的效果只要这样写,重新绑定MBTN_LEFT click这一个键

[inputevent-noleft-onfocus]
profile-cond=mp.commandv('script-message-to','inputevent','bind','MBTN_LEFT',focused and '{"click": "cycle pause"}' or '{"click": ""}')

要想不影响双击的话,加个定时器,获取焦点时延迟绑定,延迟时间大概1.5倍的input-doubleclick-time

[inputevent-noleft-onfocus]
profile-cond=mp.add_timeout(focused and input_doubleclick_time*1.5/1000 or 0, function() mp.commandv('script-message-to','inputevent','bind','MBTN_LEFT',focused and '{"click": "cycle pause"}' or '{"click": ""}') end)

暂时用着不错,估计还是有些特殊情况有冲突。

最大的缺点是可读性可维护性太差了,这里写lua代码不能换行,必须强制压为一行,\ 只是一种取巧写法,利用auto profile去监测属性变化并执行代码,并不是auto profile的正常用法。

verygoodlee commented 8 months ago

旧版的硬编码写死还是不太好,有些人可能不需要这个功能,可以试用下这个 verygoodlee/input-event@14ce642 可配置的。

获取焦点的时候写入一个 user-data属性user-data/inputevent/onfocus,并在1.5倍input-doubleclick-time定时之后删除它。

绑定按键使用property-expansion 语法判断一下,不存在这个属性时才执行 MBTN_LEFT ${!user-data/inputevent/onfocus:cycle pause}

@natural-harmonia-gropius 如果觉得不错可以提个PR合并一下

natural-harmonia-gropius commented 8 months ago

我觉得就像 _DBL 存在逻辑问题一样,获取窗口焦点的一次点击不应该触发任何事件。一般默认左键单击是播放/暂停,通过鼠标来获取焦点会让正在播放的视频暂停,这是反直觉的。

如果有人有实际的需要我再想怎么改。

verygoodlee commented 8 months ago

我试了几个有单击暂停功能的网页播放器,获取焦点时也会暂停,不过浏览器中有较多空白区域可以获取焦点,不会刻意去点视频区域获取焦点。 win10的电影和电视和win11的媒体播放器压根就不支持单击暂停,pot mpc这些也多年未用了,不记得他们是什么行为

natural-harmonia-gropius commented 8 months ago

我下载mpc-hc试了下会播放/暂停。没有必要跟从别人的行为啊,逻辑上就是点这一下会暂停很烦人。而且mpv除了顶栏就没有空白区域,就这唯一的顶栏还可以关掉,对一些用户来说是没有安全单击区域的。

verygoodlee commented 8 months ago

最近在用这个原生右键菜单 https://github.com/tsl0922/mpv-menu-plugin ,也有类似的问题 tsl0922/mpv-menu-plugin#23,没有一个通用的解决方案。 这个右键菜单不会使主窗口失去焦点,所以暂时inputevent不能解决,如果关闭菜单时能给inputevent发个script-message,或许能解决。

natural-harmonia-gropius commented 8 months ago

https://github.com/natural-harmonia-gropius/mpv-menu-plugin/actions/runs/7723662042

你试试看这个行不行

verygoodlee commented 8 months ago

https://github.com/natural-harmonia-gropius/mpv-menu-plugin/actions/runs/7723662042

你试试看这个行不行

可以的,但是和inputevent的有点冲突,inputevent的单击双击都绑定的MBTN_LEFT,直接禁用MBTN_LEFT会导致双击也失效,要完美搭配inputevent使用还是得自己改改

natural-harmonia-gropius commented 8 months ago

搭配inputevent

@verygoodlee 试试 https://github.com/tsl0922/mpv-menu-plugin/actions 最新版,在inputevent最后面加上这个。

mp.register_script_message('menu-close', function()
    local binding = bind_map["MBTN_LEFT"]
    if not binding then
        return
    end
    binding:ignore("click", binding.duration)
end)
verygoodlee commented 8 months ago

是的,上次就是这么改的,可以复用一下on_focused_update

mp.register_script_message("menu-close", function() on_focused_update(nil, true) end)