From b969f0824f9d0ae6a8c8745c7b07c619fa406315 Mon Sep 17 00:00:00 2001 From: Damocles Date: Sun, 12 Apr 2026 10:57:48 +0200 Subject: [PATCH] extract constants --- modules/Backlight.qml | 5 +++-- modules/Bar.qml | 10 +++++----- modules/BarIcon.qml | 8 ++++---- modules/BarLabel.qml | 8 ++++---- modules/BarSection.qml | 8 ++++---- modules/Battery.qml | 5 +++-- modules/Bluetooth.qml | 2 +- modules/Cpu.qml | 15 +++++++++++---- modules/Disk.qml | 2 +- modules/Flyout.qml | 2 +- modules/Memory.qml | 5 +++-- modules/Mpris.qml | 14 +++++++++----- modules/Network.qml | 20 +++++++++++++------- modules/Notifications.qml | 18 ++++++++++++------ modules/PowerProfile.qml | 12 ++++++++---- modules/Temperature.qml | 2 +- modules/Theme.qml | 12 ++++++++++++ modules/Tray.qml | 2 +- modules/Volume.qml | 12 ++++++------ modules/Weather.qml | 2 +- modules/Workspaces.qml | 2 +- nix/hm-module.nix | 3 ++- 22 files changed, 106 insertions(+), 63 deletions(-) diff --git a/modules/Backlight.qml b/modules/Backlight.qml index 2529c47..e994c8e 100644 --- a/modules/Backlight.qml +++ b/modules/Backlight.qml @@ -4,7 +4,7 @@ import "." as M M.BarSection { id: root - spacing: 4 + spacing: M.Theme.moduleSpacing visible: percent > 0 tooltip: "Brightness: " + root.percent + "%" @@ -14,7 +14,8 @@ M.BarSection { id: adjProc property string cmd: "" command: ["sh", "-c", cmd] - onRunningChanged: if (!running && cmd !== "") current.reload() + onRunningChanged: if (!running && cmd !== "") + current.reload() } function adjust(delta) { diff --git a/modules/Bar.qml b/modules/Bar.qml index 8035588..ecbebb3 100644 --- a/modules/Bar.qml +++ b/modules/Bar.qml @@ -29,15 +29,15 @@ PanelWindow { Item { anchors.fill: parent - anchors.leftMargin: 8 - anchors.rightMargin: 8 + anchors.leftMargin: M.Theme.barPadding + anchors.rightMargin: M.Theme.barPadding // ---- center (declared first so left/right can anchor to it) ---- RowLayout { id: centerSection anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter - spacing: 8 + spacing: M.Theme.barSpacing M.Clock {} M.Notifications {} @@ -48,7 +48,7 @@ PanelWindow { anchors.left: parent.left anchors.right: centerSection.left anchors.verticalCenter: parent.verticalCenter - spacing: 8 + spacing: M.Theme.barSpacing M.Tray { bar: bar @@ -63,7 +63,7 @@ PanelWindow { anchors.left: centerSection.right anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter - spacing: 12 + spacing: M.Theme.barSpacing Item { Layout.fillWidth: true diff --git a/modules/BarIcon.qml b/modules/BarIcon.qml index 0b07239..ec0d99a 100644 --- a/modules/BarIcon.qml +++ b/modules/BarIcon.qml @@ -15,11 +15,11 @@ Text { HoverHandler { onHoveredChanged: { if (hovered && root.tooltip !== "") { - M.FlyoutState.text = root.tooltip - M.FlyoutState.itemX = root.mapToGlobal(root.width / 2, 0).x - M.FlyoutState.visible = true + M.FlyoutState.text = root.tooltip; + M.FlyoutState.itemX = root.mapToGlobal(root.width / 2, 0).x; + M.FlyoutState.visible = true; } else if (!hovered && root.tooltip !== "") { - M.FlyoutState.visible = false + M.FlyoutState.visible = false; } } } diff --git a/modules/BarLabel.qml b/modules/BarLabel.qml index 8baad19..fa4bdf8 100644 --- a/modules/BarLabel.qml +++ b/modules/BarLabel.qml @@ -15,11 +15,11 @@ Text { HoverHandler { onHoveredChanged: { if (hovered && root.tooltip !== "") { - M.FlyoutState.text = root.tooltip - M.FlyoutState.itemX = root.mapToGlobal(root.width / 2, 0).x - M.FlyoutState.visible = true + M.FlyoutState.text = root.tooltip; + M.FlyoutState.itemX = root.mapToGlobal(root.width / 2, 0).x; + M.FlyoutState.visible = true; } else if (!hovered && root.tooltip !== "") { - M.FlyoutState.visible = false + M.FlyoutState.visible = false; } } } diff --git a/modules/BarSection.qml b/modules/BarSection.qml index a7d44e6..0fb07a8 100644 --- a/modules/BarSection.qml +++ b/modules/BarSection.qml @@ -8,11 +8,11 @@ Row { HoverHandler { onHoveredChanged: { if (hovered && root.tooltip !== "") { - M.FlyoutState.text = root.tooltip - M.FlyoutState.itemX = root.mapToGlobal(root.width / 2, 0).x - M.FlyoutState.visible = true + M.FlyoutState.text = root.tooltip; + M.FlyoutState.itemX = root.mapToGlobal(root.width / 2, 0).x; + M.FlyoutState.visible = true; } else if (!hovered && root.tooltip !== "") { - M.FlyoutState.visible = false + M.FlyoutState.visible = false; } } } diff --git a/modules/Battery.qml b/modules/Battery.qml index 11d6c1b..3e5c0a2 100644 --- a/modules/Battery.qml +++ b/modules/Battery.qml @@ -4,7 +4,7 @@ import "." as M M.BarSection { id: root - spacing: 4 + spacing: M.Theme.moduleSpacing visible: UPower.displayDevice?.isLaptopBattery ?? false tooltip: { const state = root.charging ? "Charging" : "Discharging"; @@ -20,7 +20,8 @@ M.BarSection { M.BarIcon { icon: { - if (root.charging) return "\uDB80\uDC84"; + if (root.charging) + return "\uDB80\uDC84"; const icons = ["\uDB80\uDC8E", "\uDB80\uDC7A", "\uDB80\uDC7B", "\uDB80\uDC7C", "\uDB80\uDC7D", "\uDB80\uDC7E", "\uDB80\uDC7F", "\uDB80\uDC80", "\uDB80\uDC81", "\uDB80\uDC82", "\uDB85\uDFE2"]; return icons[Math.min(10, Math.floor(root.pct / 10))]; } diff --git a/modules/Bluetooth.qml b/modules/Bluetooth.qml index 07e2c56..99abd20 100644 --- a/modules/Bluetooth.qml +++ b/modules/Bluetooth.qml @@ -4,7 +4,7 @@ import "." as M M.BarSection { id: root - spacing: 4 + spacing: M.Theme.moduleSpacing tooltip: root.status === "connected" ? "Bluetooth: " + root.device : "Bluetooth: on" property string status: "off" diff --git a/modules/Cpu.qml b/modules/Cpu.qml index 00a1eb6..b9f81fa 100644 --- a/modules/Cpu.qml +++ b/modules/Cpu.qml @@ -4,7 +4,7 @@ import "." as M M.BarSection { id: root - spacing: 2 + spacing: Math.max(1, M.Theme.moduleSpacing - 2) tooltip: "CPU: " + root.usage + "%\n" + root.freqGhz.toFixed(2) + " GHz" property int usage: 0 @@ -25,7 +25,10 @@ M.BarSection { if (dTotal > 0) root.usage = Math.round((1 - dIdle / dTotal) * 100); } - root._prev = { idle, total }; + root._prev = { + idle, + total + }; } } FileView { @@ -33,7 +36,8 @@ M.BarSection { path: "/proc/cpuinfo" onLoaded: { const lines = text().split("\n").filter(l => l.startsWith("cpu MHz")); - if (lines.length === 0) return; + if (lines.length === 0) + return; const sum = lines.reduce((a, l) => a + parseFloat(l.split(":")[1]), 0); root.freqGhz = sum / lines.length / 1000; } @@ -42,7 +46,10 @@ M.BarSection { interval: 1000 running: true repeat: true - onTriggered: { stat.reload(); cpuinfo.reload(); } + onTriggered: { + stat.reload(); + cpuinfo.reload(); + } } M.BarIcon { diff --git a/modules/Disk.qml b/modules/Disk.qml index df33abc..9179fb8 100644 --- a/modules/Disk.qml +++ b/modules/Disk.qml @@ -4,7 +4,7 @@ import "." as M M.BarSection { id: root - spacing: 2 + spacing: Math.max(1, M.Theme.moduleSpacing - 2) tooltip: root.freePct + "% free of " + root.totalTb.toFixed(1) + " TB" property int freePct: 0 diff --git a/modules/Flyout.qml b/modules/Flyout.qml index b342cd5..c5569ae 100644 --- a/modules/Flyout.qml +++ b/modules/Flyout.qml @@ -36,7 +36,7 @@ PanelWindow { color: M.Theme.base01 border.color: M.Theme.base03 border.width: 1 - radius: 4 + radius: M.Theme.radius Text { id: label diff --git a/modules/Memory.qml b/modules/Memory.qml index 1faab25..dda864f 100644 --- a/modules/Memory.qml +++ b/modules/Memory.qml @@ -4,7 +4,7 @@ import "." as M M.BarSection { id: root - spacing: 2 + spacing: Math.max(1, M.Theme.moduleSpacing - 2) tooltip: "Memory: " + root.percent + "% used" property int percent: 0 @@ -16,7 +16,8 @@ M.BarSection { const m = {}; text().split("\n").forEach(l => { const [k, v] = l.split(":"); - if (v) m[k.trim()] = parseInt(v.trim()); + if (v) + m[k.trim()] = parseInt(v.trim()); }); const total = m.MemTotal; const avail = m.MemAvailable; diff --git a/modules/Mpris.qml b/modules/Mpris.qml index 5ed5737..ef08443 100644 --- a/modules/Mpris.qml +++ b/modules/Mpris.qml @@ -4,15 +4,19 @@ import "." as M M.BarSection { id: root - spacing: 4 + spacing: M.Theme.moduleSpacing visible: player !== null tooltip: { const p = root.player; - if (!p) return ""; + if (!p) + return ""; const parts = []; - if (p.trackTitle) parts.push(p.trackTitle); - if (p.trackArtists?.length) parts.push(p.trackArtists.join(", ")); - if (p.trackAlbum) parts.push(p.trackAlbum); + if (p.trackTitle) + parts.push(p.trackTitle); + if (p.trackArtists?.length) + parts.push(p.trackArtists.join(", ")); + if (p.trackAlbum) + parts.push(p.trackAlbum); return parts.join("\n") || p.identity; } diff --git a/modules/Network.qml b/modules/Network.qml index e9451ef..f767a06 100644 --- a/modules/Network.qml +++ b/modules/Network.qml @@ -4,11 +4,14 @@ import "." as M M.BarSection { id: root - spacing: 4 + spacing: M.Theme.moduleSpacing tooltip: { - if (root.state === "wifi") return "WiFi: " + root.essid + (root.ifname ? "\nInterface: " + root.ifname : ""); - if (root.state === "eth") return "Ethernet: " + root.ifname; - if (root.state === "linked") return "Linked: " + root.ifname; + if (root.state === "wifi") + return "WiFi: " + root.essid + (root.ifname ? "\nInterface: " + root.ifname : ""); + if (root.state === "eth") + return "Ethernet: " + root.ifname; + if (root.state === "linked") + return "Linked: " + root.ifname; return "Disconnected"; } @@ -50,9 +53,12 @@ M.BarSection { M.BarIcon { icon: { - if (root.state === "wifi") return "\uF1EB"; - if (root.state === "eth") return "\uDB80\uDE00"; - if (root.state === "linked") return "\uDB85\uDE16"; + if (root.state === "wifi") + return "\uF1EB"; + if (root.state === "eth") + return "\uDB80\uDE00"; + if (root.state === "linked") + return "\uDB85\uDE16"; return "\uDB82\uDCFD"; } anchors.verticalCenter: parent.verticalCenter diff --git a/modules/Notifications.qml b/modules/Notifications.qml index fdca87d..7f5fae4 100644 --- a/modules/Notifications.qml +++ b/modules/Notifications.qml @@ -4,11 +4,13 @@ import "." as M M.BarSection { id: root - spacing: 4 + spacing: M.Theme.moduleSpacing tooltip: { const parts = [root.count + " notification" + (root.count !== 1 ? "s" : "")]; - if (root.dnd) parts.push("Do not disturb"); - if (root.inhibited) parts.push("Inhibited"); + if (root.dnd) + parts.push("Do not disturb"); + if (root.inhibited) + parts.push("Inhibited"); return parts.join("\n"); } @@ -36,8 +38,10 @@ M.BarSection { M.BarIcon { icon: { - if (root.inhibited) return root.count > 0 ? "\uDB80\uDC9B" : "\uDB82\uDE91"; - if (root.dnd) return root.count > 0 ? "\uDB80\uDCA0" : "\uDB82\uDE93"; + if (root.inhibited) + return root.count > 0 ? "\uDB80\uDC9B" : "\uDB82\uDE91"; + if (root.dnd) + return root.count > 0 ? "\uDB80\uDCA0" : "\uDB82\uDE93"; return root.count > 0 ? "\uDB84\uDD6B" : "\uDB80\uDC9C"; } anchors.verticalCenter: parent.verticalCenter @@ -61,5 +65,7 @@ M.BarSection { clicker.running = true; } } - Process { id: clicker } + Process { + id: clicker + } } diff --git a/modules/PowerProfile.qml b/modules/PowerProfile.qml index 09240f5..c770ea3 100644 --- a/modules/PowerProfile.qml +++ b/modules/PowerProfile.qml @@ -9,9 +9,12 @@ M.BarIcon { property string profile: "" icon: { - if (root.profile === "performance") return "\uF0E7"; - if (root.profile === "power-saver") return "\uF06C"; - if (root.profile === "balanced") return "\uF24E"; + if (root.profile === "performance") + return "\uF0E7"; + if (root.profile === "power-saver") + return "\uF06C"; + if (root.profile === "balanced") + return "\uF24E"; return "\uF0E7"; } @@ -34,7 +37,8 @@ M.BarIcon { id: setter property string next: "" command: ["powerprofilesctl", "set", next] - onRunningChanged: if (!running && next !== "") proc.running = true + onRunningChanged: if (!running && next !== "") + proc.running = true } MouseArea { diff --git a/modules/Temperature.qml b/modules/Temperature.qml index c302962..304cc7b 100644 --- a/modules/Temperature.qml +++ b/modules/Temperature.qml @@ -4,7 +4,7 @@ import "." as M M.BarSection { id: root - spacing: 2 + spacing: Math.max(1, M.Theme.moduleSpacing - 2) tooltip: "Temperature: " + root.celsius + "\u00B0C" property int celsius: 0 diff --git a/modules/Theme.qml b/modules/Theme.qml index 27b904e..80c6ba0 100644 --- a/modules/Theme.qml +++ b/modules/Theme.qml @@ -30,6 +30,10 @@ QtObject { property int fontSize: 12 property real barOpacity: 0.9 property int barHeight: 32 + property int barPadding: 8 + property int barSpacing: 12 + property int moduleSpacing: 4 + property int radius: 4 property FileView _themeFile: FileView { path: (Quickshell.env("XDG_CONFIG_HOME") || (Quickshell.env("HOME") + "/.config")) + "/nova-shell/theme.json" @@ -60,5 +64,13 @@ QtObject { root.barOpacity = data.barOpacity; if (data.barHeight !== undefined) root.barHeight = data.barHeight; + if (data.barPadding !== undefined) + root.barPadding = data.barPadding; + if (data.barSpacing !== undefined) + root.barSpacing = data.barSpacing; + if (data.moduleSpacing !== undefined) + root.moduleSpacing = data.moduleSpacing; + if (data.radius !== undefined) + root.radius = data.radius; } } diff --git a/modules/Tray.qml b/modules/Tray.qml index e9a0f07..ae33beb 100644 --- a/modules/Tray.qml +++ b/modules/Tray.qml @@ -5,7 +5,7 @@ import Quickshell.Services.SystemTray RowLayout { id: root - spacing: 6 + spacing: M.Theme.moduleSpacing + 2 required property var bar diff --git a/modules/Volume.qml b/modules/Volume.qml index f17d676..4868064 100644 --- a/modules/Volume.qml +++ b/modules/Volume.qml @@ -4,10 +4,8 @@ import "." as M M.BarSection { id: root - spacing: 4 - tooltip: (root.sink?.description ?? root.sink?.name ?? "Unknown sink") + - "\nVolume: " + Math.round(root.volume * 100) + "%" + - (root.muted ? "\nMuted" : "") + spacing: M.Theme.moduleSpacing + tooltip: (root.sink?.description ?? root.sink?.name ?? "Unknown sink") + "\nVolume: " + Math.round(root.volume * 100) + "%" + (root.muted ? "\nMuted" : "") PwObjectTracker { objects: [Pipewire.defaultAudioSink] @@ -27,12 +25,14 @@ M.BarSection { } TapHandler { - onTapped: if (root.sink?.audio) root.sink.audio.muted = !root.sink.audio.muted + onTapped: if (root.sink?.audio) + root.sink.audio.muted = !root.sink.audio.muted } WheelHandler { onWheel: event => { - if (!root.sink?.audio) return; + if (!root.sink?.audio) + return; root.sink.audio.volume = Math.max(0, root.sink.audio.volume + (event.angleDelta.y > 0 ? 0.05 : -0.05)); } } diff --git a/modules/Weather.qml b/modules/Weather.qml index 94f8bd6..b8d03d0 100644 --- a/modules/Weather.qml +++ b/modules/Weather.qml @@ -4,7 +4,7 @@ import "." as M M.BarSection { id: root - spacing: 4 + spacing: M.Theme.moduleSpacing tooltip: root.weatherTooltip property string weatherTooltip: "" diff --git a/modules/Workspaces.qml b/modules/Workspaces.qml index a134eda..d379941 100644 --- a/modules/Workspaces.qml +++ b/modules/Workspaces.qml @@ -3,5 +3,5 @@ import QtQuick.Layouts // Placeholder — Quickshell.Services.Niri not yet available RowLayout { - spacing: 4 + spacing: M.Theme.moduleSpacing } diff --git a/nix/hm-module.nix b/nix/hm-module.nix index 893015c..656a1d9 100644 --- a/nix/hm-module.nix +++ b/nix/hm-module.nix @@ -57,7 +57,8 @@ in default = { }; description = '' Theme overrides written to `$XDG_CONFIG_HOME/nova-shell/theme.json`. - Keys: colors (base00-base0F), fontFamily, iconFontFamily, fontSize, barOpacity, barHeight. + Keys: colors (base00-base0F), fontFamily, iconFontFamily, fontSize, + barOpacity, barHeight, barPadding, barSpacing, moduleSpacing, radius. Automatically populated from stylix when it is available. ''; };