Repository navigation
clipboard: bind the first wl_seat only - #3989
Conversation
niri advertises two seats, seat0 and niri-agent. setupRegistry bound every wl_seat it saw, so the second one overwrote m.seat. A data device created on niri-agent is valid and silent: it never receives selection or data_offer events, so clipboard history stops recording while startup still logs a clean "Data device setup complete". Bind the first seat and skip the rest. connectSession already does this for the CLI watcher, which is why `dms clipboard watch` kept working on the same compositor.
TouchEntry routed through storeEntry, which deduplicates the row against itself and assigns a fresh sequence number. The id the panel was holding went stale the moment it was touched, so pasting an entry right after selecting it could serve the previous clipboard content. Rewrite the row in place so the id survives. GetHistory then has to sort by timestamp: key order no longer tracks recency once rows are updated without new keys. The QML list sorts the same way.
|
/claude review |
| if err != nil { | ||
| return err | ||
| } | ||
| return b.Put(itob(id), encoded) |
There was a problem hiding this comment.
A touched entry keeps its old (low) key, but trimLengthInTx still evicts by key order (c.Last()/c.Prev()). With history at MaxHistory, restoring the oldest entry and then copying anything new deletes the entry the user just restored, even though it's now the most recent. Before this change the touch moved it to a new top key, so it survived. trimLengthInTx (and Search, which also lists in key order) need to rank by timestamp too, or touch has to keep re-keying.
| // place to keep its id stable for the UI. | ||
| slices.SortFunc(history, func(a, b Entry) int { | ||
| return b.Timestamp.Compare(a.Timestamp) | ||
| }) |
There was a problem hiding this comment.
Timestamps are stored with one-second resolution (encodeEntry writes Timestamp.Unix()), and slices.SortFunc isn't stable. So two copies made within the same second can come back in either order, and the newest copy may not be at the top. Use ID as the tie-break, since that was the old ordering:
| }) | |
| slices.SortFunc(history, func(a, b Entry) int { | |
| if c := b.Timestamp.Compare(a.Timestamp); c != 0 { | |
| return c | |
| } | |
| return cmp.Compare(b.ID, a.ID) | |
| }) |
(needs cmp imported). ClipboardService.qml should break ties on id the same way.
Claude reviewThe seat fix is good. The in-place touch breaks history trimming and makes the order unreliable for copies made within the same second.
|
TouchEntry rewrites a row in place to keep its id stable for the UI, which breaks the assumption that bucket key order tracks recency. Three places still relied on it: - trimLengthInTx walked the bucket backwards and evicted the lowest keys, so a restored entry was the first casualty of the next copy once history was full. - GetHistory sorted on a second-resolution stamp, leaving rows copied within the same second in bucket order. - GetPinnedEntries never sorted at all, so a restored pinned entry sank to the bottom. Rows now carry nanosecond stamps and every listing sorts through one comparator that falls back to id. Legacy rows keep their second-resolution stamp: the decoder tells the two apart by magnitude, since no second-resolution stamp reaches 1e12 before the year 33658. The QML list mirrors the same tie-break, because JS Date drops sub- millisecond digits.
|
Both points are fixed in 047a2c4.
The unstable sort had a deeper cause than a missing tie-break: While auditing the other callers I found a third one your review did not mention: Two regression tests cover the trim eviction and the same-second ordering. Both fail on the previous commit and pass now: Verified against a copy of a real 152-entry database: legacy rows decode unchanged, new rows store nanoseconds, and three copies in the same second list newest-first. |
|
/claude review |
Claude reviewNo issues found. The follow-up commit fixes both earlier findings: |
port 2.0 (cherry picked from commit df8b1d8)
Description
Clipboard history silently stops recording when the compositor advertises more than one
wl_seat. niri does: it exposesseat0alongside aniri-agentseat.setupRegistrybinds everywl_seatglobal it sees and assigns each one tom.seat, so the last seat wins. A data device created onniri-agentis accepted by the compositor and never delivers aselectionordata_offerevent. Nothing fails, so startup still logs a cleanData device setup completewhile history stays frozen.Measured on niri with the same binary, changing only which seat is bound:
seat0(first)niri-agent(last, current behaviour)id == nilcore/internal/clipboard/wl.goalready guards against this for the CLI watcher (if s.seat != nil { return }), which is whydms clipboard watchkeeps working on an affected compositor while the daemon's history does not. The manager was missing the same guard.The second commit fixes an unrelated defect in the same path.
TouchEntryrouted throughstoreEntry, which deduplicates the row against itself and assigns a fresh sequence number. The id the panel was holding went stale as soon as an entry was touched, so restoring an entry could serve the previous clipboard content. The row is now rewritten in place, which meansGetHistoryhas to sort by timestamp rather than relying on key order.Fixes #3812, though the root cause there was misattributed to the shared wayland dispatcher at the time and the issue was closed before it was found.
A third commit answers review feedback on the in-place update. Rewriting a row without touching its key broke the assumption that bucket key order tracks recency, which
trimLengthInTxandGetPinnedEntriesleaned on. Rows now store nanosecond stamps, every listing shares one comparator that falls back to id, andtrimLengthInTxranks by that comparator instead of walking keys backwards. Legacy rows keep decoding at second resolution, told apart by magnitude.Type of change
Related issues
Fixes #3812
Screenshots / video
Not a visual change. Verification below.
Verification
Built and ran against niri, which advertises both seats.
Three consecutive copies now appear in
dms clipboard history, newest first. Restoring an entry keeps its id, so a paste immediately after selecting from the panel serves the selected entry.make testpassesmake fmtproduces no diffgo build ./...cleanChecklist
I18n.tr()with translator context, reusing existing terms where possiblemake fmt, added/updated tests,make testpasses, andgo mod tidyis cleanmake lint-qmlwith no new warningsThe QML change is a sort comparator swap on an existing array, with no new strings or user-visible behaviour beyond ordering. No docs change applies: this restores documented behaviour rather than adding any.