diff options
| author | CismonX <admin@cismon.net> | 2026-05-20 18:38:16 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2026-05-22 09:49:46 +0000 |
| commit | 4bf60d0fbcad533c5131288617caae67342c1065 (patch) | |
| tree | 9c46c6fd5483be42237abe552e8b204465cfe613 | |
| parent | csi: DECCRA: clamp and verify destination rectangle coordinates (diff) | |
selection: do not copy empty text
Copy-on-select (configured with 'selection-target') may accidentally
clear the clipboard, if the user drags the mouse a little bit when
clicking inside a terminal window.
Now we only copy if there is actual text being selected.
Closes #2327
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | selection.c | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 93f80251..464f096f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,9 +81,11 @@ content ([#2353][2353]). * DECCRA not clamping or verifying the destination rectangle ([#2352][2352]). +* Empty selection clearing the clipboard ([#2327][2327]). [2353]: https://codeberg.org/dnkl/foot/issues/2353 [2352]: https://codeberg.org/dnkl/foot/issues/2352 +[2327]: https://codeberg.org/dnkl/foot/issues/2327 ### Security diff --git a/selection.c b/selection.c index 0a479ee8..bb0d3f1b 100644 --- a/selection.c +++ b/selection.c @@ -1948,6 +1948,9 @@ static const struct zwp_primary_selection_source_v1_listener primary_selection_s bool text_to_clipboard(struct seat *seat, struct terminal *term, char *text, uint32_t serial) { + if (text == NULL || text[0] == '\0') + return false; + xassert(serial != 0); struct wl_clipboard *clipboard = &seat->clipboard; @@ -2418,6 +2421,9 @@ selection_from_clipboard(struct seat *seat, struct terminal *term, uint32_t seri bool text_to_primary(struct seat *seat, struct terminal *term, char *text, uint32_t serial) { + if (text == NULL || text[0] == '\0') + return false; + if (term->wl->primary_selection_device_manager == NULL) return false; |
