From 4f578189cc5ff6cd9be87db8c6b590804a49afa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 16 Jan 2021 15:39:44 +0100 Subject: [PATCH] =?UTF-8?q?config:=20add=20=E2=80=98none=E2=80=99=20as=20a?= =?UTF-8?q?=20possible=20value=20for=20=E2=80=98selection-target=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- config.c | 30 ++++++++++++++++++------------ config.h | 1 + selection.c | 3 +++ 3 files changed, 22 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 { diff --git a/config.h b/config.h index 3dc976e1..1c349f2a 100644 --- a/config.h +++ b/config.h @@ -182,6 +182,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 0c4c6d1b..00292541 100644 --- a/selection.c +++ b/selection.c @@ -1019,6 +1019,9 @@ selection_finalize(struct seat *seat, struct terminal *term, uint32_t serial) xassert(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;