import QtQuick import Quickshell import Quickshell.Wayland import Quickshell.Io import "../Shared" PanelWindow { id: clipboardWindow property QtObject rootState visible: rootState.clipboardManagerOpen anchors { top: true bottom: true left: true right: true } exclusiveZone: 0 color: "transparent" WlrLayershell.layer: WlrLayer.Overlay WlrLayershell.namespace: "quickshell-clipboard" WlrLayershell.keyboardFocus: WlrKeyboardFocus.Exclusive MouseArea { anchors.fill: parent onClicked: rootState.clipboardManagerOpen = false } Rectangle { id: container width: 800 height: Math.min(600, (clipList.count > 0 ? clipList.contentHeight : 0) + (searchInput.text.length > 0 ? 50 + Theme.geometry.spacing : 0) + Theme.geometry.padding * 2) anchors.centerIn: parent radius: Theme.geometry.radius color: Theme.colors.background border.color: Theme.colors.border border.width: 1 Behavior on scale { SpringAnimation { spring: 3; damping: 0.2 } } Behavior on opacity { NumberAnimation { duration: Theme.animation.durationFast } } Behavior on height { NumberAnimation { duration: Theme.animation.durationFast; easing.type: Easing.OutCubic } } opacity: rootState.clipboardManagerOpen ? 1 : 0 MouseArea { anchors.fill: parent } Column { anchors.fill: parent anchors.margins: Theme.geometry.padding spacing: searchInput.text.length > 0 ? Theme.geometry.spacing : 0 Rectangle { width: parent.width height: searchInput.text.length > 0 ? 50 : 0 opacity: searchInput.text.length > 0 ? 1 : 0 clip: true color: Theme.colors.surface radius: Theme.geometry.radius Behavior on height { NumberAnimation { duration: Theme.animation.durationFast } } Behavior on opacity { NumberAnimation { duration: Theme.animation.durationFast } } TextInput { id: searchInput anchors.fill: parent anchors.margins: Theme.geometry.padding verticalAlignment: TextInput.AlignVCenter font.family: Theme.font.family font.pixelSize: 18 color: Theme.colors.text clip: true Text { text: "Search clipboard..." color: Theme.colors.textMuted font.family: Theme.font.family font.pixelSize: 18 anchors.verticalCenter: parent.verticalCenter visible: searchInput.text.length === 0 } onVisibleChanged: { if (visible) forceActiveFocus(); } onTextChanged: { loadProcess.restart(); } Keys.onEscapePressed: (event) => { rootState.clipboardManagerOpen = false; event.accepted = true; } Keys.onUpPressed: (event) => { if (clipList.currentIndex > 0) { clipList.currentIndex--; clipList.positionViewAtIndex(clipList.currentIndex, ListView.Contain); } event.accepted = true; } Keys.onDownPressed: (event) => { if (clipList.currentIndex < clipList.count - 1) { clipList.currentIndex++; clipList.positionViewAtIndex(clipList.currentIndex, ListView.Contain); } event.accepted = true; } Keys.onReturnPressed: (event) => { if (clipList.currentIndex >= 0 && clipList.currentIndex < clipModel.count) { let item = clipModel.get(clipList.currentIndex); copyToClipboard(item.id); } event.accepted = true; } Keys.onPressed: (event) => { if (event.key === Qt.Key_Delete || (event.key === Qt.Key_Backspace && searchInput.text.length === 0)) { if (clipList.currentIndex >= 0 && clipList.currentIndex < clipModel.count) { let item = clipModel.get(clipList.currentIndex); deleteFromClipboard(item.id, item.rawLine, clipList.currentIndex); } event.accepted = true; } } } } ListView { id: clipList width: parent.width height: parent.height - (searchInput.text.length > 0 ? 50 + Theme.geometry.spacing : 0) clip: true spacing: Theme.geometry.spacing model: ListModel { id: clipModel } delegate: Rectangle { width: clipList.width height: 36 color: ListView.isCurrentItem ? Theme.colors.surfaceHover : "transparent" radius: Theme.geometry.radius Item { anchors.fill: parent anchors.leftMargin: Theme.geometry.padding anchors.rightMargin: Theme.geometry.padding Text { text: model.content color: Theme.colors.text font.family: Theme.font.family font.pixelSize: 14 anchors.fill: parent verticalAlignment: Text.AlignVCenter elide: Text.ElideRight } } MouseArea { anchors.fill: parent hoverEnabled: true onEntered: clipList.currentIndex = index onClicked: { clipList.currentIndex = index; copyToClipboard(model.id); } } } } } } Process { id: loadProcess command: [ "bash", "-c", "cliphist list | ( [ -z \"$1\" ] && cat || rg -i \"$1\" ) | head -n 50", "_", searchInput.text ] running: false function restart() { running = false; running = true; } stdout: StdioCollector { onStreamFinished: { let lines = this.text.split('\n').filter(l => l.trim() !== ""); clipModel.clear(); for (let i = 0; i < lines.length; i++) { let firstTab = lines[i].indexOf('\t'); if (firstTab !== -1) { let id = lines[i].substring(0, firstTab); // Clean up newlines for multiline strings natively copied let content = lines[i].substring(firstTab + 1).replace(/\n/g, ' ').replace(/\\n/g, ' '); clipModel.append({ "id": id, "content": content, "rawLine": lines[i] }); } } clipList.currentIndex = 0; } } } Process { id: actionProcess running: false function execute(cmdArray) { command = cmdArray; running = false; running = true; } } function copyToClipboard(id) { actionProcess.execute(["bash", "-c", "cliphist decode '" + id + "' | wl-copy"]); rootState.clipboardManagerOpen = false; } function deleteFromClipboard(id, rawLine, index) { actionProcess.execute(["bash", "-c", "printf '%s\\n' \"$1\" | cliphist delete", "_", rawLine]); clipModel.remove(index); if (clipList.currentIndex >= clipModel.count) { clipList.currentIndex = Math.max(0, clipModel.count - 1); } } onVisibleChanged: { if (visible) { container.scale = 1.0; searchInput.text = ""; clipModel.clear(); loadProcess.restart(); } else { container.scale = 0.95; } } }