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
499499 Note that there is a static limit of (as of this writing) 10 arguments
500500 (this limit could be raised on demand).
501501
502−``enable_section "<section>" [default|exclusive]``
502+``enable_section "<section>" [flags]``
503503 Enable all key bindings in the named input section.
504504
505505 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
508508 implicitly removed beforehand. (A section cannot be on the stack more than
509509 once.)
510510
511− If ``exclusive`` is specified as second argument, all sections below the
512− newly enabled section are disabled. They will be re-enabled as soon as
513− all exclusive sections above them are removed.
511+ The ``flags`` parameter can be a combination (separated by ``+``) of the
512+ following flags:
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.
514523
515524 ``disable_section "<section>"``
516525 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
162162
163163 { MP_CMD_ENABLE_INPUT_SECTION, "enable-section", {
164164 ARG_STRING,
165− OARG_CHOICE(0, ({"default", 0},
166− {"exclusive", 1})),
165+ OARG_FLAGS(0, ({"default", 0},
166+ {"exclusive", MP_INPUT_EXCLUSIVE},
167+ {"allow-hide-cursor", MP_INPUT_ALLOW_HIDE_CURSOR},
168+ {"allow-vo-dragging", MP_INPUT_ALLOW_VO_DRAGGING})),
167169 }},
168170 { MP_CMD_DISABLE_INPUT_SECTION, "disable-section", { ARG_STRING } },
169171 { 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
46844684 }
46854685
46864686 case MP_CMD_ENABLE_INPUT_SECTION:
4687− mp_input_enable_section(mpctx->input, cmd->args[0].v.s,
4688− cmd->args[1].v.i == 1 ? MP_INPUT_EXCLUSIVE : 0);
4687+ mp_input_enable_section(mpctx->input, cmd->args[0].v.s, cmd->args[1].v.i);
46894688 break;
46904689
46914690 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
10241024 return 1;
10251025 }
10261026
1027−static 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−
1051−static 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−
10591027 static int script_input_set_section_mouse_area(lua_State *L)
10601028 {
10611029 struct MPContext *mpctx = get_mpctx(L);
@@ -1301,8 +1269,6 @@ static const struct fn_entry main_fns[] = { · 239 unmodified lines
13011269 FN_ENTRY(get_screen_margins),
13021270 FN_ENTRY(get_mouse_pos),
13031271 FN_ENTRY(get_time),
1304− FN_ENTRY(input_enable_section),
1305− FN_ENTRY(input_disable_section),
13061272 FN_ENTRY(input_set_section_mouse_area),
13071273 FN_ENTRY(format_time),
13081274 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
3131 mp.commandv("define-section", section, contents, flags)
3232 end
3333
34+function mp.input_enable_section(section, flags)
35+ if flags == nil then
36+ flags = ""
37+ end
38+ mp.commandv("enable-section", section, flags)
39+end
40+
41+function mp.input_disable_section(section)
42+ mp.commandv("disable-section", section)
43+end
44+
3445 -- For dispatching script_binding. This is sent as:
3546 -- script_message_to $script_name $binding_name $keystate
3647 -- 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
140151 end
141152 mp.input_define_section(section, cfg, flags)
142153 -- 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")
144155 end
145156 end
146157
player/lua/osc.lua+1−1
@@ -1935,7 +1935,7 @@ end · 1934 unmodified lines
19351935
19361936 function do_enable_keybindings()
19371937 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")
19391939 end
19401940 end
19411941

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