summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2025-05-05 15:36:15 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2025-05-05 15:36:15 -0700
commitb1f23e176163324222338a80f92cf5ad32849566 (patch)
tree324c227a53ebc58215328aeb976e11a902dc1b45 /main.lua
parentdf67945f328b87967f63b1fef6060fc1ca8e153c (diff)
downloadmpv-iptv-menu-b1f23e176163324222338a80f92cf5ad32849566.tar.gz
mpv-iptv-menu-b1f23e176163324222338a80f92cf5ad32849566.tar.xz
add ability to toggle menu visibility
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua44
1 files changed, 37 insertions, 7 deletions
diff --git a/main.lua b/main.lua
index a2746d5..586d536 100644
--- a/main.lua
+++ b/main.lua
@@ -126,12 +126,42 @@ function handle_backspace()
update_osd()
end
-local repeatable = {repeatable=true}
-mp.add_forced_key_binding('UP', 'up', handle_up, repeatable)
-mp.add_forced_key_binding('DOWN', 'down', handle_down, repeatable)
-mp.add_forced_key_binding('PGUP', 'page_up', handle_page_up, repeatable)
-mp.add_forced_key_binding('PGDWN', 'page_down', handle_page_down, repeatable)
-mp.add_forced_key_binding('ENTER', 'enter', handle_enter)
-mp.add_forced_key_binding('BS', 'backspace', handle_backspace)
+function toggle_menu()
+ osd.hidden = not osd.hidden
+ osd:update()
+
+ if osd.hidden then
+ unbind_keys()
+ else
+ bind_keys()
+ end
+end
+
+local key_bindings = {}
+
+function bind_key(key, func, opts)
+ key_bindings[#key_bindings+1] = key
+ mp.add_forced_key_binding(key, key, func, opts)
+end
+
+function unbind_keys()
+ for _, key in ipairs(key_bindings) do
+ mp.remove_key_binding(key)
+ end
+ key_bindings = {}
+end
+
+function bind_keys()
+ local repeatable = {repeatable=true}
+ bind_key('UP', handle_up, repeatable)
+ bind_key('DOWN', handle_down, repeatable)
+ bind_key('PGUP', handle_page_up, repeatable)
+ bind_key('PGDWN', handle_page_down, repeatable)
+ bind_key('ENTER', handle_enter)
+ bind_key('BS', handle_backspace)
+end
+
+mp.add_forced_key_binding('TAB', 'toggle-menu', toggle_menu)
+bind_keys()
update_osd()