Files
2026-10-16 14:28:25 -04:00

65 lines
2.3 KiB
QML

import QtQuick
import Quickshell
// One monitor's badges, one in each bottom corner, and the editor they open.
Scope {
id: root
required property ShellScreen modelData
required property Compositor compositor
required property ColorStore store
required property Theme theme
// The workspace active on this monitor, or null when unknown.
// An entry from Compositor.outputs, so this stays untyped.
readonly property var info: root.compositor.outputs[root.modelData.name] ?? null
readonly property int wsId: root.info ? root.info.id : -1
readonly property int wsIdx: root.info ? root.info.idx : -1
readonly property string wsName: root.info ? root.info.name : ""
// Workspaces without a name show their number.
readonly property string label: root.wsName.length > 0 ? root.wsName : String(root.wsIdx)
readonly property string colorKey: root.store.keyFor(root.wsId, root.wsName)
readonly property color wsColor: root.store.colorFor(root.colorKey)
readonly property real wsOpacity: root.store.opacityFor(root.colorKey)
// Rough brightness of the color, so the text can stay readable on it.
readonly property bool lightColor: 0.299 * root.wsColor.r + 0.587 * root.wsColor.g + 0.114 * root.wsColor.b > 0.6
function openEditor(): void {
if (!root.info)
return;
popup.openFor(root.modelData.name, root.wsId, root.wsName, root.colorKey);
}
BadgeBox {
screen: root.modelData
visible: root.info !== null
theme: root.theme
leftSide: false
label: root.label
boxColor: root.wsColor
boxOpacity: root.wsOpacity
textColor: root.lightColor ? root.theme.badgeTextOnLight : root.theme.badgeTextOnDark
onClicked: root.openEditor()
}
BadgeBox {
screen: root.modelData
visible: root.info !== null
theme: root.theme
leftSide: true
label: root.label
boxColor: root.wsColor
boxOpacity: root.wsOpacity
textColor: root.lightColor ? root.theme.badgeTextOnLight : root.theme.badgeTextOnDark
onClicked: root.openEditor()
}
EditPopup {
id: popup
screen: root.modelData
compositor: root.compositor
store: root.store
theme: root.theme
}
}