summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-08-06 00:31:47 +0200
committerwm4 <wm4@nowhere>2015-08-06 00:31:47 +0200
commitd6c99bcda2b4e2791c6b147f5ba9d9cd95c7be7f (patch)
treecc31efc6ab85fef7e30c3a560c2d691b60ff4528
parentcaebbded67195d7f234e620cadc25ec276f4abcc (diff)
downloadmpv-d6c99bcda2b4e2791c6b147f5ba9d9cd95c7be7f.tar.bz2
mpv-d6c99bcda2b4e2791c6b147f5ba9d9cd95c7be7f.tar.xz
lua: implement input_enable_section/input_disable_section via commands
Removes some more internal API calls from the Lua scripting backend. Which is good, because ideally the scripting backend would use libmpv functions only. One awkwardness is that mouse sections are still not supported by the public commands (and probably will never), so flags like allow-hide- cursor make no sense to an outside user. Also, the way flags are passed to the Lua function changes. But that's ok, because they're only undocumented internal functions, and not supposed to be used by script users. osc.lua only does due to historical reasons.
-rw-r--r--DOCS/man/input.rst17
-rw-r--r--input/cmd_list.c6
-rw-r--r--player/command.c3
-rw-r--r--player/lua.c34
-rw-r--r--player/lua/defaults.lua13
-rw-r--r--player/lua/osc.lua2
6 files changed, 31 insertions, 44 deletions
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst
index 58413d54e3..530bb8f4dd 100644
--- a/DOCS/man/input.rst
+++ b/DOCS/man/input.rst
@@ -499,7 +499,7 @@ Input Commands that are Possibly Subject to Change
Note that there is a static limit of (as of this writing) 10 arguments
(this limit could be raised on demand).
-``enable_section "<section>" [default|exclusive]``
+``enable_section "<section>" [flags]``
Enable all key bindings in the named input section.
The enabled input sections form a stack. Bindings in sections on the top of
@@ -508,9 +508,18 @@ Input Commands that are Possibly Subject to Change
implicitly removed beforehand. (A section cannot be on the stack more than
once.)
- If ``exclusive`` is specified as second argument, all sections below the
- newly enabled section are disabled. They will be re-enabled as soon as
- all exclusive sections above them are removed.
+ The ``flags`` parameter can be a combination (separated by ``+``) of the
+ following flags:
+
+ <exclusive>
+ All sections enabled before the newly enabled section are disabled.
+ They will be re-enabled as soon as all exclusive sections above them
+ are removed. In other words, the new section shadows all previous
+ sections.
+ <allow-hide-cursor>
+ This feature can't be used through the public API.
+ <allow-vo-dragging>
+ Same.
``disable_section "<section>"``
Disable the named input section. Undoes ``enable_section``.
diff --git a/input/cmd_list.c b/input/cmd_list.c
index 250f451955..3640cce460 100644
--- a/input/cmd_list.c
+++ b/input/cmd_list.c
@@ -162,8 +162,10 @@ const struct mp_cmd_def mp_cmds[] = {
{ MP_CMD_ENABLE_INPUT_SECTION, "enable-section", {
ARG_STRING,
- OARG_CHOICE(0, ({"default", 0},
- {"exclusive", 1})),
+ OARG_FLAGS(0, ({"default", 0},
+ {"exclusive", MP_INPUT_EXCLUSIVE},
+ {"allow-hide-cursor", MP_INPUT_ALLOW_HIDE_CURSOR},
+ {"allow-vo-dragging", MP_INPUT_ALLOW_VO_DRAGGING})),
}},
{ MP_CMD_DISABLE_INPUT_SECTION, "disable-section", { ARG_STRING } },
{ MP_CMD_DEFINE_INPUT_SECTION, "define-section", {
diff --git a/player/command.c b/player/command.c
index edb1d81d66..742e78ef9e 100644
--- a/player/command.c
+++ b/player/command.c
@@ -4684,8 +4684,7 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
}
case MP_CMD_ENABLE_INPUT_SECTION:
- mp_input_enable_section(mpctx->input, cmd->args[0].v.s,
- cmd->args[1].v.i == 1 ? MP_INPUT_EXCLUSIVE : 0);
+ mp_input_enable_section(mpctx->input, cmd->args[0].v.s, cmd->args[1].v.i);
break;
case MP_CMD_DISABLE_INPUT_SECTION:
diff --git a/player/lua.c b/player/lua.c
index 3621e7aee5..cf0c5caa41 100644
--- a/player/lua.c
+++ b/player/lua.c
@@ -1024,38 +1024,6 @@ static int script_get_time(lua_State *L)
return 1;
}
-static int script_input_enable_section(lua_State *L)
-{
- struct MPContext *mpctx = get_mpctx(L);
- char *section = (char *)luaL_checkstring(L, 1);
- char *sflags = (char *)luaL_optstring(L, 2, "");
- bstr bflags = bstr0(sflags);
- int flags = 0;
- while (bflags.len) {
- bstr val;
- bstr_split_tok(bflags, "|", &val, &bflags);
- if (bstr_equals0(val, "allow-hide-cursor")) {
- flags |= MP_INPUT_ALLOW_HIDE_CURSOR;
- } else if (bstr_equals0(val, "allow-vo-dragging")) {
- flags |= MP_INPUT_ALLOW_VO_DRAGGING;
- } else if (bstr_equals0(val, "exclusive")) {
- flags |= MP_INPUT_EXCLUSIVE;
- } else {
- luaL_error(L, "invalid flag");
- }
- }
- mp_input_enable_section(mpctx->input, section, flags);
- return 0;
-}
-
-static int script_input_disable_section(lua_State *L)
-{
- struct MPContext *mpctx = get_mpctx(L);
- char *section = (char *)luaL_checkstring(L, 1);
- mp_input_disable_section(mpctx->input, section);
- return 0;
-}
-
static int script_input_set_section_mouse_area(lua_State *L)
{
struct MPContext *mpctx = get_mpctx(L);
@@ -1301,8 +1269,6 @@ static const struct fn_entry main_fns[] = {
FN_ENTRY(get_screen_margins),
FN_ENTRY(get_mouse_pos),
FN_ENTRY(get_time),
- FN_ENTRY(input_enable_section),
- FN_ENTRY(input_disable_section),
FN_ENTRY(input_set_section_mouse_area),
FN_ENTRY(format_time),
FN_ENTRY(enable_messages),
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua
index bc9114ffa5..d0ef57cccd 100644
--- a/player/lua/defaults.lua
+++ b/player/lua/defaults.lua
@@ -31,6 +31,17 @@ function mp.input_define_section(section, contents, flags)
mp.commandv("define-section", section, contents, flags)
end
+function mp.input_enable_section(section, flags)
+ if flags == nil then
+ flags = ""
+ end
+ mp.commandv("enable-section", section, flags)
+end
+
+function mp.input_disable_section(section)
+ mp.commandv("disable-section", section)
+end
+
-- For dispatching script_binding. This is sent as:
-- script_message_to $script_name $binding_name $keystate
-- The array is indexed by $binding_name, and has functions like this as value:
@@ -140,7 +151,7 @@ local function update_key_bindings()
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")
+ mp.input_enable_section(section, "allow-hide-cursor+allow-vo-dragging")
end
end
diff --git a/player/lua/osc.lua b/player/lua/osc.lua
index 8ce146d8e3..e131127922 100644
--- a/player/lua/osc.lua
+++ b/player/lua/osc.lua
@@ -1935,7 +1935,7 @@ end
function do_enable_keybindings()
if state.enabled then
- mp.enable_key_bindings("showhide", "allow-vo-dragging|allow-hide-cursor")
+ mp.enable_key_bindings("showhide", "allow-vo-dragging+allow-hide-cursor")
end
end