extract constants

This commit is contained in:
Damocles 2026-04-12 10:57:48 +02:00
parent bc3a85d18d
commit b969f0824f
22 changed files with 106 additions and 63 deletions

View file

@ -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) {

View file

@ -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

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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))];
}

View file

@ -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"

View file

@ -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 {

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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;
}

View file

@ -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

View file

@ -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
}
}

View file

@ -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 {

View file

@ -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

View file

@ -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;
}
}

View file

@ -5,7 +5,7 @@ import Quickshell.Services.SystemTray
RowLayout {
id: root
spacing: 6
spacing: M.Theme.moduleSpacing + 2
required property var bar

View file

@ -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));
}
}

View file

@ -4,7 +4,7 @@ import "." as M
M.BarSection {
id: root
spacing: 4
spacing: M.Theme.moduleSpacing
tooltip: root.weatherTooltip
property string weatherTooltip: ""

View file

@ -3,5 +3,5 @@ import QtQuick.Layouts
// Placeholder Quickshell.Services.Niri not yet available
RowLayout {
spacing: 4
spacing: M.Theme.moduleSpacing
}

View file

@ -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.
'';
};