import QtQuick import Quickshell import Quickshell.Wayland import Quickshell.Hyprland import Quickshell.Io import Quickshell.Services.UPower import "../Shared" PanelWindow { id: barWindow // Reference to global state property QtObject rootState anchors { top: true left: true right: true } readonly property int hyprGapsOut: 20 margins { top: hyprGapsOut left: hyprGapsOut right: hyprGapsOut } // Fixed pill-row height. The tray tooltip (below) needs extra surface // space beneath this to render into, but that space is reserved // up front at a constant size rather than grown/shrunk at runtime - // resizing a wlr-layer-shell surface on every hover forces a full // reconfigure that visibly flashes/redraws the whole bar. Instead the // surface is always tall enough, and only the tooltip's own visibility // toggles. readonly property int barContentHeight: 40 readonly property int tooltipReserve: 40 // Just the pill row's own height - not barContentHeight + margins.top. // The wlr-layer-shell protocol already adds this surface's margins on // top of exclusiveZone when reserving screen space, so including // margins.top here again double-counts it (verified via `hyprctl // monitors`: reported reserved space was margins.top + exclusiveZone, // not just exclusiveZone). That double-count was also why the gap below // the bar measured out to margins.top + 22px instead of a fixed 22px // (Hyprland's own gaps_out + border) - no value of margins.top could // ever make the two gaps equal while the formula double-counted it. exclusiveZone: barContentHeight implicitHeight: barContentHeight + tooltipReserve color: "transparent" WlrLayershell.layer: WlrLayer.Top WlrLayershell.namespace: "quickshell-bar" // Only the pill row accepts input - the reserved tooltip space below it // stays click-through so it doesn't block the desktop/windows under it // when no tooltip is showing. mask: Region { x: 0 y: 0 width: barWindow.width height: barWindow.barContentHeight } property string tooltipText: "" property real tooltipAnchorX: 0 property real tooltipAnchorY: 0 function showTooltip(x, y, text) { tooltipAnchorX = x; tooltipAnchorY = y; tooltipText = text; } function hideTooltip() { tooltipText = ""; } Tooltip { id: tooltipItem text: barWindow.tooltipText visible: barWindow.tooltipText.length > 0 x: Math.max( Theme.geometry.spacing, Math.min(barWindow.tooltipAnchorX - width / 2, barWindow.width - width - Theme.geometry.spacing) ) y: barWindow.tooltipAnchorY } // Left Pill (Workspaces) - tinted with the primary accent. Pill { id: leftPill anchors.left: parent.left anchors.top: parent.top height: barWindow.barContentHeight tint: Theme.colors.primary glow: true // Workspaces Row { spacing: Theme.geometry.spacing Repeater { model: Hyprland.workspaces.values.filter(ws => ws.monitor && ws.monitor.name === barWindow.screen.name) delegate: Rectangle { width: 24 height: 24 radius: Theme.geometry.radiusTiny color: modelData.active ? Theme.colors.primary : Theme.colors.surfaceHover Behavior on color { ColorAnimation { duration: Theme.animation.durationFast } } Text { anchors.centerIn: parent text: modelData.id color: modelData.active ? Theme.colors.textOnAccent : Theme.colors.text font.family: Theme.font.family font.pixelSize: Theme.type.caption font.bold: modelData.active } MouseArea { anchors.fill: parent cursorShape: Qt.PointingHandCursor onClicked: modelData.activate() } } } } } // Center Pill (Clock) - tinted with the secondary accent. Pill { id: centerPill anchors.horizontalCenter: parent.horizontalCenter anchors.top: parent.top height: barWindow.barContentHeight tint: Theme.colors.secondary glow: true SystemClock { id: clock precision: SystemClock.Minutes } Text { id: clockText text: Qt.formatDateTime(clock.date, "hh:mm") color: Theme.colors.secondary font.family: Theme.font.family font.bold: true } } // Right Pill (System tray: CPU/RAM/temp stats, WiFi, Bluetooth, Battery) // Tinted with the tertiary accent; each stat/icon also carries its own // color so the pill reads as a set of distinct signals, not one blob. Pill { id: rightPill anchors.right: parent.right anchors.top: parent.top height: barWindow.barContentHeight tint: Theme.colors.tertiary StatIndicator { glyph: "" // nf-fa-microchip text: sysStats.cpuPercent + "%" tint: Theme.colors.tertiary tooltip: "CPU usage: " + sysStats.cpuPercent + "%" } Repeater { model: dieTempsModel StatIndicator { required property string label required property string temp glyph: "" // nf-fa-thermometer_half text: temp + "°" tint: { let t = Number(temp); if (t >= 80) return Theme.colors.alert; if (t >= 65) return Theme.colors.warning; return Theme.colors.textMuted; } tooltip: (dieTempsModel.count > 1 ? label + " " : "CPU ") + "temp: " + temp + "°C" } } StatIndicator { glyph: "" // nf-fa-server text: sysStats.ramUsedGB + "G" tint: Theme.colors.secondary tooltip: "RAM usage: " + sysStats.ramUsedGB + " GiB (" + sysStats.ramPercent + "%)" } TrayIcon { glyph: "" // nf-fa-wifi active: wifiPoll.connected tint: Theme.colors.primary tooltip: "WiFi: " + wifiPoll.ssid visible: wifiPoll.connected } TrayIcon { glyph: "" // nf-fa-bluetooth_b active: true tint: Theme.colors.secondary tooltip: "Bluetooth: " + bluetoothPoll.connectedDevices visible: bluetoothPoll.connectedDevices.length > 0 } TrayIcon { glyph: { let p = battery.percentage; if (!battery.isPresent) return ""; // nf-fa-plug (desktop/no battery) if (p >= 0.9) return ""; // nf-fa-battery_full if (p >= 0.65) return ""; // nf-fa-battery_three_quarters if (p >= 0.4) return ""; // nf-fa-battery_half if (p >= 0.15) return ""; // nf-fa-battery_quarter return ""; // nf-fa-battery_empty } active: battery.state === UPowerDeviceState.Charging tint: { let p = battery.percentage; if (p >= 0.5) return Theme.colors.success; if (p >= 0.2) return Theme.colors.warning; return Theme.colors.alert; } tooltip: battery.isPresent ? "Battery: " + Math.round(battery.percentage * 100) + "%" + (battery.state === UPowerDeviceState.Charging ? " (charging)" : "") : "No battery" visible: battery.isPresent } } property QtObject battery: UPower.displayDevice // --- System stats (CPU%, per-die CPU temps, RAM%) read straight from /proc and /sys --- QtObject { id: sysStats property string cpuPercent: "0" property string ramPercent: "0" property string ramUsedGB: "0" // Previous /proc/stat totals, for computing CPU% as a delta between polls. property real prevTotal: -1 property real prevIdle: -1 } FileView { id: statFile; path: "/proc/stat" } FileView { id: memInfoFile; path: "/proc/meminfo" } Timer { interval: 1000 running: true repeat: true triggeredOnStart: true onTriggered: { statFile.reload(); memInfoFile.reload(); // First line: "cpu user nice system idle iowait irq softirq ..." let fields = statFile.text().split("\n")[0].trim().split(/\s+/).slice(1).map(Number); let idle = fields[3] + fields[4]; let total = fields.reduce((a, b) => a + b, 0); if (sysStats.prevTotal >= 0) { let totalDelta = total - sysStats.prevTotal; let idleDelta = idle - sysStats.prevIdle; sysStats.cpuPercent = totalDelta > 0 ? Math.round(100 * (totalDelta - idleDelta) / totalDelta).toString() : "0"; } sysStats.prevTotal = total; sysStats.prevIdle = idle; let mem = {}; for (const line of memInfoFile.text().split("\n")) { let match = line.match(/^(\w+):\s+(\d+)/); if (match) mem[match[1]] = Number(match[2]); } sysStats.ramPercent = mem.MemTotal > 0 ? Math.round(100 * (mem.MemTotal - mem.MemAvailable) / mem.MemTotal).toString() : "0"; // MemTotal/MemAvailable are in KiB. sysStats.ramUsedGB = mem.MemTotal > 0 ? ((mem.MemTotal - mem.MemAvailable) / 1024 / 1024).toFixed(1) : "0"; } } // One entry per CPU die: { label: "Tccd1", temp: "45" }. On chips with // a single die (no Tccd sensors, e.g. most Intel coretemp setups) this // falls back to a single "CPU" entry from Tctl/Package temp. Updated // in place (set/append/remove) rather than replaced wholesale, so the // Repeater bound to it doesn't destroy/recreate delegates - and lose // their hover state - on every poll. ListModel { id: dieTempsModel } // Find the CPU sensor chip's hwmon dir and emit one "label millideg" line // per die (Tccd1, Tccd2, ...), falling back to a single Tctl/Package // reading on chips with no per-die sensors. Re-run in full every poll // rather than caching the hwmon path, since hwmonN numbering isn't // stable across boots and this walk is cheap. Process { id: dieTempProcess command: ["bash", "-c", "h=\"\"; for d in /sys/class/hwmon/hwmon*; do n=$(cat \"$d/name\" 2>/dev/null); if [ \"$n\" = k10temp ] || [ \"$n\" = zenpower ] || [ \"$n\" = coretemp ]; then h=\"$d\"; break; fi; done; [ -z \"$h\" ] && exit 0; found=0; for lbl in \"$h\"/temp*_label; do [ -e \"$lbl\" ] || continue; name=$(cat \"$lbl\"); case \"$name\" in Tccd*) idx=\"${lbl%_label}\"; val=$(cat \"${idx}_input\" 2>/dev/null); if [ -n \"$val\" ]; then echo \"$name $val\"; found=1; fi ;; esac; done; if [ \"$found\" = 0 ]; then val=$(cat \"$h/temp1_input\" 2>/dev/null); [ -n \"$val\" ] && echo \"CPU $val\"; fi"] running: false stdout: StdioCollector { onStreamFinished: { let temps = []; for (const line of this.text.trim().split("\n")) { let parts = line.trim().split(/\s+/); if (parts.length < 2) continue; let millideg = Number(parts[1]); if (millideg > 0) temps.push({ label: parts[0], temp: Math.round(millideg / 1000).toString() }); } for (let i = 0; i < temps.length; i++) { if (i < dieTempsModel.count) dieTempsModel.set(i, temps[i]); else dieTempsModel.append(temps[i]); } while (dieTempsModel.count > temps.length) dieTempsModel.remove(dieTempsModel.count - 1); } } } Timer { interval: 1000 running: true repeat: true triggeredOnStart: true onTriggered: dieTempProcess.exec(dieTempProcess.command) } // --- WiFi status (polled via nmcli; requires NetworkManager) --- QtObject { id: wifiPoll property bool connected: false property string ssid: "" } Timer { interval: 5000 running: true repeat: true triggeredOnStart: true onTriggered: wifiProcess.restart() } Process { id: wifiProcess command: ["bash", "-c", "nmcli -t -f ACTIVE,SSID dev wifi 2>/dev/null | awk -F: '$1==\"yes\"{print $2; exit}'"] running: false function restart() { running = false; running = true; } stdout: StdioCollector { onStreamFinished: { let ssid = this.text.trim(); wifiPoll.connected = ssid.length > 0; wifiPoll.ssid = ssid; } } } // --- Bluetooth status (polled via bluetoothctl) --- QtObject { id: bluetoothPoll property bool available: true property bool powered: false property string connectedDevices: "" } Timer { interval: 5000 running: true repeat: true triggeredOnStart: true onTriggered: bluetoothProcess.restart() } Process { id: bluetoothProcess command: ["bash", "-c", "powered=$(bluetoothctl show 2>/dev/null | awk -F': ' '/Powered/{print $2}'); devices=$(bluetoothctl devices Connected 2>/dev/null | sed -E 's/^Device [0-9A-F:]+ //' | paste -sd, -); echo \"$powered|$devices\""] running: false function restart() { running = false; running = true; } stdout: StdioCollector { onStreamFinished: { let parts = this.text.trim().split("|"); if (parts[0] === undefined || parts[0] === "") { bluetoothPoll.available = false; return; } bluetoothPoll.available = true; bluetoothPoll.powered = parts[0] === "yes"; bluetoothPoll.connectedDevices = parts[1] || ""; } } } // Inline component for a compact icon+text stat readout (CPU, temp, RAM). // `tint` colors both the glyph and text, so each stat reads as its own // signal instead of everything sharing one flat color. component StatIndicator: Item { id: statIndicator property string glyph: "" property alias text: statText.text property color tint: Theme.colors.text property string tooltip: "" width: statRow.width height: 24 Row { id: statRow anchors.verticalCenter: parent.verticalCenter spacing: 4 Text { anchors.verticalCenter: parent.verticalCenter text: statIndicator.glyph font.family: Theme.font.family font.pixelSize: Theme.type.body color: statIndicator.tint Behavior on color { ColorAnimation { duration: Theme.animation.durationFast } } } Text { id: statText anchors.verticalCenter: parent.verticalCenter color: statIndicator.tint font.family: Theme.font.family font.pixelSize: Theme.type.caption Behavior on color { ColorAnimation { duration: Theme.animation.durationFast } } } } MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { if (statIndicator.tooltip.length > 0) { let pos = statIndicator.mapToItem(null, statIndicator.width / 2, statIndicator.height + 12); barWindow.showTooltip(pos.x, pos.y, statIndicator.tooltip); } } onExited: barWindow.hideTooltip() } } // Inline component for a hoverable tray icon. `tint` is this icon's // own identity color (wifi vs bluetooth vs battery-by-level, etc.). component TrayIcon: Item { id: trayIcon property string glyph: "" property string tooltip: "" property bool active: false property color tint: Theme.colors.primary width: 24 height: 24 Rectangle { anchors.fill: parent radius: Theme.geometry.radiusTiny color: hoverArea.containsMouse ? Theme.colors.surfaceHover : (trayIcon.active ? Qt.alpha(trayIcon.tint, 0.15) : "transparent") Behavior on color { ColorAnimation { duration: Theme.animation.durationFast } } Text { anchors.centerIn: parent text: trayIcon.glyph font.family: Theme.font.family font.pixelSize: Theme.type.body color: trayIcon.active ? trayIcon.tint : Theme.colors.text Behavior on color { ColorAnimation { duration: Theme.animation.durationFast } } } } MouseArea { id: hoverArea anchors.fill: parent hoverEnabled: true onEntered: { if (trayIcon.tooltip.length > 0) { // Anchor on the icon's horizontal center; the tooltip // item centers its bubble under this point itself. let pos = trayIcon.mapToItem(null, trayIcon.width / 2, trayIcon.height + 12); barWindow.showTooltip(pos.x, pos.y, trayIcon.tooltip); } } onExited: barWindow.hideTooltip() } } }