input: add ability to disable all default bindings for an input section

Add a flags parameter to mp_input_set_section(). Add a flag that defines
whether bindings in the default section are used or not. This is useful
for special functionality, where the normal key bindings may have
unwanted effects.

For example, it shouldn't be possible to seek during encoding. However,
you want to be able to cancel the encoding process gracefully. For that
purpose, the "encode" section of input.conf could be made exclusive:

    mp_input_set_section(mpctx->input, "encode", MP_INPUT_NO_DEFAULT_SECTION);

And input.conf could contain this definition:

    RIGHT seek 10
    q {encode} quit

Then only the key "q" would be bound during encoding.
This commit is contained in:
wm4 committed 2012-08-24 14:30:25 +02:00
1 parent 2adc81f0a2
commit 27a8610c56
3 files changed
+20 -8

No files matched your search

+10 -5
View File
@@ -452,6 +452,8 @@ struct input_ctx {
struct cmd_bind_section *cmd_bind_sections;
// Name of currently used command section
char *section;
// Bitfield of mp_input_section_flags
int section_flags;
// Used to track whether we managed to read something while checking
// events sources. If yes, the sources may have more queued.
@@ -1023,10 +1025,12 @@ static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, int n, int *keys)
cmd = section_find_bind_for_key(ictx, false, ictx->section, n, keys);
if (ictx->default_bindings && cmd == NULL)
cmd = section_find_bind_for_key(ictx, true, ictx->section, n, keys);
if (cmd == NULL)
cmd = section_find_bind_for_key(ictx, false, "default", n, keys);
if (ictx->default_bindings && cmd == NULL)
cmd = section_find_bind_for_key(ictx, true, "default", n, keys);
if (!(ictx->section_flags & MP_INPUT_NO_DEFAULT_SECTION)) {
if (cmd == NULL)
cmd = section_find_bind_for_key(ictx, false, "default", n, keys);
if (ictx->default_bindings && cmd == NULL)
cmd = section_find_bind_for_key(ictx, true, "default", n, keys);
}
if (cmd == NULL) {
char *key_buf = get_key_combo_name(keys, n);
@@ -1524,10 +1528,11 @@ static int parse_config_file(struct input_ctx *ictx, char *file)
return 1;
}
void mp_input_set_section(struct input_ctx *ictx, char *name)
void mp_input_set_section(struct input_ctx *ictx, char *name, int flags)
{
talloc_free(ictx->section);
ictx->section = talloc_strdup(ictx, name ? name : "default");
ictx->section_flags = flags;
}
char *mp_input_get_section(struct input_ctx *ictx)
+8 -1
View File
@@ -166,6 +166,12 @@ enum mp_command_type {
// Key FIFO was full - release events may be lost, zero button-down status
#define MP_INPUT_RELEASE_ALL -5
enum mp_input_section_flags {
// If a key binding is not defined in the current section, search the
// default section for it ("default" refers to bindings with no section
// specified, not to the default input.conf aka builtin key bindings)
MP_INPUT_NO_DEFAULT_SECTION = 1,
};
struct input_ctx;
@@ -246,7 +252,8 @@ void mp_cmd_free(struct mp_cmd *cmd);
struct mp_cmd *mp_cmd_clone(struct mp_cmd *cmd);
// Set current input section
void mp_input_set_section(struct input_ctx *ictx, char *name);
// flags is a bitfield of enum mp_input_section_flags values
void mp_input_set_section(struct input_ctx *ictx, char *name, int flags);
// Get current input section
char *mp_input_get_section(struct input_ctx *ictx);
+2 -2
View File
@@ -3613,10 +3613,10 @@ goto_enable_cache:
mpctx->sh_video->fps, mpctx->sh_video->frametime);
}
mp_input_set_section(mpctx->input, NULL);
mp_input_set_section(mpctx->input, NULL, 0);
//TODO: add desired (stream-based) sections here
if (mpctx->stream->type == STREAMTYPE_TV)
mp_input_set_section(mpctx->input, "tv");
mp_input_set_section(mpctx->input, "tv", 0);
//==================== START PLAYING =======================