diff options
Diffstat (limited to 'core/input/input.c')
-rw-r--r-- | core/input/input.c | 93 |
1 files changed, 41 insertions, 52 deletions
diff --git a/core/input/input.c b/core/input/input.c index 6419f28bc1..31b807d92f 100644 --- a/core/input/input.c +++ b/core/input/input.c @@ -61,9 +61,7 @@ #include <lirc/lircc.h> #endif -#include "ar.h" - -#define MP_MAX_KEY_DOWN 32 +#define MP_MAX_KEY_DOWN 4 struct cmd_bind { int input[MP_MAX_KEY_DOWN + 1]; @@ -130,6 +128,7 @@ static const mp_cmd_t mp_cmds[] = { { MP_CMD_QUIT, "quit", { OARG_INT(0) } }, { MP_CMD_STOP, "stop", }, { MP_CMD_FRAME_STEP, "frame_step", }, + { MP_CMD_FRAME_BACK_STEP, "frame_back_step", }, { MP_CMD_PLAYLIST_NEXT, "playlist_next", { OARG_CHOICE(0, ({"weak", 0}, {"0", 0}, {"force", 1}, {"1", 1})), @@ -221,7 +220,7 @@ static const struct legacy_cmd legacy_cmds[] = { {"audio_delay", "add audio-delay"}, {"switch_audio", "cycle audio"}, {"balance", "add balance"}, - {"vo_fullscreen", "no-osd cycle fullscreen"}, + {"vo_fullscreen", "cycle fullscreen"}, {"panscan", "add panscan"}, {"vo_ontop", "cycle ontop"}, {"vo_border", "cycle border"}, @@ -388,17 +387,6 @@ static const struct key_name key_names[] = { { MP_JOY_BTN8, "JOY_BTN8" }, { MP_JOY_BTN9, "JOY_BTN9" }, - { MP_AR_PLAY, "AR_PLAY" }, - { MP_AR_PLAY_HOLD, "AR_PLAY_HOLD" }, - { MP_AR_NEXT, "AR_NEXT" }, - { MP_AR_NEXT_HOLD, "AR_NEXT_HOLD" }, - { MP_AR_PREV, "AR_PREV" }, - { MP_AR_PREV_HOLD, "AR_PREV_HOLD" }, - { MP_AR_MENU, "AR_MENU" }, - { MP_AR_MENU_HOLD, "AR_MENU_HOLD" }, - { MP_AR_VUP, "AR_VUP" }, - { MP_AR_VDOWN, "AR_VDOWN" }, - { MP_KEY_POWER, "POWER" }, { MP_KEY_MENU, "MENU" }, { MP_KEY_PLAY, "PLAY" }, @@ -528,7 +516,6 @@ static const m_option_t input_conf[] = { { "keylist", print_key_list, CONF_TYPE_PRINT_FUNC, CONF_GLOBAL | CONF_NOCFG }, { "cmdlist", print_cmd_list, CONF_TYPE_PRINT_FUNC, CONF_GLOBAL | CONF_NOCFG }, OPT_STRING("js-dev", input.js_dev, CONF_GLOBAL), - OPT_STRING("ar-dev", input.ar_dev, CONF_GLOBAL), OPT_STRING("file", input.in_file, CONF_GLOBAL), OPT_FLAG("default-bindings", input.default_bindings, CONF_GLOBAL), OPT_FLAG("test", input.test, CONF_GLOBAL), @@ -540,7 +527,6 @@ static const m_option_t mp_input_opts[] = { OPT_FLAG("joystick", input.use_joystick, CONF_GLOBAL), OPT_FLAG("lirc", input.use_lirc, CONF_GLOBAL), OPT_FLAG("lircc", input.use_lircc, CONF_GLOBAL), - OPT_FLAG("ar", input.use_ar, CONF_GLOBAL), { NULL, NULL, 0, 0, 0, 0, NULL} }; @@ -578,7 +564,7 @@ static char *get_key_combo_name(int *keys, int max) while (1) { ret = get_key_name(*keys, ret); if (--max && *++keys) - talloc_asprintf_append_buffer(ret, "-"); + ret = talloc_asprintf_append_buffer(ret, "-"); else break; } @@ -821,7 +807,7 @@ mp_cmd_t *mp_input_parse_cmd(bstr str, const char *loc) if (bstrcasecmp(bstr_splice(str, 0, old_len), (bstr) {(char *)entry->old, old_len}) == 0) { - mp_tmsg(MSGT_INPUT, MSGL_V, "Warning: command '%s' is " + mp_tmsg(MSGT_INPUT, MSGL_WARN, "Warning: command '%s' is " "deprecated, replaced with '%s' at %s.\n", entry->old, entry->new, loc); bstr s = bstr_cut(str, old_len); @@ -1157,11 +1143,9 @@ static struct cmd_bind *section_find_bind_for_key(struct input_ctx *ictx, return bs->cmd_binds ? find_bind_for_key(bs->cmd_binds, n, keys) : NULL; } -static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, int n, int *keys) +static struct cmd_bind *find_any_bind_for_key(struct input_ctx *ictx, + int n, int *keys) { - if (ictx->test) - return handle_test(ictx, n, keys); - struct cmd_bind *cmd = section_find_bind_for_key(ictx, false, ictx->section, n, keys); if (ictx->default_bindings && cmd == NULL) @@ -1172,6 +1156,20 @@ static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, int n, int *keys) if (ictx->default_bindings && cmd == NULL) cmd = section_find_bind_for_key(ictx, true, "default", n, keys); } + return cmd; +} + +static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, int n, int *keys) +{ + if (ictx->test) + return handle_test(ictx, n, keys); + + struct cmd_bind *cmd = find_any_bind_for_key(ictx, n, keys); + if (cmd == NULL && n > 1) { + // Hitting two keys at once, and if there's no binding for this + // combination, the key hit last should be checked. + cmd = find_any_bind_for_key(ictx, 1, (int[]){keys[n - 1]}); + } if (cmd == NULL) { char *key_buf = get_key_combo_name(keys, n); @@ -1201,7 +1199,7 @@ static mp_cmd_t *interpret_key(struct input_ctx *ictx, int code) * we want to have "a" and "A" instead of "a" and "Shift+A"; but a separate * shift modifier is still kept for special keys like arrow keys. */ - int unmod = code & ~MP_KEY_MODIFIER_MASK; + int unmod = code & ~(MP_KEY_MODIFIER_MASK | MP_KEY_STATE_DOWN); if (unmod >= 32 && unmod < MP_KEY_BASE) code &= ~MP_KEY_MODIFIER_SHIFT; @@ -1223,7 +1221,10 @@ static mp_cmd_t *interpret_key(struct input_ctx *ictx, int code) ictx->num_key_down++; ictx->last_key_down = GetTimer(); ictx->ar_state = 0; - return NULL; + ret = NULL; + if (!(code & MP_NO_REPEAT_KEY)) + ret = get_cmd_from_keys(ictx, ictx->num_key_down, ictx->key_down); + return ret; } // button released or press of key with no separate down/up events for (j = 0; j < ictx->num_key_down; j++) { @@ -1239,6 +1240,7 @@ static mp_cmd_t *interpret_key(struct input_ctx *ictx, int code) j = ictx->num_key_down - 1; ictx->key_down[j] = code; } + bool emit_key = ictx->last_key_down && (code & MP_NO_REPEAT_KEY); if (j == ictx->num_key_down) { // was not already down; add temporarily if (ictx->num_key_down > MP_MAX_KEY_DOWN) { mp_tmsg(MSGT_INPUT, MSGL_ERR, "Too many key down events " @@ -1247,12 +1249,12 @@ static mp_cmd_t *interpret_key(struct input_ctx *ictx, int code) } ictx->key_down[ictx->num_key_down] = code; ictx->num_key_down++; - ictx->last_key_down = 1; + emit_key = true; } // Interpret only maximal point of multibutton event - ret = ictx->last_key_down ? - get_cmd_from_keys(ictx, ictx->num_key_down, ictx->key_down) - : NULL; + ret = NULL; + if (emit_key) + ret = get_cmd_from_keys(ictx, ictx->num_key_down, ictx->key_down); if (doubleclick) { ictx->key_down[j] = code - MP_MOUSE_BTN0_DBL + MP_MOUSE_BTN0; return ret; @@ -1275,6 +1277,8 @@ static mp_cmd_t *check_autorepeat(struct input_ctx *ictx) if (ictx->ar_rate > 0 && ictx->ar_state >= 0 && ictx->num_key_down > 0 && !(ictx->key_down[ictx->num_key_down - 1] & MP_NO_REPEAT_KEY)) { unsigned int t = GetTimer(); + if (ictx->last_ar + 2000000 < t) + ictx->last_ar = t; // First time : wait delay if (ictx->ar_state == 0 && (t - ictx->last_key_down) >= ictx->ar_delay * 1000) @@ -1287,12 +1291,12 @@ static mp_cmd_t *check_autorepeat(struct input_ctx *ictx) return NULL; } ictx->ar_state = 1; - ictx->last_ar = t; + ictx->last_ar = ictx->last_key_down + ictx->ar_delay * 1000; return mp_cmd_clone(ictx->ar_cmd); // Then send rate / sec event } else if (ictx->ar_state == 1 && (t - ictx->last_ar) >= 1000000 / ictx->ar_rate) { - ictx->last_ar = t; + ictx->last_ar += 1000000 / ictx->ar_rate; return mp_cmd_clone(ictx->ar_cmd); } } @@ -1303,11 +1307,13 @@ void mp_input_feed_key(struct input_ctx *ictx, int code) { ictx->got_new_events = true; if (code == MP_INPUT_RELEASE_ALL) { + mp_msg(MSGT_INPUT, MSGL_V, "input: release all\n"); memset(ictx->key_down, 0, sizeof(ictx->key_down)); ictx->num_key_down = 0; ictx->last_key_down = 0; return; } + mp_msg(MSGT_INPUT, MSGL_V, "input: key code=%#x\n", code); struct mp_cmd *cmd = interpret_key(ictx, code); if (!cmd) return; @@ -1364,6 +1370,10 @@ static void read_key_fd(struct input_ctx *ictx, struct input_fd *key_fd) */ static void read_events(struct input_ctx *ictx, int time) { + if (ictx->num_key_down) { + time = FFMIN(time, 1000 / ictx->ar_rate); + time = FFMIN(time, ictx->ar_delay); + } ictx->got_new_events = false; struct input_fd *key_fds = ictx->key_fds; struct input_fd *cmd_fds = ictx->cmd_fds; @@ -1779,27 +1789,6 @@ struct input_ctx *mp_input_init(struct input_conf *input_conf, } #endif -#ifdef CONFIG_APPLE_REMOTE - if (input_conf->use_ar) { - if (mp_input_ar_init() < 0) - mp_tmsg(MSGT_INPUT, MSGL_ERR, "Can't init Apple Remote.\n"); - else - mp_input_add_key_fd(ictx, -1, 0, mp_input_ar_read, - mp_input_ar_close, NULL); - } -#endif - -#ifdef CONFIG_APPLE_IR - if (input_conf->use_ar) { - int fd = mp_input_appleir_init(input_conf->ar_dev); - if (fd < 0) - mp_tmsg(MSGT_INPUT, MSGL_ERR, "Can't init Apple Remote.\n"); - else - mp_input_add_key_fd(ictx, fd, 1, mp_input_appleir_read, - close, NULL); - } -#endif - if (input_conf->in_file) { int mode = O_RDONLY; #ifndef __MINGW32__ |