repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
quickshell/nugu/ClipboardWidget.qml
Rawimport QtQuick
import QtQuick.Layouts
import Quickshell
import Quickshell.Io
import "."
Item {
id: root
// Bar clipboard preview is intentionally small: it gives Ironbar parity on
// the status bar while the full picker owns search/keyboard selection. The
// storage backend remains cliphist until replacement storage is in scope.
required property QtObject theme
required property QtObject commands
required property var barWindow
property bool open: false
property var entries: []
implicitWidth: button.implicitWidth
implicitHeight: button.implicitHeight
function refresh(): void {
list.exec(["sh", "-c", "cliphist list | head -n 5"])
}
StatusItem {
id: button
theme: root.theme
text: ""
minWidth: 24
active: root.open
onLeftClicked: {
root.open = !root.open
if (root.open) root.refresh()
}
onMiddleClicked: {
root.open = !root.open
if (root.open) root.refresh()
}
}
PopupWindow {
visible: root.open
implicitWidth: 380
implicitHeight: Math.max(56, entries.length * 32 + 18)
color: "transparent"
anchor {
window: root.barWindow
item: button
gravity: Edges.Bottom
adjustment: PopupAdjustment.Slide
}
Rectangle {
anchors.fill: parent
radius: 7
color: root.theme.ui.backdrop
border.width: 2
border.color: root.theme.ui.accent
ColumnLayout {
anchors.fill: parent
anchors.margins: 8
spacing: 4
Repeater {
model: root.entries
Rectangle {
required property var modelData
Layout.fillWidth: true
Layout.preferredHeight: 28
radius: 6
color: mouse.containsMouse ? root.theme.ui.accent : "transparent"
clip: true
Text {
anchors.left: parent.left
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 8
anchors.rightMargin: 8
text: parent.modelData.preview
color: mouse.containsMouse ? root.theme.content.backdrop : root.theme.ui.normal
font.family: "IBM Plex Mono"
font.pixelSize: 12
elide: Text.ElideRight
maximumLineCount: 1
}
MouseArea {
id: mouse
anchors.fill: parent
hoverEnabled: true
onClicked: {
root.commands.copyClipboardEntry(parent.modelData.encoded, parent.modelData.preview)
root.open = false
}
}
}
}
Text {
visible: root.entries.length === 0
text: "clipboard empty"
color: root.theme.ui.minor
font.family: "IBM Plex Mono"
font.pixelSize: 12
}
}
}
}
Process {
id: list
stdout: StdioCollector {
onStreamFinished: {
root.entries = this.text.trim().length === 0 ? [] : this.text.trim().split("\n").map(line => {
const tab = line.indexOf("\t")
const encoded = line
const raw = tab >= 0 ? line.slice(tab + 1) : line
const compact = raw.replace(/\s+/g, " ")
const preview = compact.length > 30 ? `${compact.slice(0, 27)}…` : compact
return { "encoded": encoded, "preview": preview }
})
}
}
}
}