aboutsummaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-11-06 18:29:23 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-11-06 18:30:05 +0000
commit9ce79e2ef0b0b19b06990302807d6c3b3a755e1e (patch)
treeab5f6821303de10a53f465599fc7e9df59b2a5f2 /config.c
parentconfig: mouse combos: set count=1 if user has omitted click count (diff)
config: add support for pipe-* actions in mouse bindings
Closes #183
Diffstat (limited to 'config.c')
-rw-r--r--config.c56
1 files changed, 52 insertions, 4 deletions
diff --git a/config.c b/config.c
index c460c987..bb8324db 100644
--- a/config.c
+++ b/config.c
@@ -1470,8 +1470,13 @@ has_mouse_binding_collisions(struct config *conf, const key_combo_list_t *key_co
bool count = it->item.count == it2->item.m.count;
if (shift && alt && ctrl && meta && button && count) {
+ bool has_pipe = it->item.pipe.cmd != NULL;
+ LOG_AND_NOTIFY_ERR("%s:%d: %s already mapped to '%s%s%s%s'",
path, lineno, it2->item.text,
- binding_action_map[it->item.action]);
+ binding_action_map[it->item.action],
+ has_pipe ? " [" : "",
+ has_pipe ? it->item.pipe.cmd : "",
+ has_pipe ? "]" : "");
return true;
}
}
@@ -1486,6 +1491,17 @@ parse_section_mouse_bindings(
const char *key, const char *value, struct config *conf,
const char *path, unsigned lineno)
{
+ char *pipe_cmd;
+ char **pipe_argv;
+
+ ssize_t pipe_remove_len = pipe_argv_from_string(
+ value, &pipe_cmd, &pipe_argv, conf, path, lineno);
+
+ if (pipe_remove_len < 0)
+ return false;
+
+ value += pipe_remove_len;
+
for (enum bind_action_normal action = 0;
action < BIND_ACTION_COUNT;
action++)
@@ -1502,9 +1518,16 @@ parse_section_mouse_bindings(
/* Unset binding */
if (strcasecmp(value, "none") == 0) {
tll_foreach(conf->bindings.mouse, it) {
- if (it->item.action == action)
+ if (it->item.action == action) {
+ if (it->item.pipe.master_copy) {
+ free(it->item.pipe.cmd);
+ free(it->item.pipe.argv);
+ }
tll_remove(conf->bindings.mouse, it);
+ }
}
+ free(pipe_argv);
+ free(pipe_cmd);
return true;
}
@@ -1512,26 +1535,43 @@ parse_section_mouse_bindings(
if (!parse_mouse_combos(conf, value, &key_combos, path, lineno) ||
has_mouse_binding_collisions(conf, &key_combos, path, lineno))
{
+ free(pipe_argv);
+ free(pipe_cmd);
free_key_combo_list(&key_combos);
return false;
}
/* Remove existing bindings for this action */
tll_foreach(conf->bindings.mouse, it) {
- if (it->item.action == action) {
+ if (it->item.action == action &&
+ ((it->item.pipe.argv == NULL && pipe_argv == NULL) ||
+ (it->item.pipe.argv != NULL && pipe_argv != NULL &&
+ argv_compare(it->item.pipe.argv, pipe_argv) == 0)))
+ {
+ if (it->item.pipe.master_copy) {
+ free(it->item.pipe.cmd);
+ free(it->item.pipe.argv);
+ }
tll_remove(conf->bindings.mouse, it);
}
}
/* Emit mouse bindings */
+ bool first = true;
tll_foreach(key_combos, it) {
struct config_mouse_binding binding = {
.action = action,
.modifiers = it->item.modifiers,
.button = it->item.m.button,
.count = it->item.m.count,
+ .pipe = {
+ .cmd = pipe_cmd,
+ .argv = pipe_argv,
+ .master_copy = first,
+ },
};
tll_push_back(conf->bindings.mouse, binding);
+ first = false;
}
free_key_combo_list(&key_combos);
@@ -1539,6 +1579,8 @@ parse_section_mouse_bindings(
}
LOG_AND_NOTIFY_ERR("%s:%u: [mouse-bindings]: %s: invalid key", path, lineno, key);
+ free(pipe_argv);
+ free(pipe_cmd);
return false;
}
@@ -1937,7 +1979,7 @@ add_default_mouse_bindings(struct config *conf)
do { \
tll_push_back( \
conf->bindings.mouse, \
- ((struct config_mouse_binding){action, mods, btn, count})); \
+ ((struct config_mouse_binding){action, mods, btn, count, {0}})); \
} while (0)
const struct config_key_modifiers none = {0};
@@ -2133,6 +2175,12 @@ config_free(struct config conf)
free(it->item.pipe.argv);
}
}
+ tll_foreach(conf.bindings.mouse, it) {
+ if (it->item.pipe.master_copy) {
+ free(it->item.pipe.cmd);
+ free(it->item.pipe.argv);
+ }
+ }
tll_free(conf.bindings.key);
tll_free(conf.bindings.mouse);