Simplify clipboard watcher lifecycle with pdeathsig

Replace the three-layer process management (trap cleanup, PPID-polling
watchdog subshell, /proc-scanning reaper) with kernel-level lifetime
binding: each wl-paste watcher is spawned under setpriv --pdeathsig TERM,
so it dies with the shell no matter how the shell exits.

- Delete watch.sh: the shell now spawns both watchers directly as
  declarative Process commands instead of a wrapper script with traps
  and a 1s polling loop
- Delete init.sh: reaping stale watchers from a crashed pre-pdeathsig
  shell is a single pkill at startup
- Collapse capture.sh's dual stream/snapshot modes: wl-paste forwards
  arguments to its watch command, so the mime rides along as $1 instead
  of an env var, letting both modes share one emit_image function
- Turn the six-branch image mime chain into a loop

Net: two fewer files, three fewer runtime processes, and the watch-mode
capture tests now exercise the same argument protocol the shell uses.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
David Heinemeier Hansson
2026-07-02 21:32:30 -07:00
co-authored by Claude Fable 5
parent 055ffaccd4
commit 60e0a2a0cd
5 changed files with 72 additions and 180 deletions
+17 -7
View File
@@ -19,8 +19,6 @@ Item {
property string historyPath: Quickshell.env("HOME") + "/.local/state/omarchy/clipboard-history.json"
property string captureScript: root.omarchyPath + "/shell/plugins/clipboard/capture.sh"
property string initScript: root.omarchyPath + "/shell/plugins/clipboard/init.sh"
property string watchScript: root.omarchyPath + "/shell/plugins/clipboard/watch.sh"
// Shares the [menu] surface tokens — themes that style the menu also
// style the clipboard. Selected-row colors composed in the
// singleton so consumers drop them straight into Rectangle bindings.
@@ -260,19 +258,22 @@ Item {
onFileChanged: reload()
}
// Reap watchers left behind by a previous shell instance, then start our
// own. The pdeathsig on the watchers makes the kernel kill them whenever
// the shell exits, however it exits, so no further lifecycle management.
Process {
id: initProc
command: [root.initScript, root.captureScript]
command: ["pkill", "-f", "wl-paste .*--watch .*/shell/plugins/clipboard/capture\\.sh"]
onExited: {
currentProc.command = [root.captureScript]
currentProc.running = true
watchProc.command = [root.watchScript, root.captureScript]
watchProc.running = true
textWatchProc.running = true
imageWatchProc.running = true
}
}
Process {
id: currentProc
command: [root.captureScript]
stdout: StdioCollector {
waitForEnd: true
onStreamFinished: root.addClipboardJson(text)
@@ -280,7 +281,16 @@ Item {
}
Process {
id: watchProc
id: textWatchProc
command: ["setpriv", "--pdeathsig", "TERM", "wl-paste", "--type", "text", "--watch", root.captureScript, "text"]
stdout: SplitParser {
onRead: function(data) { root.addClipboardJson(data) }
}
}
Process {
id: imageWatchProc
command: ["setpriv", "--pdeathsig", "TERM", "wl-paste", "--type", "image/png", "--watch", root.captureScript, "image/png"]
stdout: SplitParser {
onRead: function(data) { root.addClipboardJson(data) }
}