summaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2011-06-29 08:49:01 +0300
committerUoti Urpala <uau@mplayer2.org>2011-06-29 08:54:15 +0300
commit4e1e23b2e92a756151d5c919057ad2fdad8996c2 (patch)
treeee32d3cbe91094d422f8e54c0121b5f9c1c5bab5 /input
parent2d187f97509f89faff8a544c05b971a344c9163f (diff)
downloadmpv-4e1e23b2e92a756151d5c919057ad2fdad8996c2.tar.bz2
mpv-4e1e23b2e92a756151d5c919057ad2fdad8996c2.tar.xz
input: clean up messages with button combination names
Previously messages that printed key/button names would have extra names in button combinations appended after the main message, resulting in output like: No bind found for key 'MOUSE_BTN1'.-MOUSE_BTN3 Add a function that creates a complete combination name and use that for all such messages. The above example changes to: No bind found for key 'MOUSE_BTN1-MOUSE_BTN3'. Other affected messages are a input.conf parsing error message and a message about a bound command being invalid.
Diffstat (limited to 'input')
-rw-r--r--input/input.c57
1 files changed, 23 insertions, 34 deletions
diff --git a/input/input.c b/input/input.c
index 7cb498921e..b9c51f14e9 100644
--- a/input/input.c
+++ b/input/input.c
@@ -636,9 +636,8 @@ 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)
+static char *get_key_name(int key, char *ret)
{
- 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+",
@@ -658,6 +657,19 @@ static char *get_key_name(int key)
return talloc_asprintf_append_buffer(ret, "%#-8x", key);
}
+static char *get_key_combo_name(int *keys, int max)
+{
+ char *ret = talloc_strdup(NULL, "");
+ while (1) {
+ ret = get_key_name(*keys, ret);
+ if (--max && *++keys)
+ talloc_asprintf_append_buffer(ret, "-");
+ else
+ break;
+ }
+ return ret;
+}
+
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)
{
@@ -1104,36 +1116,20 @@ 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) {
- char *key_buf = get_key_name(keys[0]);
- mp_tmsg(MSGT_INPUT, MSGL_WARN, "No bind found for key '%s'.", key_buf);
+ char *key_buf = get_key_combo_name(keys, n);
+ mp_tmsg(MSGT_INPUT, MSGL_WARN,
+ "No bind found for key '%s'.\n", key_buf);
talloc_free(key_buf);
- if (n > 1) {
- for (int 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;
}
if (strcmp(cmd, "ignore") == 0)
return NULL;
ret = mp_input_parse_cmd(cmd);
if (!ret) {
- char *key_buf = get_key_name(ictx->key_down[0]);
- mp_tmsg(MSGT_INPUT, MSGL_ERR, "Invalid command for bound key %s",
- key_buf);
+ char *key_buf = get_key_combo_name(keys, n);
+ mp_tmsg(MSGT_INPUT, MSGL_ERR,
+ "Invalid command for bound key '%s': '%s'\n", key_buf, cmd);
talloc_free(key_buf);
- if (ictx->num_key_down > 1) {
- unsigned int s;
- 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);
}
return ret;
}
@@ -1679,17 +1675,10 @@ static int parse_config(struct input_ctx *ictx, char *file)
iter++;
// Found new line
if (iter[0] == '\n' || iter[0] == '\r') {
- int i;
- char *key_buf = get_key_name(keys[0]);
- mp_tmsg(MSGT_INPUT, MSGL_ERR, "No command found for key %s",
- key_buf);
+ char *key_buf = get_key_combo_name(keys, MP_MAX_KEY_DOWN);
+ mp_tmsg(MSGT_INPUT, MSGL_ERR,
+ "No command found for key '%s'.\n", 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) {
memmove(buffer, iter, bs - (iter - buffer));