fix: quickshell bar spacing

This commit is contained in:
johannes committed 2026-09-17 19:56:15 +02:00
1 parent 3edf76b4c7
commit b08b0816f4
9 files changed
+169 -134

No files matched your search

+124 -69
View File
@@ -11,10 +11,6 @@ PanelWindow {
// Reference to global state
property QtObject rootState
// Shared overlay window that renders tray icon hover tooltips (see
// TrayTooltip.qml) so this bar's own surface can stay exactly as tall
// as the pill itself.
property QtObject trayTooltip
anchors {
top: true
@@ -22,9 +18,6 @@ PanelWindow {
right: true
}
// Matches hyprland.lua's general.gaps_out (20) so the gap above the bar
// (this margin) and the gap below it (added by Hyprland once the
// exclusiveZone ends) read as the same size.
readonly property int hyprGapsOut: 20
margins {
@@ -33,22 +26,74 @@ PanelWindow {
right: hyprGapsOut
}
// No separate bottom buffer here — Hyprland's gaps_out already adds its
// own gap between the reserved zone and the tiled window below.
exclusiveZone: implicitHeight + margins.top
// 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
implicitHeight: 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.verticalCenter: parent.verticalCenter
height: parent.height
anchors.top: parent.top
height: barWindow.barContentHeight
tint: Theme.colors.primary
glow: true
@@ -89,8 +134,8 @@ PanelWindow {
Pill {
id: centerPill
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
height: parent.height
anchors.top: parent.top
height: barWindow.barContentHeight
tint: Theme.colors.secondary
glow: true
@@ -114,8 +159,8 @@ PanelWindow {
Pill {
id: rightPill
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
height: parent.height
anchors.top: parent.top
height: barWindow.barContentHeight
tint: Theme.colors.tertiary
StatIndicator {
@@ -123,29 +168,32 @@ PanelWindow {
text: sysStats.cpuPercent + "%"
tint: Theme.colors.tertiary
tooltip: "CPU usage: " + sysStats.cpuPercent + "%"
tooltipWindow: barWindow.trayTooltip
}
StatIndicator {
visible: sysStats.cpuTemp.length > 0
glyph: "" // nf-fa-thermometer_half
text: sysStats.cpuTemp + "°"
tint: {
let t = Number(sysStats.cpuTemp);
if (t >= 80) return Theme.colors.alert;
if (t >= 65) return Theme.colors.warning;
return Theme.colors.textMuted;
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"
}
tooltip: "CPU temp: " + sysStats.cpuTemp + "°C"
tooltipWindow: barWindow.trayTooltip
}
StatIndicator {
glyph: "" // nf-fa-server
text: sysStats.ramPercent + "%"
text: sysStats.ramUsedGB + "G"
tint: Theme.colors.secondary
tooltip: "RAM usage: " + sysStats.ramPercent + "%"
tooltipWindow: barWindow.trayTooltip
tooltip: "RAM usage: " + sysStats.ramUsedGB + " GiB (" + sysStats.ramPercent + "%)"
}
TrayIcon {
@@ -154,7 +202,6 @@ PanelWindow {
tint: Theme.colors.primary
tooltip: "WiFi: " + wifiPoll.ssid
visible: wifiPoll.connected
tooltipWindow: barWindow.trayTooltip
}
TrayIcon {
@@ -163,7 +210,6 @@ PanelWindow {
tint: Theme.colors.secondary
tooltip: "Bluetooth: " + bluetoothPoll.connectedDevices
visible: bluetoothPoll.connectedDevices.length > 0
tooltipWindow: barWindow.trayTooltip
}
TrayIcon {
@@ -188,18 +234,17 @@ PanelWindow {
+ (battery.state === UPowerDeviceState.Charging ? " (charging)" : "")
: "No battery"
visible: battery.isPresent
tooltipWindow: barWindow.trayTooltip
}
}
property QtObject battery: UPower.displayDevice
// --- System stats (CPU%, CPU temp, RAM%) read straight from /proc and /sys ---
// --- System stats (CPU%, per-die CPU temps, RAM%) read straight from /proc and /sys ---
QtObject {
id: sysStats
property string cpuPercent: "0"
property string cpuTemp: ""
property string ramPercent: "0"
property string ramUsedGB: "0"
// Previous /proc/stat totals, for computing CPU% as a delta between polls.
property real prevTotal: -1
@@ -241,21 +286,44 @@ PanelWindow {
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";
}
}
// Discover the CPU temp sensor's hwmon path once (the hwmonN numbering
// isn't stable across boots), then poll that fixed path via FileView.
FileView { id: cpuTempFile; watchChanges: false }
// 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: hwmonDiscovery
command: ["bash", "-c", "for h in /sys/class/hwmon/hwmon*; do n=$(cat \"$h/name\" 2>/dev/null); if [ \"$n\" = k10temp ] || [ \"$n\" = coretemp ] || [ \"$n\" = zenpower ]; then echo \"$h/temp1_input\"; break; fi; done"]
running: true
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 path = this.text.trim();
if (path.length > 0) cpuTempFile.path = path;
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);
}
}
}
@@ -265,12 +333,7 @@ PanelWindow {
running: true
repeat: true
triggeredOnStart: true
onTriggered: {
if (cpuTempFile.path.length === 0) return;
cpuTempFile.reload();
let millideg = Number(cpuTempFile.text().trim());
if (millideg > 0) sysStats.cpuTemp = Math.round(millideg / 1000).toString();
}
onTriggered: dieTempProcess.exec(dieTempProcess.command)
}
// --- WiFi status (polled via nmcli; requires NetworkManager) ---
@@ -346,7 +409,6 @@ PanelWindow {
property alias text: statText.text
property color tint: Theme.colors.text
property string tooltip: ""
property QtObject tooltipWindow
width: statRow.width
height: 24
@@ -381,20 +443,16 @@ PanelWindow {
anchors.fill: parent
hoverEnabled: true
onEntered: {
if (statIndicator.tooltipWindow && statIndicator.tooltip.length > 0) {
let pos = statIndicator.mapToGlobal(statIndicator.width / 2, statIndicator.height + Theme.geometry.spacing / 2);
statIndicator.tooltipWindow.showAt(pos.x, pos.y, statIndicator.tooltip);
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: {
if (statIndicator.tooltipWindow) statIndicator.tooltipWindow.hide();
}
onExited: barWindow.hideTooltip()
}
}
// Inline component for a hoverable tray icon. The tooltip itself is
// rendered by the shared TrayTooltip overlay window (see tooltipWindow)
// so it isn't clipped by this bar's small surface. `tint` is this icon's
// 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
@@ -402,7 +460,6 @@ PanelWindow {
property string tooltip: ""
property bool active: false
property color tint: Theme.colors.primary
property QtObject tooltipWindow
width: 24
height: 24
@@ -432,16 +489,14 @@ PanelWindow {
anchors.fill: parent
hoverEnabled: true
onEntered: {
if (trayIcon.tooltipWindow && trayIcon.tooltip.length > 0) {
if (trayIcon.tooltip.length > 0) {
// Anchor on the icon's horizontal center; the tooltip
// window centers its bubble under this point itself.
let pos = trayIcon.mapToGlobal(trayIcon.width / 2, trayIcon.height + Theme.geometry.spacing / 2);
trayIcon.tooltipWindow.showAt(pos.x, pos.y, trayIcon.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: {
if (trayIcon.tooltipWindow) trayIcon.tooltipWindow.hide();
}
onExited: barWindow.hideTooltip()
}
}
}