pragma ComponentBehavior: Bound import QtQuick import Quickshell.Hyprland import "../../components" import "../../theme" import "../../services" import "../../core" // Workspace switcher. Styles (bar.workspaces.style): numbers, roman numerals, kanji, // dots (filled = occupied, ring = empty) and pacman (after Serpantinum: pellets // for empty workspaces, ghosts for occupied ones, Pac-Man on the active one). GlassPill { id: root property var barScreen // Layout entry; notch islands mark theirs so the notch can use its own style. property var entry: ({}) // Every bar follows the globally focused workspace, whichever monitor it is on. readonly property int activeId: Hyprland.focusedWorkspace ? Hyprland.focusedWorkspace.id : 0 // Workspaces shown on other monitors get a faint outline. readonly property var visibleIds: Hyprland.monitors.values.map(m => m.activeWorkspace ? m.activeWorkspace.id : 0).filter(id => id > 0 && id !== activeId) readonly property int count: ConfigService.data.bar.workspaces.count readonly property string notchStyle: entry && entry.notch && ConfigService.data.notch ? ConfigService.data.notch.workspaceStyle : "bar" readonly property string style: notchStyle && notchStyle !== "bar" ? notchStyle : ConfigService.data.bar.workspaces.style || "numbers" readonly property bool textual: style === "numbers" || style === "roman" || style === "kanji" readonly property bool pacman: style === "pacman" readonly property real pacmanScale: 0.95 readonly property int slotWidth: style === "roman" ? 38 : style === "kanji" ? (count > 10 ? 40 : 30) : style === "dots" ? 22 : style === "pacman" ? 24 : 32 readonly property int slotHeight: height - 6 readonly property int activeIndex: activeId >= 1 && activeId <= count ? activeId - 1 : -1 width: count * slotWidth + 8 height: ModuleRegistry.pillHeight function roman(value) { const numerals = [[10, "X"], [9, "IX"], [5, "V"], [4, "IV"], [1, "I"]]; let result = ""; for (const [n, symbol] of numerals) while (value >= n) { result += symbol; value -= n; } return result; } // Japanese numerals: 一 … 十, then 十一 … 二十. function kanji(value) { const digits = ["", "一", "二", "三", "四", "五", "六", "七", "八", "九"]; if (value < 10) return digits[value]; return (value >= 20 ? digits[Math.floor(value / 10)] : "") + "十" + digits[value % 10]; } Repeater { model: root.pacman ? [] : root.visibleIds.filter(id => id <= root.count) Rectangle { required property int modelData x: 4 + (modelData - 1) * root.slotWidth y: 3 width: root.slotWidth height: root.slotHeight radius: height / 2 color: Qt.alpha(Theme.accent, 0.18) border.width: 1 border.color: Qt.alpha(Theme.accent, 0.6) } } // Sliding accent highlight (all styles except pacman, whose actor marks the active slot). Rectangle { visible: !root.pacman && root.activeIndex >= 0 x: 4 + Math.max(0, root.activeIndex) * root.slotWidth y: 3 width: root.slotWidth height: root.slotHeight radius: height / 2 color: Theme.accent Behavior on x { NumberAnimation { duration: Theme.duration easing.type: Easing.OutCubic } } } Row { x: 4 y: 3 Repeater { model: root.count Item { id: slot required property int index readonly property var workspace: Hyprland.workspaces.values.find(w => w.id === index + 1) || null readonly property bool active: root.activeIndex === index readonly property bool occupied: !!workspace && workspace.toplevels.values.length > 0 readonly property bool urgent: !!workspace && workspace.urgent width: root.slotWidth height: root.slotHeight // Numbers, roman numerals and kanji Text { visible: root.textual anchors.centerIn: parent anchors.verticalCenterOffset: slot.occupied && !slot.active ? -2 : 0 text: root.style === "roman" ? root.roman(slot.index + 1) : root.style === "kanji" ? root.kanji(slot.index + 1) : slot.index + 1 font.pixelSize: root.style === "roman" ? 11 : root.style === "kanji" ? 13 : 12 font.weight: root.style === "roman" ? Font.DemiBold : Font.Normal font.letterSpacing: root.style === "roman" ? 0.5 : 0 color: slot.urgent ? Theme.urgent : slot.active ? Theme.accentText : Theme.text opacity: slot.active || slot.occupied ? 1 : 0.5 } Rectangle { visible: root.textual && slot.occupied && !slot.active anchors.bottom: parent.bottom anchors.bottomMargin: 1 anchors.horizontalCenter: parent.horizontalCenter width: 3 height: 3 radius: 2 color: Theme.text } // Dots: filled when occupied, ring when empty Rectangle { visible: root.style === "dots" anchors.centerIn: parent width: slot.active ? 9 : 8 height: width radius: width / 2 color: slot.active ? Theme.accentText : slot.urgent ? Theme.urgent : slot.occupied ? Theme.text : Theme.transparent border.width: slot.occupied || slot.active ? 0 : 1.5 border.color: slot.urgent ? Theme.urgent : Qt.alpha(Theme.text, 0.6) Behavior on width { NumberAnimation { duration: Theme.duration / 2 } } } // Pacman: pellets (every second one a power pellet) and ghosts Rectangle { visible: root.pacman && !slot.occupied anchors.centerIn: parent width: Math.round((slot.index % 2 === 1 ? 9 : 6) * root.pacmanScale) height: width radius: width / 2 color: slot.urgent ? Theme.urgent : Qt.alpha(Theme.text, 0.75) scale: slot.active ? 0 : pelletArea.containsMouse ? 1.25 : 1 Behavior on scale { NumberAnimation { duration: 180 easing.type: Easing.OutBack } } } // Created only for occupied slots in pacman style: each Canvas holds // its own 2D context and texture. Loader { active: root.pacman && slot.occupied anchors.centerIn: parent sourceComponent: Canvas { id: ghost width: Math.round(16 * root.pacmanScale) height: Math.round(17 * root.pacmanScale) scale: slot.active ? 0 : pelletArea.containsMouse ? 1.15 : 1 Behavior on scale { NumberAnimation { duration: 220 easing.type: Easing.OutBack } } // Pupils look towards Pac-Man. readonly property real look: root.activeIndex > slot.index ? 1 : root.activeIndex < slot.index && root.activeIndex >= 0 ? -1 : 0 readonly property color body: slot.urgent ? Theme.urgent : Theme.textSecondary onLookChanged: requestPaint() onBodyChanged: requestPaint() onVisibleChanged: if (visible) requestPaint() Component.onCompleted: requestPaint() onPaint: { const ctx = getContext("2d"); ctx.reset(); const w = width - 2, h = height - 2, r = w / 2, x0 = 1, y0 = 1; const bottom = y0 + h, wave = h * 0.14; ctx.beginPath(); ctx.moveTo(x0, y0 + r); ctx.arc(x0 + r, y0 + r, r, Math.PI, 0, false); ctx.lineTo(x0 + w, bottom); ctx.quadraticCurveTo(x0 + w * 5 / 6, bottom - wave, x0 + w * 2 / 3, bottom); ctx.quadraticCurveTo(x0 + w / 2, bottom - wave, x0 + w / 3, bottom); ctx.quadraticCurveTo(x0 + w / 6, bottom - wave, x0, bottom); ctx.closePath(); ctx.fillStyle = body; ctx.fill(); const eye = w * 0.17, ex1 = x0 + w * 0.32, ex2 = x0 + w * 0.68, ey = y0 + r * 0.95; ctx.beginPath(); ctx.arc(ex1, ey, eye, 0, 2 * Math.PI); ctx.arc(ex2, ey, eye, 0, 2 * Math.PI); ctx.fillStyle = "#ffffff"; ctx.fill(); const shift = look * eye * 0.35; ctx.beginPath(); ctx.arc(ex1 + shift, ey, eye * 0.55, 0, 2 * Math.PI); ctx.arc(ex2 + shift, ey, eye * 0.55, 0, 2 * Math.PI); ctx.fillStyle = "#11111b"; ctx.fill(); } } } MouseArea { id: pelletArea anchors.fill: parent hoverEnabled: root.pacman cursorShape: Qt.PointingHandCursor onClicked: Hyprland.dispatch("hl.dsp.focus({ workspace = '" + (slot.index + 1) + "' })") } } } } // Pac-Man glides to the active workspace, chomps, and faces its direction of travel. Canvas { id: pac property int previous: root.activeIndex property bool facingLeft: false property real mouth: 0.18 visible: root.pacman && root.activeIndex >= 0 width: Math.round(20 * root.pacmanScale) height: width y: 3 + (root.slotHeight - height) / 2 x: 4 + Math.max(0, root.activeIndex) * root.slotWidth + (root.slotWidth - width) / 2 Behavior on x { NumberAnimation { duration: Math.max(Theme.duration, 1) * 1.4 easing.type: Easing.OutQuint } } transform: Scale { origin.x: pac.width / 2 xScale: pac.facingLeft ? -1 : 1 } Connections { target: root function onActiveIndexChanged() { if (root.activeIndex < pac.previous) pac.facingLeft = true; else if (root.activeIndex > pac.previous) pac.facingLeft = false; pac.previous = root.activeIndex; if (Theme.intensity > 0) chomp.restart(); } } SequentialAnimation { id: chomp loops: 3 NumberAnimation { target: pac property: "mouth" to: 0.02 duration: 80 easing.type: Easing.InOutQuad } NumberAnimation { target: pac property: "mouth" to: 0.18 duration: 80 easing.type: Easing.InOutQuad } } readonly property color body: Theme.accentVivid onMouthChanged: requestPaint() onBodyChanged: requestPaint() onVisibleChanged: if (visible) requestPaint() Component.onCompleted: requestPaint() onPaint: { const ctx = getContext("2d"); ctx.reset(); const r = width / 2, m = mouth * Math.PI; ctx.beginPath(); ctx.moveTo(r, r); ctx.arc(r, r, r - 0.5, m, 2 * Math.PI - m, false); ctx.closePath(); ctx.fillStyle = body; ctx.fill(); ctx.beginPath(); ctx.arc(r + r * 0.12, r - r * 0.46, Math.max(1.5, r * 0.14), 0, 2 * Math.PI); ctx.fillStyle = "#11111b"; ctx.fill(); } } }