From 2b18f110d67651e59354a58128d201f878d0b166 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sun, 1 Feb 2026 15:33:41 -0800 Subject: route persistent bindings through key handler --- input.lua | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'input.lua') 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 -- cgit v1.2.3-70-g09d2