summaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
authorUoti Urpala <uau@glyph.nonexistent.invalid>2010-12-20 19:17:43 +0200
committerUoti Urpala <uau@glyph.nonexistent.invalid>2010-12-20 19:17:43 +0200
commit0afb326035e66663a90c4609f21560ce772e9718 (patch)
tree07f443e2bd39745ac7430cff9534529958be9c53 /input
parent4a26b4c024498c9b1be4723121d86e0c2b386ed2 (diff)
parent5bb2f9787f557bd91d5eb9021238ed7b131d5fa9 (diff)
downloadmpv-0afb326035e66663a90c4609f21560ce772e9718.tar.bz2
mpv-0afb326035e66663a90c4609f21560ce772e9718.tar.xz
Merge branch 'hr-seek'
* hr-seek: input: add default keybindings Shift+[arrow] for small exact seeks input: support bindings with modifier keys for X input core: audio: make ogg missing audio timing workaround more complex core: add support for precise non-keyframe-limited seeks core: add struct for queued seek info commands: add generic option -> property wrapper options: add "choice" option type, use for -pts-association-mode core: remove looping in update_video(), modify command handling a bit core: seek: use accurate seek mode with audio-only files core: avoid using sh_video->pts as "current pts" libvo: register X11 connection fd in input event system core: timing: add special handling of long frame intervals core: move central play loop to a separate function Conflicts: DOCS/tech/slave.txt
Diffstat (limited to 'input')
-rw-r--r--input/input.c143
1 files changed, 94 insertions, 49 deletions
diff --git a/input/input.c b/input/input.c
index ab534968e3..dd4a27d63c 100644
--- a/input/input.c
+++ b/input/input.c
@@ -45,6 +45,7 @@
#include "path.h"
#include "talloc.h"
#include "options.h"
+#include "bstr.h"
#include "joystick.h"
@@ -86,7 +87,7 @@ static const mp_cmd_t mp_cmds[] = {
{ MP_CMD_RADIO_SET_FREQ, "radio_set_freq", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
{ MP_CMD_RADIO_STEP_FREQ, "radio_step_freq", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
#endif
- { MP_CMD_SEEK, "seek", 1, { {MP_CMD_ARG_FLOAT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
+ { MP_CMD_SEEK, "seek", 1, { {MP_CMD_ARG_FLOAT,{0}}, {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
{ MP_CMD_EDL_MARK, "edl_mark", 0, { {-1,{0}} } },
{ MP_CMD_AUDIO_DELAY, "audio_delay", 1, { {MP_CMD_ARG_FLOAT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
{ MP_CMD_SPEED_INCR, "speed_incr", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
@@ -361,6 +362,16 @@ static const mp_key_name_t key_names[] = {
{ 0, NULL }
};
+struct mp_key_name modifier_names[] = {
+ { KEY_MODIFIER_SHIFT, "Shift" },
+ { KEY_MODIFIER_CTRL, "Ctrl" },
+ { KEY_MODIFIER_ALT, "Alt" },
+ { KEY_MODIFIER_META, "Meta" },
+ { 0 }
+};
+
+#define KEY_MODIFIER_MASK (KEY_MODIFIER_SHIFT | KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_META)
+
// This is the default binding. The content of input.conf overrides these.
// The first arg is a null terminated array of key codes.
// The second is the command
@@ -385,8 +396,12 @@ static const mp_cmd_bind_t def_cmd_binds[] = {
{ { KEY_RIGHT, 0 }, "seek 10" },
{ { KEY_LEFT, 0 }, "seek -10" },
+ { { KEY_MODIFIER_SHIFT + KEY_RIGHT, 0 }, "seek 1 0 1" },
+ { { KEY_MODIFIER_SHIFT + KEY_LEFT, 0 }, "seek -1 0 1" },
{ { KEY_UP, 0 }, "seek 60" },
{ { KEY_DOWN, 0 }, "seek -60" },
+ { { KEY_MODIFIER_SHIFT + KEY_UP, 0 }, "seek 5 0 1" },
+ { { KEY_MODIFIER_SHIFT + KEY_DOWN, 0 }, "seek -5 0 1" },
{ { KEY_PAGE_UP, 0 }, "seek 600" },
{ { KEY_PAGE_DOWN, 0 }, "seek -600" },
{ { '+', 0 }, "audio_delay 0.100" },
@@ -621,8 +636,27 @@ static const m_option_t mp_input_opts[] = {
static int default_cmd_func(int fd,char* buf, int l);
-static char *get_key_name(int key, char buffer[12]);
+static char *get_key_name(int key)
+{
+ char *ret = talloc_strdup(NULL, "");
+ for (int i = 0; modifier_names[i].name; i++) {
+ if (modifier_names[i].key & key) {
+ ret = talloc_asprintf_append_buffer(ret, "%s+",
+ modifier_names[i].name);
+ key -= modifier_names[i].key;
+ }
+ }
+ for (int i = 0; key_names[i].name != NULL; i++) {
+ if (key_names[i].key == key)
+ return talloc_asprintf_append_buffer(ret, "%s", key_names[i].name);
+ }
+
+ if (isascii(key))
+ return talloc_asprintf_append_buffer(ret, "%c", key);
+ // Print the hex key code
+ return talloc_asprintf_append_buffer(ret, "%#-8x", key);
+}
int mp_input_add_cmd_fd(struct input_ctx *ictx, int fd, int select,
mp_cmd_func_t read_func, mp_close_func_t close_func)
@@ -1035,7 +1069,6 @@ static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, int n, int *keys)
{
char* cmd = NULL;
mp_cmd_t* ret;
- char key_buf[12];
if (ictx->cmd_binds)
cmd = find_bind_for_key(ictx->cmd_binds, n, keys);
@@ -1045,12 +1078,16 @@ static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, int n, int *keys)
cmd = find_bind_for_key(def_cmd_binds,n,keys);
if(cmd == NULL) {
- mp_tmsg(MSGT_INPUT,MSGL_WARN,"No bind found for key '%s'.", get_key_name(keys[0],
- key_buf));
+ char *key_buf = get_key_name(keys[0]);
+ mp_tmsg(MSGT_INPUT,MSGL_WARN,"No bind found for key '%s'.", key_buf);
+ talloc_free(key_buf);
if(n > 1) {
int s;
- for(s=1; s < n; s++)
- mp_msg(MSGT_INPUT,MSGL_WARN,"-%s", get_key_name(keys[s], key_buf));
+ for(s=1; s < n; s++) {
+ key_buf = get_key_name(keys[s]);
+ mp_msg(MSGT_INPUT,MSGL_WARN,"-%s", key_buf);
+ talloc_free(key_buf);
+ }
}
mp_msg(MSGT_INPUT,MSGL_WARN," \n");
return NULL;
@@ -1058,13 +1095,16 @@ static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, int n, int *keys)
if (strcmp(cmd, "ignore") == 0) return NULL;
ret = mp_input_parse_cmd(cmd);
if(!ret) {
- mp_tmsg(MSGT_INPUT,MSGL_ERR,"Invalid command for bound key %s",
- get_key_name(ictx->key_down[0], key_buf));
+ char *key_buf = get_key_name(ictx->key_down[0]);
+ mp_tmsg(MSGT_INPUT,MSGL_ERR,"Invalid command for bound key %s", key_buf);
+ talloc_free(key_buf);
if (ictx->num_key_down > 1) {
unsigned int s;
- for(s=1; s < ictx->num_key_down; s++)
- mp_msg(MSGT_INPUT,MSGL_ERR,"-%s", get_key_name(ictx->key_down[s],
- key_buf));
+ for(s=1; s < ictx->num_key_down; s++) {
+ char *key_buf = get_key_name(ictx->key_down[s]);
+ mp_msg(MSGT_INPUT,MSGL_ERR,"-%s", key_buf);
+ talloc_free(key_buf);
+ }
}
mp_msg(MSGT_INPUT,MSGL_ERR," : %s \n",cmd);
}
@@ -1077,6 +1117,14 @@ static mp_cmd_t* interpret_key(struct input_ctx *ictx, int code)
unsigned int j;
mp_cmd_t* ret;
+ /* On normal keyboards shift changes the character code of non-special
+ * keys, so don't count the modifier separately for those. In other words
+ * 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.
+ */
+ if ((code & ~KEY_MODIFIER_MASK) < 256)
+ code &= ~KEY_MODIFIER_SHIFT;
+
if(mp_input_key_cb) {
if (code & MP_KEY_DOWN)
return NULL;
@@ -1372,41 +1420,34 @@ mp_cmd_clone(mp_cmd_t* cmd) {
return ret;
}
-static char *get_key_name(int key, char buffer[12])
+int mp_input_get_key_from_name(const char *name)
{
- int i;
-
- for(i = 0; key_names[i].name != NULL; i++) {
- if(key_names[i].key == key)
- return key_names[i].name;
- }
-
- if(isascii(key)) {
- snprintf(buffer, 12, "%c",(char)key);
- return buffer;
- }
-
- // Print the hex key code
- snprintf(buffer, 12, "%#-8x",key);
- return buffer;
-
-}
-
-int
-mp_input_get_key_from_name(const char *name) {
- int i,ret = 0,len = strlen(name);
- if(len == 1) { // Direct key code
- ret = (unsigned char)name[0];
- return ret;
- } else if(len > 2 && strncasecmp("0x",name,2) == 0)
- return strtol(name,NULL,16);
-
- for(i = 0; key_names[i].name != NULL; i++) {
- if(strcasecmp(key_names[i].name,name) == 0)
- return key_names[i].key;
- }
+ int modifiers = 0;
+ const char *p;
+ while (p = strchr(name, '+')) {
+ for (struct mp_key_name *m = modifier_names; m->name; m++)
+ if (!bstrcasecmp(BSTR(m->name), (struct bstr){name, p - name})) {
+ modifiers |= m->key;
+ goto found;
+ }
+ if (!strcmp(name, "+"))
+ return '+' + modifiers;
+ return -1;
+ found:
+ name = p + 1;
+ }
+ int len = strlen(name);
+ if (len == 1) // Direct key code
+ return (unsigned char)name[0] + modifiers;
+ else if (len > 2 && strncasecmp("0x", name, 2) == 0)
+ return strtol(name, NULL, 16) + modifiers;
+
+ for (int i = 0; key_names[i].name != NULL; i++) {
+ if (strcasecmp(key_names[i].name, name) == 0)
+ return key_names[i].key + modifiers;
+ }
- return -1;
+ return -1;
}
static int get_input_from_name(char* name,int* keys) {
@@ -1589,10 +1630,14 @@ static int parse_config(struct input_ctx *ictx, char *file)
// Found new line
if(iter[0] == '\n' || iter[0] == '\r') {
int i;
- char key_buf[12];
- mp_tmsg(MSGT_INPUT,MSGL_ERR,"No command found for key %s", get_key_name(keys[0], key_buf));
- for(i = 1; keys[i] != 0 ; i++)
- mp_msg(MSGT_INPUT,MSGL_ERR,"-%s", get_key_name(keys[i], key_buf));
+ char *key_buf = get_key_name(keys[0]);
+ mp_tmsg(MSGT_INPUT,MSGL_ERR,"No command found for key %s", key_buf);
+ talloc_free(key_buf);
+ for(i = 1; keys[i] != 0 ; i++) {
+ char *key_buf = get_key_name(keys[i]);
+ mp_msg(MSGT_INPUT,MSGL_ERR,"-%s", key_buf);
+ talloc_free(key_buf);
+ }
mp_msg(MSGT_INPUT,MSGL_ERR,"\n");
keys[0] = 0;
if(iter > buffer) {