commit b744fad45884ce0c27156ba815809a56b1f468fc
Author: mrfox <jens.se@icloud.com>
AuthorDate: Fri Sep 18 21:49:12 2026 +0200
Commit: mrfox <jens.se@icloud.com>
CommitDate: Fri Sep 18 21:49:12 2026 +0200
st: don't overwrite CLIPBOARD with empty selections
03-clipboard called xclipcopy() on every finished selection, so a click
that jittered or a drag over blank cells replaced whatever was copied in
e.g. Firefox with a lone newline before it could be pasted. Only copy to
CLIPBOARD when the selection has non-whitespace text.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
---
README.md | 2 +-
st-patches/03-clipboard.patch | 22 +++++++++++++++++++---
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index a778ba4..91a1328 100644
--- a/README.md
+++ b/README.md
@@ -172,7 +172,7 @@ building, in order — all sourced from [st.suckless.org/patches](https://st.suc
|---|---|
| [`01-delkey.patch`](st-patches/01-delkey.patch) | Fixes the Delete key to send `\033[3~` instead of the legacy `\033[P` |
| [`02-scrollback.patch`](st-patches/02-scrollback.patch) | Keyboard (`Shift+PageUp/Down`) and mouse-wheel scrollback, disabled in the alt screen (vim, less, etc.) |
-| [`03-clipboard.patch`](st-patches/03-clipboard.patch) | Selecting text also copies it to the `CLIPBOARD` selection, not just `PRIMARY` |
+| [`03-clipboard.patch`](st-patches/03-clipboard.patch) | Selecting text also copies it to the `CLIPBOARD` selection, not just `PRIMARY`. Local fix on top of the upstream patch: empty/whitespace-only selections (a jittery click, dragging over blank cells) no longer overwrite `CLIPBOARD`, which used to wipe what you'd just copied in e.g. Firefox before you could paste it |
| [`04-boxdraw.patch`](st-patches/04-boxdraw.patch) | Renders box-drawing/braille characters natively instead of relying on the font |
| [`05-vertcenter.patch`](st-patches/05-vertcenter.patch) | Vertically centers glyphs that don't fill the cell (pairs with boxdraw) |
| [`06-alpha.patch`](st-patches/06-alpha.patch) | Background transparency (`-A`/`alpha`), needs a compositor |
diff --git a/st-patches/03-clipboard.patch b/st-patches/03-clipboard.patch
index 6f20da9..c7e27dd 100644
--- a/st-patches/03-clipboard.patch
+++ b/st-patches/03-clipboard.patch
@@ -1,13 +1,29 @@
diff --git a/x.c b/x.c
-index f0c0837..7d01e1b 100644
+index f0c0837..5fba5db 100644
--- a/x.c
+++ b/x.c
-@@ -688,6 +688,8 @@ setsel(char *str, Time t)
+@@ -679,6 +679,8 @@ selrequest(XEvent *e)
+ void
+ setsel(char *str, Time t)
+ {
++ char *p;
++
+ if (!str)
+ return;
+
+@@ -688,6 +690,15 @@ setsel(char *str, Time t)
XSetSelectionOwner(xw.dpy, XA_PRIMARY, xw.win, t);
if (XGetSelectionOwner(xw.dpy, XA_PRIMARY) != xw.win)
selclear();
+
-+ xclipcopy();
++ /* an empty or whitespace-only selection (a click that jittered, a
++ * drag over blank cells) must not overwrite CLIPBOARD */
++ for (p = str; *p; p++) {
++ if (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\r') {
++ xclipcopy();
++ break;
++ }
++ }
}
void