diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-01-16 14:39:44 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-02-12 09:55:50 +0000 |
| commit | 9db9a0d22515f90a75ec09deb900308e7604ad5a (patch) | |
| tree | 55d7dbee91985d48dc2438f09b68476b8b09a617 | |
| parent | selection: 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.
| -rw-r--r-- | config.c | 30 | ||||
| -rw-r--r-- | config.h | 1 | ||||
| -rw-r--r-- | selection.c | 3 |
3 files changed, 22 insertions, 12 deletions
@@ -603,19 +603,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 { @@ -167,6 +167,7 @@ struct config { bool presentation_timings; bool hold_at_exit; enum { + SELECTION_TARGET_NONE, SELECTION_TARGET_PRIMARY, SELECTION_TARGET_CLIPBOARD, SELECTION_TARGET_BOTH diff --git a/selection.c b/selection.c index fd1b1661..2b209ae2 100644 --- a/selection.c +++ b/selection.c @@ -657,6 +657,9 @@ selection_finalize(struct seat *seat, struct terminal *term, uint32_t serial) assert(term->selection.start.row <= term->selection.end.row); switch (term->conf->selection_target) { + case SELECTION_TARGET_NONE: + break; + case SELECTION_TARGET_PRIMARY: selection_to_primary(seat, term, serial); break; |
