diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-20 19:06:48 -0800 |
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-20 19:06:48 -0800 |
| commit | 9b863cad505d01017ee980e16d072fb7cffcd029 (patch) | |
| tree | 34098c692a945ab4096addb7da7c62bf3b528f02 | |
| parent | bc33649c68238f5a4c602a8cc234ba24db678ad3 (diff) | |
| download | mpv-iptv-menu-9b863cad505d01017ee980e16d072fb7cffcd029.tar.gz mpv-iptv-menu-9b863cad505d01017ee980e16d072fb7cffcd029.tar.xz | |
use internal click detection for menu button
| -rw-r--r-- | main.lua | 33 |
1 files changed, 23 insertions, 10 deletions
@@ -1238,17 +1238,17 @@ binding_state.mappings.SEARCH = { -- leaving our keys bound to a common function and building our own logic to -- route keys per the current state. local function handle_key(ev) - t = binding_state.active[ev.key_name] + local t = binding_state.active[ev.key_name] if not t and ev.key_text then t = binding_state.active['ANY_UNICODE'] end - f = t and t[1] + local f = t and t[1] if not f then return end - flag = t[2] + local flag = t[2] if flag == 'complex' then f(ev) elseif ev.event == 'down' or @@ -1305,10 +1305,23 @@ local function toggle_menu() set_key_bindings() end -mp.set_key_bindings({ - {'MBTN_LEFT', toggle_menu}, - {'MBTN_LEFT_DBL'}, -}, 'menu_button', 'force') +local function bind_click(f) + mp.command_native({'enable-section', 'click-nodrag'}) + mp.add_forced_key_binding( + 'MBTN_LEFT', 'click', function(ev) + if process_mouse_click(ev) then + f() + end + end, {complex = true}) + mp.add_forced_key_binding('MBTN_LEFT_DBL', 'click-dbl') +end + +local function unbind_click() + mp.remove_key_binding('click') + mp.remove_key_binding('click-dbl') + mp.command_native({'disable-section', 'click-nodrag'}) +end + local menu_button_timer menu_button_timer = mp.add_periodic_timer(0.1, function() if mouse_state.pos and @@ -1356,9 +1369,9 @@ mp.observe_property('mouse-pos', 'native', function(_, mpos) if not over_menu_button ~= not ms.over_menu_button then ms.over_menu_button = over_menu_button if over_menu_button then - mp.enable_key_bindings('menu_button') + bind_click(toggle_menu) else - mp.disable_key_bindings('menu_button') + unbind_click() end end @@ -1386,7 +1399,7 @@ mp.observe_property('osd-dimensions', 'native', function(_, val) -- wipe mouse state on resize, clearing it until the next move. osd:show_menu_button(false) mouse_state = {click = {}} - mp.disable_key_bindings('menu_button') + unbind_click() menu_button_timer:kill() end) |
