summaryrefslogtreecommitdiff
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
parent8160ad061328dfd40696b1c36c8aa911062cf8a4 (diff)
downloadmpv-iptv-menu-2b18f110d67651e59354a58128d201f878d0b166.tar.gz
mpv-iptv-menu-2b18f110d67651e59354a58128d201f878d0b166.tar.xz
route persistent bindings through key handler
-rw-r--r--input.lua36
-rw-r--r--main.lua5
-rw-r--r--osd.lua3
3 files changed, 33 insertions, 11 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
diff --git a/main.lua b/main.lua
index 6a7974a..de6f4d3 100644
--- a/main.lua
+++ b/main.lua
@@ -114,9 +114,10 @@ state.saved_osc_visibility = mp.get_property_native(
'user-data/osc/visibility', 'auto')
rt.set_osc_visibility(false)
-mp.add_forced_key_binding('TAB', 'toggle-menu', rt.toggle_menu)
-
input.init(state, osd, rt.toggle_menu)
+input.set_persistent_mapping({
+ ['TAB'] = {rt.toggle_menu},
+})
input.define_mapping('MENU', {
['BS'] = {rt.prev_menu},
['/'] = {rt.start_search},
diff --git a/osd.lua b/osd.lua
index 9aaa622..bbd4ee6 100644
--- a/osd.lua
+++ b/osd.lua
@@ -727,7 +727,8 @@ end
function mt:mouse_over_btn_area(mpos)
local y = mpos.y / self.scale
- return y < self.padding + (2 * config.font_size)
+ return mpos.x < self.width / 2 and
+ y < self.padding + (2 * config.font_size)
end
function mt:mouse_over_menu_btn(mpos)