aboutsummaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-01-16 14:39:44 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-01-23 09:43:59 +0000
commit4f578189cc5ff6cd9be87db8c6b590804a49afa4 (patch)
tree7ba73217a85d7bfe4cfaa92f0beedfbe2b13df10 /config.c
parentselection: copy selected text to the target configured by ‘selection-target’ (diff)
config: add ‘none’ as a possible value for ‘selection-target’
When ‘selection-target’ is set to ‘none’, selecting text does not copy the text to _any_ clipboard. This patch also refactors the value parsing to be data driven.
Diffstat (limited to 'config.c')
-rw-r--r--config.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/config.c b/config.c
index 8e896b4c..fa2646fa 100644
--- a/config.c
+++ b/config.c
@@ -674,19 +674,25 @@ parse_section_main(const char *key, const char *value, struct config *conf,
}
else if (strcmp(key, "selection-target") == 0) {
- if (strcasecmp(value, "primary") == 0)
- conf->selection_target = SELECTION_TARGET_PRIMARY;
- else if (strcasecmp(value, "clipboard") == 0)
- conf->selection_target = SELECTION_TARGET_CLIPBOARD;
- else if (strcasecmp(value, "both") == 0)
- conf->selection_target = SELECTION_TARGET_BOTH;
- else {
- LOG_AND_NOTIFY_ERR(
- "%s:%d: [default]: %s: invalid 'selection-target'; "
- "must be one of 'primary', 'clipboard' or 'both",
- path, lineno, value);
- return false;
+ static const char *const values[] = {
+ [SELECTION_TARGET_NONE] = "none",
+ [SELECTION_TARGET_PRIMARY] = "primary",
+ [SELECTION_TARGET_CLIPBOARD] = "clipboard",
+ [SELECTION_TARGET_BOTH] = "both",
+ };
+
+ for (size_t i = 0; i < ALEN(values); i++) {
+ if (strcasecmp(value, values[i]) == 0) {
+ conf->selection_target = i;
+ return true;
+ }
}
+
+ LOG_AND_NOTIFY_ERR(
+ "%s:%d: [default]: %s: invalid 'selection-target'; "
+ "must be one of 'none', 'primary', 'clipboard' or 'both",
+ path, lineno, value);
+ return false;
}
else {