Files
mxandClaude Opus 5.5 5a10469efe Add Clipboard History as a launcher mode backed by cliphist
The launcher gains a clipboard mode with the same bar, position and size:
the latest five entries show at once and the rest scroll, search filters
in recency order, Enter copies, Shift+Delete removes an entry. >clipboard
switches in place without closing or animating; glassmxrph clipboard
toggles it directly. History stays with the user's cliphist watcher.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 15:16:14 +02:00

70 lines
1.9 KiB
QML

pragma Singleton
import QtQuick
import Quickshell
// Clipboard history from cliphist, for the launcher's clipboard mode. The
// list is read only while the launcher opens; the last result stays cached so
// switching into clipboard mode shows entries immediately.
Singleton {
id: root
// Newest first: {id, text, image?, thumb?}.
property var entries: []
property string error: ""
property bool loaded: false
readonly property bool loading: lister.running
function refresh() {
lister.start({
op: "list"
});
}
// Space-separated terms, all required; recency order is kept like rofi.
function filter(query) {
const terms = query.toLowerCase().split(/\s+/).filter(t => t);
if (!terms.length)
return entries;
return entries.filter(e => {
const text = e.text.toLowerCase();
return terms.every(t => text.includes(t));
});
}
function copy(entry) {
return entry && actions.start({
op: "copy",
id: entry.id
});
}
function remove(entry) {
if (!entry)
return false;
// Optimistic: the row leaves at once; the helper returns the new list.
entries = entries.filter(e => e.id !== entry.id);
return actions.start({
op: "delete",
id: entry.id
});
}
ProviderJob {
id: lister
helper: "helpers/clipboard.py"
onFinished: (request, result) => root.apply(result)
}
ProviderJob {
id: actions
helper: "helpers/clipboard.py"
onFinished: (request, result) => root.apply(result)
}
function apply(result) {
if (!result.ok) {
error = result.error || "Clipboard history is unavailable";
return;
}
error = "";
if (result.entries) {
entries = result.entries;
loaded = true;
}
}
}