History

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.

wm4 committed 11 years ago

Commit d6c99bc1 parent caebbde6 files · +31 −44Browse files

Unified · Split

6 files
  1. DOCS/man/input.rst +13 −4
  2. input/cmd_list.c +4 −2
  3. player/command.c +1 −2
  4. player/lua.c +0 −34
  5. player/lua/defaults.lua +12 −1
  6. player/lua/osc.lua +1 −1
DOCS/man/input.rst+13−4
@@ -499,7 +499,7 @@ Input Commands that are Possibly Subject to Change · 498 unmodified lines
499 Note that there is a static limit of (as of this writing) 10 arguments499 Note that there is a static limit of (as of this writing) 10 arguments
500 (this limit could be raised on demand).500 (this limit could be raised on demand).
501 501
502``enable_section "<section>" [default|exclusive]``502``enable_section "<section>" [flags]``
503 Enable all key bindings in the named input section.503 Enable all key bindings in the named input section.
504 504
505 The enabled input sections form a stack. Bindings in sections on the top of505 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 · 2 unmodified lines
508 implicitly removed beforehand. (A section cannot be on the stack more than508 implicitly removed beforehand. (A section cannot be on the stack more than
509 once.)509 once.)
510 510
511 If ``exclusive`` is specified as second argument, all sections below the511 The ``flags`` parameter can be a combination (separated by ``+``) of the
512 newly enabled section are disabled. They will be re-enabled as soon as512 following flags:
513 all exclusive sections above them are removed.513
514 <exclusive>
515 All sections enabled before the newly enabled section are disabled.
516 They will be re-enabled as soon as all exclusive sections above them
517 are removed. In other words, the new section shadows all previous
518 sections.
519 <allow-hide-cursor>
520 This feature can't be used through the public API.
521 <allow-vo-dragging>
522 Same.
514 523
515``disable_section "<section>"``524``disable_section "<section>"``
516 Disable the named input section. Undoes ``enable_section``.525 Disable the named input section. Undoes ``enable_section``.
input/cmd_list.c+4−2
@@ -162,8 +162,10 @@ const struct mp_cmd_def mp_cmds[] = { · 161 unmodified lines
162 162
163 { MP_CMD_ENABLE_INPUT_SECTION, "enable-section", {163 { MP_CMD_ENABLE_INPUT_SECTION, "enable-section", {
164 ARG_STRING,164 ARG_STRING,
165 OARG_CHOICE(0, ({"default", 0},165 OARG_FLAGS(0, ({"default", 0},
166 {"exclusive", 1})),166 {"exclusive", MP_INPUT_EXCLUSIVE},
167 {"allow-hide-cursor", MP_INPUT_ALLOW_HIDE_CURSOR},
168 {"allow-vo-dragging", MP_INPUT_ALLOW_VO_DRAGGING})),
167 }},169 }},
168 { MP_CMD_DISABLE_INPUT_SECTION, "disable-section", { ARG_STRING } },170 { MP_CMD_DISABLE_INPUT_SECTION, "disable-section", { ARG_STRING } },
169 { MP_CMD_DEFINE_INPUT_SECTION, "define-section", {171 { MP_CMD_DEFINE_INPUT_SECTION, "define-section", {
player/command.c+1−2
@@ -4684,8 +4684,7 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re · 4683 unmodified lines
4684 }4684 }
4685 4685
4686 case MP_CMD_ENABLE_INPUT_SECTION:4686 case MP_CMD_ENABLE_INPUT_SECTION:
4687 mp_input_enable_section(mpctx->input, cmd->args[0].v.s,4687 mp_input_enable_section(mpctx->input, cmd->args[0].v.s, cmd->args[1].v.i);
4688 cmd->args[1].v.i == 1 ? MP_INPUT_EXCLUSIVE : 0);
4689 break;4688 break;
4690 4689
4691 case MP_CMD_DISABLE_INPUT_SECTION:4690 case MP_CMD_DISABLE_INPUT_SECTION:
player/lua.c+0−34
@@ -1024,38 +1024,6 @@ static int script_get_time(lua_State *L) · 1023 unmodified lines
1024 return 1;1024 return 1;
1025}1025}
1026 1026
1027static int script_input_enable_section(lua_State *L)
1028{
1029 struct MPContext *mpctx = get_mpctx(L);
1030 char *section = (char *)luaL_checkstring(L, 1);
1031 char *sflags = (char *)luaL_optstring(L, 2, "");
1032 bstr bflags = bstr0(sflags);
1033 int flags = 0;
1034 while (bflags.len) {
1035 bstr val;
1036 bstr_split_tok(bflags, "|", &val, &bflags);
1037 if (bstr_equals0(val, "allow-hide-cursor")) {
1038 flags |= MP_INPUT_ALLOW_HIDE_CURSOR;
1039 } else if (bstr_equals0(val, "allow-vo-dragging")) {
1040 flags |= MP_INPUT_ALLOW_VO_DRAGGING;
1041 } else if (bstr_equals0(val, "exclusive")) {
1042 flags |= MP_INPUT_EXCLUSIVE;
1043 } else {
1044 luaL_error(L, "invalid flag");
1045 }
1046 }
1047 mp_input_enable_section(mpctx->input, section, flags);
1048 return 0;
1049}
1050
1051static int script_input_disable_section(lua_State *L)
1052{
1053 struct MPContext *mpctx = get_mpctx(L);
1054 char *section = (char *)luaL_checkstring(L, 1);
1055 mp_input_disable_section(mpctx->input, section);
1056 return 0;
1057}
1058
1059static int script_input_set_section_mouse_area(lua_State *L)1027static int script_input_set_section_mouse_area(lua_State *L)
1060{1028{
1061 struct MPContext *mpctx = get_mpctx(L);1029 struct MPContext *mpctx = get_mpctx(L);
@@ -1301,8 +1269,6 @@ static const struct fn_entry main_fns[] = { · 239 unmodified lines
1301 FN_ENTRY(get_screen_margins),1269 FN_ENTRY(get_screen_margins),
1302 FN_ENTRY(get_mouse_pos),1270 FN_ENTRY(get_mouse_pos),
1303 FN_ENTRY(get_time),1271 FN_ENTRY(get_time),
1304 FN_ENTRY(input_enable_section),
1305 FN_ENTRY(input_disable_section),
1306 FN_ENTRY(input_set_section_mouse_area),1272 FN_ENTRY(input_set_section_mouse_area),
1307 FN_ENTRY(format_time),1273 FN_ENTRY(format_time),
1308 FN_ENTRY(enable_messages),1274 FN_ENTRY(enable_messages),
player/lua/defaults.lua+12−1
@@ -31,6 +31,17 @@ function mp.input_define_section(section, contents, flags) · 30 unmodified lines
31 mp.commandv("define-section", section, contents, flags)31 mp.commandv("define-section", section, contents, flags)
32end32end
33 33
34function mp.input_enable_section(section, flags)
35 if flags == nil then
36 flags = ""
37 end
38 mp.commandv("enable-section", section, flags)
39end
40
41function mp.input_disable_section(section)
42 mp.commandv("disable-section", section)
43end
44
34-- For dispatching script_binding. This is sent as:45-- For dispatching script_binding. This is sent as:
35-- script_message_to $script_name $binding_name $keystate46-- script_message_to $script_name $binding_name $keystate
36-- The array is indexed by $binding_name, and has functions like this as value:47-- The array is indexed by $binding_name, and has functions like this as value:
@@ -140,7 +151,7 @@ local function update_key_bindings() · 103 unmodified lines
140 end151 end
141 mp.input_define_section(section, cfg, flags)152 mp.input_define_section(section, cfg, flags)
142 -- TODO: remove the section if the script is stopped153 -- TODO: remove the section if the script is stopped
143 mp.input_enable_section(section, "allow-hide-cursor|allow-vo-dragging")154 mp.input_enable_section(section, "allow-hide-cursor+allow-vo-dragging")
144 end155 end
145end156end
146 157
player/lua/osc.lua+1−1
@@ -1935,7 +1935,7 @@ end · 1934 unmodified lines
1935 1935
1936function do_enable_keybindings()1936function do_enable_keybindings()
1937 if state.enabled then1937 if state.enabled then
1938 mp.enable_key_bindings("showhide", "allow-vo-dragging|allow-hide-cursor")1938 mp.enable_key_bindings("showhide", "allow-vo-dragging+allow-hide-cursor")
1939 end1939 end
1940end1940end
1941 1941

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t