summaryrefslogtreecommitdiffstats
path: root/mpvcore/input
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-15 23:35:36 +0100
committerwm4 <wm4@nowhere>2013-12-16 20:03:00 +0100
commit5173900ed42074c1cf53d4eef622d5a1241d0325 (patch)
tree3e1c880375c75cf198548d39240f6c473f8d3569 /mpvcore/input
parentb65a6c3cd0cac1f86a3a5069514867c48a9fa4e3 (diff)
downloadmpv-5173900ed42074c1cf53d4eef622d5a1241d0325.tar.bz2
mpv-5173900ed42074c1cf53d4eef622d5a1241d0325.tar.xz
input: move some command flags into a bitfield
Diffstat (limited to 'mpvcore/input')
-rw-r--r--mpvcore/input/input.c58
-rw-r--r--mpvcore/input/input.h13
2 files changed, 37 insertions, 34 deletions
diff --git a/mpvcore/input/input.c b/mpvcore/input/input.c
index c7081e6514..2aa2a8ef36 100644
--- a/mpvcore/input/input.c
+++ b/mpvcore/input/input.c
@@ -918,14 +918,30 @@ error:
return false;
}
+struct flag {
+ const char *name;
+ unsigned int remove, add;
+};
+
+static const struct flag cmd_flags[] = {
+ {"pausing", MP_PAUSING_FLAGS, MP_PAUSING},
+ {"pausing-toggle", MP_PAUSING_FLAGS, MP_PAUSING_TOGGLE},
+ {"no-osd", MP_ON_OSD_FLAGS, MP_ON_OSD_NO},
+ {"osd-bar", MP_ON_OSD_FLAGS, MP_ON_OSD_BAR},
+ {"osd-msg", MP_ON_OSD_FLAGS, MP_ON_OSD_MSG},
+ {"osd-msg-bar", MP_ON_OSD_FLAGS, MP_ON_OSD_MSG | MP_ON_OSD_BAR},
+ {"osd-auto", MP_ON_OSD_FLAGS, MP_ON_OSD_AUTO},
+ {"expand-properties", 0, MP_EXPAND_PROPERTIES},
+ {"raw", MP_EXPAND_PROPERTIES, 0},
+ {0}
+};
+
// If dest is non-NULL when calling this function, append the command to the
// list formed by dest->queue_next, otherwise just set *dest = new_cmd;
static int parse_cmd(struct input_ctx *ictx, struct mp_cmd **dest, bstr str,
const char *loc)
{
- int pausing = 0;
- int on_osd = MP_ON_OSD_AUTO;
- bool raw_args = false;
+ int def_flags = MP_ON_OSD_AUTO | MP_EXPAND_PROPERTIES;
struct mp_cmd *cmd = NULL;
bstr start = str;
void *tmp = talloc_new(NULL);
@@ -947,31 +963,15 @@ static int parse_cmd(struct input_ctx *ictx, struct mp_cmd **dest, bstr str,
}
while (1) {
- if (eat_token(&str, "pausing")) {
- pausing = 1;
- } else if (eat_token(&str, "pausing_keep")) {
- pausing = 2;
- } else if (eat_token(&str, "pausing_toggle")) {
- pausing = 3;
- } else if (eat_token(&str, "pausing_keep_force")) {
- pausing = 4;
- } else if (eat_token(&str, "no-osd")) {
- on_osd = MP_ON_OSD_NO;
- } else if (eat_token(&str, "osd-bar")) {
- on_osd = MP_ON_OSD_BAR;
- } else if (eat_token(&str, "osd-msg")) {
- on_osd = MP_ON_OSD_MSG;
- } else if (eat_token(&str, "osd-msg-bar")) {
- on_osd = MP_ON_OSD_MSG | MP_ON_OSD_BAR;
- } else if (eat_token(&str, "osd-auto")) {
- // default
- } else if (eat_token(&str, "raw")) {
- raw_args = true;
- } else if (eat_token(&str, "expand-properties")) {
- // default
- } else {
- break;
+ for (int n = 0; cmd_flags[n].name; n++) {
+ if (eat_token(&str, cmd_flags[n].name)) {
+ def_flags &= ~cmd_flags[n].remove;
+ def_flags |= cmd_flags[n].add;
+ goto cont;
+ }
}
+ break;
+ cont: ;
}
int cmd_idx = 0;
@@ -991,9 +991,7 @@ static int parse_cmd(struct input_ctx *ictx, struct mp_cmd **dest, bstr str,
*cmd = (struct mp_cmd) {
.name = (char *)cmd_def->name,
.id = cmd_def->id,
- .pausing = pausing,
- .on_osd = on_osd,
- .raw_args = raw_args,
+ .flags = def_flags,
.scale = 1,
.def = cmd_def,
};
diff --git a/mpvcore/input/input.h b/mpvcore/input/input.h
index 13b86d227e..1698c9cf9f 100644
--- a/mpvcore/input/input.h
+++ b/mpvcore/input/input.h
@@ -114,11 +114,18 @@ 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_on_osd {
+enum mp_cmd_flags {
MP_ON_OSD_NO = 0, // prefer not using OSD
MP_ON_OSD_AUTO = 1, // use default behavior of the specific command
MP_ON_OSD_BAR = 2, // force a bar, if applicable
MP_ON_OSD_MSG = 4, // force a message, if applicable
+ MP_EXPAND_PROPERTIES = 8, // expand strings as properties
+ MP_PAUSING = 16, // pause after running command
+ MP_PAUSING_TOGGLE = 32, // toggle pause after running command
+
+ MP_ON_OSD_FLAGS = MP_ON_OSD_NO | MP_ON_OSD_AUTO |
+ MP_ON_OSD_BAR | MP_ON_OSD_MSG,
+ MP_PAUSING_FLAGS = MP_PAUSING | MP_PAUSING_TOGGLE,
};
enum mp_input_section_flags {
@@ -150,9 +157,7 @@ typedef struct mp_cmd {
char *name;
struct mp_cmd_arg args[MP_CMD_MAX_ARGS];
int nargs;
- int pausing;
- bool raw_args;
- enum mp_on_osd on_osd;
+ int flags; // mp_cmd_flags bitfield
bstr original;
char *input_section;
bool key_up_follows;