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.
Unified · Split
| @@ -499,7 +499,7 @@ Input Commands that are Possibly Subject to Change · 498 unmodified lines | ||
| 499 | 499 | Note that there is a static limit of (as of this writing) 10 arguments |
| 500 | 500 | (this limit could be raised on demand). |
| 501 | 501 | |
| 502 | −``enable_section "<section>" [default|exclusive]`` | |
| 502 | +``enable_section "<section>" [flags]`` | |
| 503 | 503 | Enable all key bindings in the named input section. |
| 504 | 504 | |
| 505 | 505 | 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 | 508 | implicitly removed beforehand. (A section cannot be on the stack more than |
| 509 | 509 | once.) |
| 510 | 510 | |
| 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. | |
| 514 | 523 | |
| 515 | 524 | ``disable_section "<section>"`` |
| 516 | 525 | Disable the named input section. Undoes ``enable_section``. |
| @@ -162,8 +162,10 @@ const struct mp_cmd_def mp_cmds[] = { · 161 unmodified lines | ||
| 162 | 162 | |
| 163 | 163 | { MP_CMD_ENABLE_INPUT_SECTION, "enable-section", { |
| 164 | 164 | 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})), | |
| 167 | 169 | }}, |
| 168 | 170 | { MP_CMD_DISABLE_INPUT_SECTION, "disable-section", { ARG_STRING } }, |
| 169 | 171 | { MP_CMD_DEFINE_INPUT_SECTION, "define-section", { |
| @@ -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 | 4686 | 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); | |
| 4689 | 4688 | break; |
| 4690 | 4689 | |
| 4691 | 4690 | case MP_CMD_DISABLE_INPUT_SECTION: |
| @@ -1024,38 +1024,6 @@ static int script_get_time(lua_State *L) · 1023 unmodified lines | ||
| 1024 | 1024 | return 1; |
| 1025 | 1025 | } |
| 1026 | 1026 | |
| 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 | − | |
| 1059 | 1027 | static int script_input_set_section_mouse_area(lua_State *L) |
| 1060 | 1028 | { |
| 1061 | 1029 | struct MPContext *mpctx = get_mpctx(L); |
| @@ -1301,8 +1269,6 @@ static const struct fn_entry main_fns[] = { · 239 unmodified lines | ||
| 1301 | 1269 | FN_ENTRY(get_screen_margins), |
| 1302 | 1270 | FN_ENTRY(get_mouse_pos), |
| 1303 | 1271 | FN_ENTRY(get_time), |
| 1304 | − FN_ENTRY(input_enable_section), | |
| 1305 | − FN_ENTRY(input_disable_section), | |
| 1306 | 1272 | FN_ENTRY(input_set_section_mouse_area), |
| 1307 | 1273 | FN_ENTRY(format_time), |
| 1308 | 1274 | FN_ENTRY(enable_messages), |
| @@ -31,6 +31,17 @@ function mp.input_define_section(section, contents, flags) · 30 unmodified lines | ||
| 31 | 31 | mp.commandv("define-section", section, contents, flags) |
| 32 | 32 | end |
| 33 | 33 | |
| 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 | + | |
| 34 | 45 | -- For dispatching script_binding. This is sent as: |
| 35 | 46 | -- script_message_to $script_name $binding_name $keystate |
| 36 | 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 | 151 | end |
| 141 | 152 | mp.input_define_section(section, cfg, flags) |
| 142 | 153 | -- 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 | 155 | end |
| 145 | 156 | end |
| 146 | 157 | |
| @@ -1935,7 +1935,7 @@ end · 1934 unmodified lines | ||
| 1935 | 1935 | |
| 1936 | 1936 | function do_enable_keybindings() |
| 1937 | 1937 | 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 | 1939 | end |
| 1940 | 1940 | end |
| 1941 | 1941 | |