From bf21727ad517a7ccfaa8d5065adfc771fae5ed92 Mon Sep 17 00:00:00 2001 From: Johannes Kresner Date: Sun, 6 Sep 2026 14:37:40 +0200 Subject: [PATCH] fix: quickshell bar spacing --- config/MangoHud/MangoHud.conf | 4 + home.nix | 1 + mutable_config/btop/btop.conf | 4 +- mutable_config/hypr/hyprland.lua | 14 ++ .../quickshell/components/Bar/Bar.qml | 193 +++++++++++------- .../quickshell/components/Bar/TrayTooltip.qml | 53 ----- .../components/Shared/TextField.qml | 13 ++ .../WallpaperPicker/WallpaperPicker.qml | 16 +- mutable_config/quickshell/shell.qml | 5 - 9 files changed, 169 insertions(+), 134 deletions(-) create mode 100644 config/MangoHud/MangoHud.conf delete mode 100644 mutable_config/quickshell/components/Bar/TrayTooltip.qml diff --git a/config/MangoHud/MangoHud.conf b/config/MangoHud/MangoHud.conf new file mode 100644 index 0000000..816add0 --- /dev/null +++ b/config/MangoHud/MangoHud.conf @@ -0,0 +1,4 @@ +fps_limit=0 +frame_timing=1 +gpu_stats=1 +cpu_stats=1 diff --git a/home.nix b/home.nix index e4c176a..6ce4439 100644 --- a/home.nix +++ b/home.nix @@ -79,6 +79,7 @@ lutris claude-code imagemagick + mangohud ]; home.file = { diff --git a/mutable_config/btop/btop.conf b/mutable_config/btop/btop.conf index 4d3ed9e..34fa19c 100644 --- a/mutable_config/btop/btop.conf +++ b/mutable_config/btop/btop.conf @@ -111,11 +111,11 @@ keep_dead_proc_usage = false #* Sets the CPU stat shown in upper half of the CPU graph, "total" is always available. #* Select from a list of detected attributes from the options menu. -cpu_graph_upper = "total" +cpu_graph_upper = "Auto" #* Sets the CPU stat shown in lower half of the CPU graph, "total" is always available. #* Select from a list of detected attributes from the options menu. -cpu_graph_lower = "total" +cpu_graph_lower = "Auto" #* If gpu info should be shown in the cpu box. Available values = "Auto", "On" and "Off". show_gpu_info = "Auto" diff --git a/mutable_config/hypr/hyprland.lua b/mutable_config/hypr/hyprland.lua index 1e4bbc6..2b64d1f 100644 --- a/mutable_config/hypr/hyprland.lua +++ b/mutable_config/hypr/hyprland.lua @@ -228,6 +228,12 @@ hl.bind("XF86AudioStop", hl.dsp.exec_cmd("playerctl stop"), { locked = true }) hl.bind("XF86AudioNext", hl.dsp.exec_cmd("playerctl next"), { locked = true }) hl.bind("XF86AudioPrev", hl.dsp.exec_cmd("playerctl previous"), { locked = true }) +-- Screenshots +hl.bind("Print", hl.dsp.exec_cmd("hyprshot -m output")) +hl.bind("SHIFT + Print", hl.dsp.exec_cmd("hyprshot -m window")) +hl.bind("CTRL + Print", hl.dsp.exec_cmd("hyprshot -m region")) +hl.bind(mainMod .. " + Print", hl.dsp.exec_cmd("hyprshot -m region --raw | swappy -f -")) + -- Move focus with mainMod + arrow keys hl.bind(mainMod .. " + left", hl.dsp.focus({ direction = "left" })) hl.bind(mainMod .. " + right", hl.dsp.focus({ direction = "right" })) @@ -285,3 +291,11 @@ for _, title in ipairs(quickshell_popups) do rounding = 20, }) end + +-- The bar's surface grows/shrinks to fit its hover tooltip (see Bar.qml); +-- Hyprland's default layer animation makes that resize visibly slide/fade, +-- which reads as broken rather than intentional. Disable it for the bar. +hl.layer_rule({ + match = { namespace = "^(quickshell-bar)$" }, + no_anim = true, +}) diff --git a/mutable_config/quickshell/components/Bar/Bar.qml b/mutable_config/quickshell/components/Bar/Bar.qml index 686a3e8..e21a42c 100644 --- a/mutable_config/quickshell/components/Bar/Bar.qml +++ b/mutable_config/quickshell/components/Bar/Bar.qml @@ -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() } } } diff --git a/mutable_config/quickshell/components/Bar/TrayTooltip.qml b/mutable_config/quickshell/components/Bar/TrayTooltip.qml deleted file mode 100644 index 245ca15..0000000 --- a/mutable_config/quickshell/components/Bar/TrayTooltip.qml +++ /dev/null @@ -1,53 +0,0 @@ -import QtQuick -import Quickshell -import Quickshell.Wayland -import "../Shared" - -// Full-screen, click-through overlay used to render tray icon tooltips. -// Kept as its own window so the Bar's own surface can stay exactly as tall -// as the pill itself (no shadow/margin bloat from an oversized surface). -PanelWindow { - id: tooltipWindow - - property string shownText: "" - property real anchorX: 0 - property real anchorY: 0 - - function showAt(x, y, text) { - anchorX = x; - anchorY = y; - shownText = text; - } - - function hide() { - shownText = ""; - } - - anchors { - top: true - left: true - right: true - bottom: true - } - - exclusiveZone: 0 - color: "transparent" - visible: shownText.length > 0 - - WlrLayershell.layer: WlrLayer.Overlay - WlrLayershell.namespace: "quickshell-tray-tooltip" - - // Never accept input; this window only ever draws a small label. - mask: Region {} - - Tooltip { - // anchorX is the icon's horizontal center; center this bubble on it, - // clamped so it never runs past the screen edges. - x: Math.max( - Theme.geometry.spacing, - Math.min(tooltipWindow.anchorX - width / 2, tooltipWindow.width - width - Theme.geometry.spacing) - ) - y: tooltipWindow.anchorY - text: tooltipWindow.shownText - } -} diff --git a/mutable_config/quickshell/components/Shared/TextField.qml b/mutable_config/quickshell/components/Shared/TextField.qml index 517b947..1438459 100644 --- a/mutable_config/quickshell/components/Shared/TextField.qml +++ b/mutable_config/quickshell/components/Shared/TextField.qml @@ -21,6 +21,19 @@ Rectangle { function focusInput() { input.forceActiveFocus(); } + // The layer-shell surface only gets real keyboard focus from the + // compositor asynchronously after it's first mapped, so a single + // forceActiveFocus() call right on visible-toggle can silently lose + // input the first time a panel is shown in a session. There's no + // reliable signal for "the compositor granted focus now" on a + // wlr-layer-shell surface, so just retry until it actually sticks. + Timer { + interval: 30 + repeat: true + running: field.visible && !input.activeFocus + onTriggered: input.forceActiveFocus() + } + height: 50 color: Theme.colors.surface radius: Theme.geometry.radiusSmall diff --git a/mutable_config/quickshell/components/WallpaperPicker/WallpaperPicker.qml b/mutable_config/quickshell/components/WallpaperPicker/WallpaperPicker.qml index d648a81..de281be 100644 --- a/mutable_config/quickshell/components/WallpaperPicker/WallpaperPicker.qml +++ b/mutable_config/quickshell/components/WallpaperPicker/WallpaperPicker.qml @@ -168,11 +168,17 @@ PanelWindow { anchors.fill: parent focus: true - Connections { - target: pickerWindow - function onVisibleChanged() { - if (pickerWindow.visible) keyHandler.forceActiveFocus(); - } + // The layer-shell surface only gets real keyboard focus from the + // compositor asynchronously after it's first mapped, so a single + // forceActiveFocus() call right on visible-toggle can silently lose + // input the first time this panel is shown in a session. There's no + // reliable signal for "the compositor granted focus now" on a + // wlr-layer-shell surface, so just retry until it actually sticks. + Timer { + interval: 30 + repeat: true + running: pickerWindow.visible && !keyHandler.activeFocus + onTriggered: keyHandler.forceActiveFocus() } Keys.onEscapePressed: (event) => { diff --git a/mutable_config/quickshell/shell.qml b/mutable_config/quickshell/shell.qml index 2045772..357d92d 100644 --- a/mutable_config/quickshell/shell.qml +++ b/mutable_config/quickshell/shell.qml @@ -86,10 +86,6 @@ ShellRoot { running: false } - TrayTooltip { - id: trayTooltip - } - Variants { model: Quickshell.screens @@ -97,7 +93,6 @@ ShellRoot { required property var modelData screen: modelData rootState: root - trayTooltip: trayTooltip } }