summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--player/lua/defaults.lua15
1 files changed, 13 insertions, 2 deletions
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua
index f3e16b9ed3..f2983e8dc3 100644
--- a/player/lua/defaults.lua
+++ b/player/lua/defaults.lua
@@ -131,6 +131,7 @@ end
-- "Newer" and more convenient API
local key_bindings = {}
+local key_binding_counter = 0
local function update_key_bindings()
for i = 1, 2 do
@@ -143,12 +144,19 @@ local function update_key_bindings()
section = "input_forced_" .. mp.script_name
flags = "force"
end
- local cfg = ""
+ local bindings = {}
for k, v in pairs(key_bindings) do
if v.bind and v.forced ~= def then
- cfg = cfg .. v.bind .. "\n"
+ bindings[#bindings + 1] = v
end
end
+ table.sort(bindings, function(a, b)
+ return a.priority < b.priority
+ end)
+ local cfg = ""
+ for _, v in ipairs(bindings) do
+ cfg = cfg .. v.bind .. "\n"
+ end
mp.input_define_section(section, cfg, flags)
-- TODO: remove the section if the script is stopped
mp.input_enable_section(section, "allow-hide-cursor+allow-vo-dragging")
@@ -217,6 +225,9 @@ local function add_binding(attrs, key, name, fn, rp)
attrs.bind = key .. " script-binding " .. mp.script_name .. "/" .. name
end
attrs.name = name
+ -- new bindings override old ones (but do not overwrite them)
+ key_binding_counter = key_binding_counter + 1
+ attrs.priority = key_binding_counter
key_bindings[name] = attrs
update_key_bindings()
dispatch_key_bindings[name] = key_cb