1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-24 00:46:58 +00:00

stats.lua: page 4 (keys): fix "excluding stats keys" - attempt 2

Page 4 bindings listing wants to exclude the interactive keys of the
stats script itself - so that they don't hide the normal keys which
are bound when stats is not interactive.

It did so by testing that the bound command includes stats/__key
which is how it usually looks when a script binds keys.

However, if a script uses a name for the binding - like stats.lua does
for the interative keys (because it later removes them by name when
interactive mode ends), then the command has stats/name rather than
stats/__key...

To fix this, we change the names of the forced interactive bindings
to start with __forced_, and that's now also what the page-4 listing
excludes.
This commit is contained in:
Avi Halachmi (:avih) 2021-07-20 00:49:03 +03:00
parent 1e1b5a6e14
commit 70c9d8d5d7

View File

@ -407,7 +407,7 @@ local function get_kbinfo_lines(width)
(active[bind.key].is_weak and not bind.is_weak) or
(bind.is_weak == active[bind.key].is_weak and
bind.priority > active[bind.key].priority)
) and not bind.cmd:find("script-binding stats/__key", 1, true)
) and not bind.cmd:find("script-binding stats/__forced_", 1, true)
then
active[bind.key] = bind
end
@ -1020,15 +1020,15 @@ local function reset_scroll_offsets()
end
local function bind_scroll()
if not scroll_bound then
mp.add_forced_key_binding(o.key_scroll_up, o.key_scroll_up, scroll_up, {repeatable=true})
mp.add_forced_key_binding(o.key_scroll_down, o.key_scroll_down, scroll_down, {repeatable=true})
mp.add_forced_key_binding(o.key_scroll_up, "__forced_"..o.key_scroll_up, scroll_up, {repeatable=true})
mp.add_forced_key_binding(o.key_scroll_down, "__forced_"..o.key_scroll_down, scroll_down, {repeatable=true})
scroll_bound = true
end
end
local function unbind_scroll()
if scroll_bound then
mp.remove_key_binding(o.key_scroll_up)
mp.remove_key_binding(o.key_scroll_down)
mp.remove_key_binding("__forced_"..o.key_scroll_up)
mp.remove_key_binding("__forced_"..o.key_scroll_down)
scroll_bound = false
end
end
@ -1052,7 +1052,7 @@ local function add_page_bindings()
end
end
for k, _ in pairs(pages) do
mp.add_forced_key_binding(k, k, a(k), {repeatable=true})
mp.add_forced_key_binding(k, "__forced_"..k, a(k), {repeatable=true})
end
update_scroll_bindings(curr_page)
end
@ -1061,7 +1061,7 @@ end
-- Remove keybindings for every page
local function remove_page_bindings()
for k, _ in pairs(pages) do
mp.remove_key_binding(k)
mp.remove_key_binding("__forced_"..k)
end
unbind_scroll()
end