From e69ca255b03cf71c07d39747510f3ff82e8f98ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 16 Jan 2021 11:26:03 +0100 Subject: [PATCH 1/6] =?UTF-8?q?config:=20add=20new=20option=20=E2=80=98sel?= =?UTF-8?q?ection-target=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This option controls the clipboard target that selected text should be copied to. --- config.c | 17 +++++++++++++++++ config.h | 5 +++++ foot.ini | 1 + 3 files changed, 23 insertions(+) diff --git a/config.c b/config.c index da55f8f8..8e896b4c 100644 --- a/config.c +++ b/config.c @@ -673,6 +673,22 @@ parse_section_main(const char *key, const char *value, struct config *conf, conf->notify.argv = argv; } + 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; + } + } + else { LOG_AND_NOTIFY_ERR("%s:%u: [default]: %s: invalid key", path, lineno, key); return false; @@ -2127,6 +2143,7 @@ config_load(struct config *conf, const char *conf_path, .render_worker_count = sysconf(_SC_NPROCESSORS_ONLN), .server_socket_path = get_server_socket_path(), .presentation_timings = false, + .selection_target = SELECTION_TARGET_PRIMARY, .hold_at_exit = false, .notify = { .raw_cmd = NULL, diff --git a/config.h b/config.h index 2bae8d31..3dc976e1 100644 --- a/config.h +++ b/config.h @@ -181,6 +181,11 @@ struct config { char *server_socket_path; bool presentation_timings; bool hold_at_exit; + enum { + SELECTION_TARGET_PRIMARY, + SELECTION_TARGET_CLIPBOARD, + SELECTION_TARGET_BOTH + } selection_target; struct { char *raw_cmd; diff --git a/foot.ini b/foot.ini index 330b4b7f..19a82061 100644 --- a/foot.ini +++ b/foot.ini @@ -23,6 +23,7 @@ # bell=none # word-delimiters=,│`|:"'()[]{}<> # notify=notify-send -a foot -i foot ${title} ${body} +# selection-target=primary # workers= [scrollback] From 07f6b3b1af2ad9a492efe81c867cd033ae22f12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 16 Jan 2021 11:26:45 +0100 Subject: [PATCH 2/6] =?UTF-8?q?selection:=20copy=20selected=20text=20to=20?= =?UTF-8?q?the=20target=20configured=20by=20=E2=80=98selection-target?= =?UTF-8?q?=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #288 --- selection.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/selection.c b/selection.c index 966b6b2a..0c4c6d1b 100644 --- a/selection.c +++ b/selection.c @@ -1017,7 +1017,20 @@ selection_finalize(struct seat *seat, struct terminal *term, uint32_t serial) } xassert(term->selection.start.row <= term->selection.end.row); - selection_to_primary(seat, term, serial); + + switch (term->conf->selection_target) { + case SELECTION_TARGET_PRIMARY: + selection_to_primary(seat, term, serial); + break; + case SELECTION_TARGET_CLIPBOARD: + selection_to_clipboard(seat, term, serial); + break; + + case SELECTION_TARGET_BOTH: + selection_to_primary(seat, term, serial); + selection_to_clipboard(seat, term, serial); + break; + } } void 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 3/6] =?UTF-8?q?config:=20add=20=E2=80=98none=E2=80=99=20as?= =?UTF-8?q?=20a=20possible=20value=20for=20=E2=80=98selection-target?= =?UTF-8?q?=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; From 821935e5affd3499fe2789dfe4387a5333d1dab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 16 Jan 2021 15:44:51 +0100 Subject: [PATCH 4/6] changelog: selection-target=none|primary|clipboard|both --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27cc543b..709ee757 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,11 @@ selection mode to 'character-wise' when extending a selection. * `DECSET` `47`, `1047` and `1048`. * FreeBSD support (https://codeberg.org/dnkl/foot/issues/238). +* `selection-target=none|primary|clipboard|both` to `foot.ini`. It can + be used to configure which clipboard(s) selected text should be + copied to. The default is `primary`, which corresponds to the + behavior in older foot releases + (https://codeberg.org/dnkl/foot/issues/288). ### Changed From b8685e17ea96bd6bfd3f47b6659089db31920b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 20 Jan 2021 17:56:14 +0100 Subject: [PATCH 5/6] doc: foot.ini: selection-target=none|primary|clipboard|both --- doc/foot.ini.5.scd | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index c78ad7bc..180ac7c2 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -161,12 +161,6 @@ in this order: compositor can use this value to e.g. group multiple windows, or apply window management rules. Default: _foot_. -*workers* - Number of threads to use for rendering. Set to 0 to disable - multithreading. Default: the number of available logical CPUs - (including SMT). Note that this is not always the best value. In - some cases, the number of physical _cores_ is better. - *bold-text-in-bright* Boolean. When enabled, bold text is rendered in a brighter color (in addition to using a bold font). Default: _no_. @@ -212,6 +206,17 @@ in this order: Default: _notify-send -a foot -i foot ${title} ${body}_. +*selection-target* + Clipboard target to automatically copy selected text to. One of + *none*, *primary*, *clipboard* or *both*. Default: _primary_. + + +*workers* + Number of threads to use for rendering. Set to 0 to disable + multithreading. Default: the number of available logical CPUs + (including SMT). Note that this is not always the best value. In + some cases, the number of physical _cores_ is better. + # SECTION: scrollback From 3d60600897f13b47407bf3932ff037f9f1c2783e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 20 Jan 2021 17:57:44 +0100 Subject: [PATCH 6/6] =?UTF-8?q?config:=20selection-target:=20space-optimiz?= =?UTF-8?q?e=20the=20static=20=E2=80=98value=E2=80=99=20array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.c b/config.c index fa2646fa..81b329cf 100644 --- a/config.c +++ b/config.c @@ -674,7 +674,7 @@ parse_section_main(const char *key, const char *value, struct config *conf, } else if (strcmp(key, "selection-target") == 0) { - static const char *const values[] = { + static const char values[][12] = { [SELECTION_TARGET_NONE] = "none", [SELECTION_TARGET_PRIMARY] = "primary", [SELECTION_TARGET_CLIPBOARD] = "clipboard",