summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.lua33
1 files changed, 23 insertions, 10 deletions
diff --git a/main.lua b/main.lua
index f454034..04e86fc 100644
--- a/main.lua
+++ b/main.lua
@@ -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)