Hello,

Please find attached a small patch extending the existing X11
clipboard handling to OpenBSD.

Under X11, the clipboard contents depend on the process retaining
ownership of the selection.

Codex already preserves the clipboard handle on Linux. This patch
enables the same mechanism on OpenBSD, where arboard also uses X11.

It introduces no new clipboard backend and leaves OSC 52 unchanged.

I have not yet tested the clipboard behavior interactively on OpenBSD.

Thanks,
David.
Index: devel/codex/patches/patch-codex-rs_tui_src_clipboard_copy_rs
===================================================================
RCS file: devel/codex/patches/patch-codex-rs_tui_src_clipboard_copy_rs
diff -N devel/codex/patches/patch-codex-rs_tui_src_clipboard_copy_rs
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ devel/codex/patches/patch-codex-rs_tui_src_clipboard_copy_rs	18 Oct 2026 16:10:35 -0000
@@ -0,0 +1,64 @@
+Keep the existing X11 clipboard lease alive on OpenBSD too. arboard uses
+its Unix/X11 backend here; no new clipboard implementation is introduced.
+
+Index: codex-rs/tui/src/clipboard_copy.rs
+--- codex-rs/tui/src/clipboard_copy.rs.orig
++++ codex-rs/tui/src/clipboard_copy.rs
+@@ -8,7 +8,7 @@
+ //! suppress native copying. Both the host and attached client's clipboards may
+ //! change. Outside tmux, Herdr, and SSH, use OSC 52 only if native copying fails.
+ //!
+-//! On Linux, X11 and some Wayland compositors require the process that wrote the
++//! On Linux and OpenBSD, X11 and some Wayland compositors require the process that wrote the
+ //! clipboard to keep its handle open. `ClipboardLease` wraps the `arboard::Clipboard`
+ //! so the copy worker can retain it for the lifetime of the TUI. On other platforms the lease
+ //! is always `None`.
+@@ -138,19 +138,19 @@ fn copy_to_clipboard(
+ 
+ /// Keeps a platform clipboard owner alive when the backend requires one.
+ ///
+-/// On Linux/X11 and some Wayland compositors, clipboard contents are served by the
++/// On X11 (including OpenBSD) and some Wayland compositors, clipboard contents are served by the
+ /// owning process. Dropping the `arboard::Clipboard` before the user pastes causes
+ /// the content to vanish. Store this lease on a session-lived owner so closing a
+-/// transient overlay does not release the clipboard contents. On non-Linux native paths and OSC 52
++/// transient overlay does not release the clipboard contents. On other native paths and OSC 52
+ /// paths the lease is `None` — those backends do not require process-lifetime
+ /// ownership.
+ pub(crate) struct ClipboardLease {
+-    #[cfg(target_os = "linux")]
++    #[cfg(any(target_os = "linux", target_os = "openbsd"))]
+     _clipboard: Option<arboard::Clipboard>,
+ }
+ 
+ impl ClipboardLease {
+-    #[cfg(target_os = "linux")]
++    #[cfg(any(target_os = "linux", target_os = "openbsd"))]
+     fn native_linux(clipboard: arboard::Clipboard) -> Self {
+         Self {
+             _clipboard: Some(clipboard),
+@@ -160,7 +160,7 @@ impl ClipboardLease {
+     #[cfg(test)]
+     pub(crate) fn test() -> Self {
+         Self {
+-            #[cfg(target_os = "linux")]
++            #[cfg(any(target_os = "linux", target_os = "openbsd"))]
+             _clipboard: None,
+         }
+     }
+@@ -279,12 +279,12 @@ fn arboard_copy(
+         None => clipboard.set_text(text),
+     }
+     .map_err(|e| format!("failed to set clipboard text: {e}"))?;
+-    // Linux clipboard owners must stay alive until the user pastes.
+-    #[cfg(target_os = "linux")]
++    // Linux and OpenBSD clipboard owners must stay alive until the user pastes.
++    #[cfg(any(target_os = "linux", target_os = "openbsd"))]
+     {
+         Ok(Some(ClipboardLease::native_linux(clipboard)))
+     }
+-    #[cfg(not(target_os = "linux"))]
++    #[cfg(not(any(target_os = "linux", target_os = "openbsd")))]
+     {
+         Ok(None)
+     }

Reply via email to