import QtQuick import Quickshell import Quickshell.Wayland import Quickshell.Io import "../Shared" PanelWindow { id: clipboardWindow property QtObject rootState readonly property int headerHeight: 50 readonly property int footerHeight: 24 readonly property int emptyStateHeight: 40 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 { id: backdrop anchors.fill: parent onClicked: rootState.clipboardManagerOpen = false } Surface { id: container width: 800 height: Math.min(600, headerHeight + Theme.geometry.spacing + (clipModel.count > 0 ? clipList.contentHeight : emptyStateHeight) + Theme.geometry.spacing + footerHeight + Theme.geometry.padding * 2) anchors.centerIn: parent tint: Theme.colors.secondary glow: true Behavior on scale { SpringAnimation { spring: Theme.motion.springSoft.spring; damping: Theme.motion.springSoft.damping } } 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: Theme.geometry.spacing TextField { id: searchInput width: parent.width height: clipboardWindow.headerHeight placeholder: "Search clipboard..." onVisibleChanged: { if (visible) focusInput(); } onTextChanged: { loadProcess.restart(); } onEscapePressed: { rootState.clipboardManagerOpen = false; } onUpPressed: { if (clipList.currentIndex > 0) { clipList.currentIndex--; clipList.positionViewAtIndex(clipList.currentIndex, ListView.Contain); } } onDownPressed: { if (clipList.currentIndex < clipList.count - 1) { clipList.currentIndex++; clipList.positionViewAtIndex(clipList.currentIndex, ListView.Contain); } } onReturnPressed: { if (clipList.currentIndex >= 0 && clipList.currentIndex < clipModel.count) { let item = clipModel.get(clipList.currentIndex); copyToClipboard(item.id); } } onDeleteRequested: { if (clipList.currentIndex >= 0 && clipList.currentIndex < clipModel.count) { let item = clipModel.get(clipList.currentIndex); deleteFromClipboard(item.id, item.rawLine, clipList.currentIndex); } } } Text { width: parent.width height: clipboardWindow.emptyStateHeight visible: clipModel.count === 0 verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter text: searchInput.text.length > 0 ? "No clipboard entries match “" + searchInput.text + "”" : "Clipboard is empty" color: Theme.colors.textMuted font.family: Theme.font.family font.pixelSize: Theme.type.body } ListView { id: clipList width: parent.width height: parent.height - clipboardWindow.headerHeight - clipboardWindow.footerHeight - Theme.geometry.spacing * 2 visible: clipModel.count > 0 clip: true spacing: Theme.geometry.spacing / 2 model: ListModel { id: clipModel } delegate: ListRow { id: clipRow width: clipList.width selected: ListView.isCurrentItem accent: Theme.colors.secondary onEntered: clipList.currentIndex = index onClicked: (mouse) => { clipList.currentIndex = index; if (mouse.button === Qt.RightButton) { let pos = mapToItem(backdrop, mouse.x, mouse.y); let itemId = model.id; let rawLine = model.rawLine; let itemIndex = index; contextMenu.model = [ { label: "Copy", icon: "", action: function() { copyToClipboard(itemId); } }, { separator: true }, { label: "Delete", icon: "", destructive: true, action: function() { deleteFromClipboard(itemId, rawLine, itemIndex); } } ]; contextMenu.openAt(pos.x, pos.y); } else { copyToClipboard(model.id); } } Text { text: model.content color: Theme.colors.text font.family: Theme.font.family font.pixelSize: Theme.type.label anchors.left: parent.left anchors.right: deleteButton.left anchors.rightMargin: Theme.geometry.spacing anchors.verticalCenter: parent.verticalCenter verticalAlignment: Text.AlignVCenter elide: Text.ElideRight } Text { id: deleteButton text: "" anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter font.family: Theme.font.family font.pixelSize: Theme.type.body color: deleteMouse.containsMouse ? Theme.colors.alert : Theme.colors.textMuted opacity: clipRow.hovered ? 1 : 0 Behavior on opacity { NumberAnimation { duration: Theme.animation.durationFast } } Behavior on color { ColorAnimation { duration: Theme.animation.durationFast } } MouseArea { id: deleteMouse anchors.fill: parent anchors.margins: -6 hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: deleteFromClipboard(model.id, model.rawLine, index) } } } } HintBar { width: parent.width height: clipboardWindow.footerHeight hints: [ { key: "↵", label: "Copy" }, { key: "Del", label: "Delete" }, { key: "Esc", label: "Close" } ] } } } MouseArea { anchors.fill: parent visible: contextMenu.visible z: 999 onClicked: contextMenu.close() } ContextMenu { id: contextMenu } 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; } } }