summaryrefslogtreecommitdiff
path: root/input.lua
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-02-01 15:33:41 -0800
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-02-01 15:33:41 -0800
commit2b18f110d67651e59354a58128d201f878d0b166 (patch)
treed463ff7461ec028a0ecc0a16df0b497709dabb47 /input.lua
parent8160ad061328dfd40696b1c36c8aa911062cf8a4 (diff)
downloadmpv-iptv-menu-2b18f110d67651e59354a58128d201f878d0b166.tar.gz
mpv-iptv-menu-2b18f110d67651e59354a58128d201f878d0b166.tar.xz
route persistent bindings through key handler
Diffstat (limited to 'input.lua')
-rw-r--r--input.lua36
1 files changed, 28 insertions, 8 deletions
diff --git a/input.lua b/input.lua
index ae3002e..4172b72 100644
--- a/input.lua
+++ b/input.lua
@@ -6,6 +6,7 @@ local input = {}
local mappings = {}
local active_mapping = {}
+local persistent_mapping = {}
local mapping_bound = false
local clicks = {}
@@ -78,6 +79,13 @@ local function process_mbtn(ev, id)
end
end
+local btn_timer; btn_timer = mp.add_periodic_timer(0.1, function()
+ if osd.mpos and mp.get_time() - osd.mpos_time > config.btn_timeout then
+ osd:show_menu_btn(false)
+ btn_timer:kill()
+ end
+end, true) -- disabled
+
-- mpv does not process key-binding changes requested by script functions until
-- those functions return. in the meantime, while the function is running, mpv
-- discards any key presses for keys that were not already bound prior to the
@@ -112,8 +120,8 @@ local function handle_key(ev)
local target_mapping = osd.mstate.target and
active_mapping._targets and
active_mapping._targets[osd.mstate.target]
- local t = target_mapping and
- (target_mapping[k] or
+ local t = persistent_mapping[k] or
+ target_mapping and (target_mapping[k] or
ev.key_text and target_mapping['ANY_UNICODE']) or
(active_mapping[k] or
ev.key_text and active_mapping['ANY_UNICODE'])
@@ -126,6 +134,12 @@ local function handle_key(ev)
elseif osd.mactive then
osd:set_mactive(false)
clicks.k = nil
+
+ if not osd.menu_btn.hidden and
+ osd.mstate.target ~= 'menu_btn' then
+ osd:show_menu_btn(false)
+ btn_timer:kill()
+ end
end
local f = t and t[1]
@@ -147,6 +161,18 @@ local function handle_key(ev)
osd:flush(state)
end
+function input.set_persistent_mapping(m)
+ for k, _ in pairs(persistent_mapping) do
+ mp.remove_key_binding('persistent-' .. k)
+ end
+
+ persistent_mapping = m
+ for k, _ in pairs(m) do
+ mp.add_forced_key_binding(
+ k, 'persistent-' .. k, handle_key, {complex = true})
+ end
+end
+
-- uses enable-section and disable-section to disable builtin key bindings
-- while the OSD is visible. these commands are technically deprecated for
-- non-internal use, but they still work, and there doesn't appear to be
@@ -195,12 +221,6 @@ local function unbind_click()
mp.command_native({'disable-section', 'click-nodrag'})
end
-local btn_timer; btn_timer = mp.add_periodic_timer(0.1, function()
- if osd.mpos and mp.get_time() - osd.mpos_time > config.btn_timeout then
- osd:show_menu_btn(false)
- btn_timer:kill()
- end
-end, true) -- disabled
function input.update_mpos(mpos)
if not mpos then
return