From 00838e1d64f29e3e2a153d6a314e8eeee7a4e677 Mon Sep 17 00:00:00 2001 From: Damocles Date: Sat, 11 Apr 2026 00:35:37 +0200 Subject: [PATCH] dedup, monospace font for icons --- modules/Backlight.qml | 2 +- modules/BarIcon.qml | 12 ++++++++++++ modules/BarLabel.qml | 12 ++++++++++++ modules/Battery.qml | 14 +++++--------- modules/Bluetooth.qml | 2 +- modules/Cpu.qml | 2 +- modules/Disk.qml | 2 +- modules/IdleInhibitor.qml | 8 ++------ modules/Memory.qml | 2 +- modules/Mpris.qml | 14 ++++---------- modules/Network.qml | 2 +- modules/Notifications.qml | 20 ++++++-------------- modules/PowerProfile.qml | 23 ++++++++--------------- modules/Temperature.qml | 2 +- modules/Theme.qml | 3 +++ modules/Volume.qml | 18 +++++------------- modules/Wlogout.qml | 8 ++------ nix/hm-module.nix | 1 + 18 files changed, 67 insertions(+), 80 deletions(-) create mode 100644 modules/BarIcon.qml create mode 100644 modules/BarLabel.qml diff --git a/modules/Backlight.qml b/modules/Backlight.qml index 8eddbf2..4f33b24 100644 --- a/modules/Backlight.qml +++ b/modules/Backlight.qml @@ -33,7 +33,7 @@ Row { text: root.percent + "% " color: M.Theme.base05 font.pixelSize: M.Theme.fontSize - font.family: M.Theme.fontFamily + font.family: M.Theme.iconFontFamily anchors.verticalCenter: parent.verticalCenter } } diff --git a/modules/BarIcon.qml b/modules/BarIcon.qml new file mode 100644 index 0000000..82a4df5 --- /dev/null +++ b/modules/BarIcon.qml @@ -0,0 +1,12 @@ +import QtQuick +import "." as M + +Text { + property string icon: "" + + text: icon + color: M.Theme.base05 + font.pixelSize: M.Theme.fontSize + 1 + font.family: M.Theme.iconFontFamily + verticalAlignment: Text.AlignVCenter +} diff --git a/modules/BarLabel.qml b/modules/BarLabel.qml new file mode 100644 index 0000000..c16119f --- /dev/null +++ b/modules/BarLabel.qml @@ -0,0 +1,12 @@ +import QtQuick +import "." as M + +Text { + property string label: "" + + text: label + color: M.Theme.base05 + font.pixelSize: M.Theme.fontSize + font.family: M.Theme.fontFamily + verticalAlignment: Text.AlignVCenter +} diff --git a/modules/Battery.qml b/modules/Battery.qml index 50bb983..15e4233 100644 --- a/modules/Battery.qml +++ b/modules/Battery.qml @@ -11,23 +11,19 @@ Row { readonly property real pct: (dev?.percentage ?? 0) * 100 readonly property bool charging: dev?.state === UPowerDeviceState.Charging - Text { - text: { - if (root.charging) - return ""; + M.BarIcon { + icon: { + if (root.charging) return ""; const icons = ["󰂎", "󰁺", "󰁻", "󰁼", "󰁽", "󰁾", "󰁿", "󰂀", "󰂁", "󰂂", "󱟢"]; return icons[Math.min(10, Math.floor(root.pct / 10))]; } color: root.pct < 15 ? M.Theme.base08 : M.Theme.base05 font.pixelSize: M.Theme.fontSize + 2 - font.family: M.Theme.fontFamily anchors.verticalCenter: parent.verticalCenter } - Text { - text: Math.round(root.pct) + "%" + M.BarLabel { + label: Math.round(root.pct) + "%" color: root.pct < 15 ? M.Theme.base08 : M.Theme.base05 - font.pixelSize: M.Theme.fontSize - font.family: M.Theme.fontFamily anchors.verticalCenter: parent.verticalCenter } } diff --git a/modules/Bluetooth.qml b/modules/Bluetooth.qml index c6e530e..51fb5bf 100644 --- a/modules/Bluetooth.qml +++ b/modules/Bluetooth.qml @@ -32,7 +32,7 @@ Row { text: root.status === "connected" ? (" " + root.device) : "" color: M.Theme.base05 font.pixelSize: M.Theme.fontSize + 1 - font.family: M.Theme.fontFamily + font.family: M.Theme.iconFontFamily anchors.verticalCenter: parent.verticalCenter } } diff --git a/modules/Cpu.qml b/modules/Cpu.qml index b372566..bc62490 100644 --- a/modules/Cpu.qml +++ b/modules/Cpu.qml @@ -54,6 +54,6 @@ Text { text: " " + root.usage.toString().padStart(2) + "%@" + root.freqGhz.toFixed(2) color: M.Theme.base05 font.pixelSize: M.Theme.fontSize - font.family: M.Theme.fontFamily + font.family: M.Theme.iconFontFamily verticalAlignment: Text.AlignVCenter } diff --git a/modules/Disk.qml b/modules/Disk.qml index 39969e0..4ac0095 100644 --- a/modules/Disk.qml +++ b/modules/Disk.qml @@ -33,6 +33,6 @@ Text { text: " " + root.freePct + "% " + root.totalTb.toFixed(1) color: M.Theme.base05 font.pixelSize: M.Theme.fontSize - font.family: M.Theme.fontFamily + font.family: M.Theme.iconFontFamily verticalAlignment: Text.AlignVCenter } diff --git a/modules/IdleInhibitor.qml b/modules/IdleInhibitor.qml index 4a85188..4d43e5b 100644 --- a/modules/IdleInhibitor.qml +++ b/modules/IdleInhibitor.qml @@ -2,16 +2,12 @@ import QtQuick import Quickshell.Io import "." as M -Text { +M.BarIcon { id: root property bool active: false - text: root.active ? "" : "" - color: M.Theme.base05 - font.pixelSize: M.Theme.fontSize + 1 - font.family: M.Theme.fontFamily - verticalAlignment: Text.AlignVCenter + icon: root.active ? "" : "" Process { id: toggle diff --git a/modules/Memory.qml b/modules/Memory.qml index 851e850..bc49f48 100644 --- a/modules/Memory.qml +++ b/modules/Memory.qml @@ -33,6 +33,6 @@ Text { text: " " + root.percent + "%" color: M.Theme.base05 font.pixelSize: M.Theme.fontSize - font.family: M.Theme.fontFamily + font.family: M.Theme.iconFontFamily verticalAlignment: Text.AlignVCenter } diff --git a/modules/Mpris.qml b/modules/Mpris.qml index eba740b..1703794 100644 --- a/modules/Mpris.qml +++ b/modules/Mpris.qml @@ -10,18 +10,12 @@ Row { readonly property MprisPlayer player: Mpris.players.values[0] ?? null readonly property bool playing: player?.playbackState === MprisPlaybackState.Playing - Text { - text: root.playing ? "" : (root.player?.playbackState === MprisPlaybackState.Paused ? "󰏤" : "󰓛") - color: M.Theme.base05 - font.pixelSize: M.Theme.fontSize + 1 - font.family: M.Theme.fontFamily + M.BarIcon { + icon: root.playing ? "" : (root.player?.playbackState === MprisPlaybackState.Paused ? "󰏤" : "󰓛") anchors.verticalCenter: parent.verticalCenter } - Text { - text: root.player?.identity ?? "" - color: M.Theme.base05 - font.pixelSize: M.Theme.fontSize - font.family: M.Theme.fontFamily + M.BarLabel { + label: root.player?.identity ?? "" anchors.verticalCenter: parent.verticalCenter } diff --git a/modules/Network.qml b/modules/Network.qml index 65d07e8..d323e76 100644 --- a/modules/Network.qml +++ b/modules/Network.qml @@ -54,7 +54,7 @@ Row { } color: M.Theme.base05 font.pixelSize: M.Theme.fontSize + 1 - font.family: M.Theme.fontFamily + font.family: M.Theme.iconFontFamily anchors.verticalCenter: parent.verticalCenter } } diff --git a/modules/Notifications.qml b/modules/Notifications.qml index 49bfc51..8fe2178 100644 --- a/modules/Notifications.qml +++ b/modules/Notifications.qml @@ -28,24 +28,16 @@ Row { } } - Text { - text: { - if (root.inhibited) - return root.count > 0 ? "󰂛" : "󰪑"; - if (root.dnd) - return root.count > 0 ? "󰂠" : "󰪓"; + M.BarIcon { + icon: { + if (root.inhibited) return root.count > 0 ? "󰂛" : "󰪑"; + if (root.dnd) return root.count > 0 ? "󰂠" : "󰪓"; return root.count > 0 ? "󱅫" : "󰂜"; } - color: M.Theme.base05 - font.pixelSize: M.Theme.fontSize + 2 - font.family: M.Theme.fontFamily anchors.verticalCenter: parent.verticalCenter } - Text { - text: root.count > 0 ? String(root.count) : "" - color: M.Theme.base05 - font.pixelSize: M.Theme.fontSize - font.family: M.Theme.fontFamily + M.BarLabel { + label: root.count > 0 ? String(root.count) : "" anchors.verticalCenter: parent.verticalCenter } diff --git a/modules/PowerProfile.qml b/modules/PowerProfile.qml index 34f7b92..8aaf8ad 100644 --- a/modules/PowerProfile.qml +++ b/modules/PowerProfile.qml @@ -2,11 +2,18 @@ import QtQuick import Quickshell.Io import "." as M -Text { +M.BarIcon { id: root property string profile: "" + icon: { + if (root.profile === "performance") return ""; + if (root.profile === "power-saver") return ""; + if (root.profile === "balanced") return ""; + return ""; + } + Process { id: proc running: true @@ -21,18 +28,4 @@ Text { repeat: true onTriggered: proc.running = true } - - text: { - if (root.profile === "performance") - return ""; - if (root.profile === "power-saver") - return ""; - if (root.profile === "balanced") - return ""; - return ""; - } - color: M.Theme.base05 - font.pixelSize: M.Theme.fontSize + 1 - font.family: M.Theme.fontFamily - verticalAlignment: Text.AlignVCenter } diff --git a/modules/Temperature.qml b/modules/Temperature.qml index 59c40b4..3ed517e 100644 --- a/modules/Temperature.qml +++ b/modules/Temperature.qml @@ -22,6 +22,6 @@ Text { text: " " + root.celsius + "°C" color: root.celsius > 80 ? M.Theme.base08 : M.Theme.base05 font.pixelSize: M.Theme.fontSize - font.family: M.Theme.fontFamily + font.family: M.Theme.iconFontFamily verticalAlignment: Text.AlignVCenter } diff --git a/modules/Theme.qml b/modules/Theme.qml index ef4972e..e83e2fd 100644 --- a/modules/Theme.qml +++ b/modules/Theme.qml @@ -26,6 +26,7 @@ QtObject { property color base0F: "#f2cdcd" property string fontFamily: "sans-serif" + property string iconFontFamily: "Symbols Nerd Font Mono" property int fontSize: 12 property real barOpacity: 0.9 property int barHeight: 32 @@ -51,6 +52,8 @@ QtObject { } if (data.fontFamily) root.fontFamily = data.fontFamily; + if (data.iconFontFamily) + root.iconFontFamily = data.iconFontFamily; if (data.fontSize) root.fontSize = data.fontSize; if (data.barOpacity !== undefined) diff --git a/modules/Volume.qml b/modules/Volume.qml index 628b679..aa7ec21 100644 --- a/modules/Volume.qml +++ b/modules/Volume.qml @@ -14,24 +14,16 @@ Row { readonly property real volume: sink?.audio?.volume ?? 0 readonly property bool muted: sink?.audio?.muted ?? false - Text { - text: root.muted ? "" : (root.volume > 0.5 ? "" : (root.volume > 0 ? "" : "")) - color: M.Theme.base05 - font.pixelSize: M.Theme.fontSize + 1 - font.family: M.Theme.fontFamily + M.BarIcon { + icon: root.muted ? "" : (root.volume > 0.5 ? "" : (root.volume > 0 ? "" : "")) anchors.verticalCenter: parent.verticalCenter } - - Text { - text: Math.round(root.volume * 100) + "%" - color: M.Theme.base05 - font.pixelSize: M.Theme.fontSize - font.family: M.Theme.fontFamily + M.BarLabel { + label: Math.round(root.volume * 100) + "%" anchors.verticalCenter: parent.verticalCenter } 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 } } diff --git a/modules/Wlogout.qml b/modules/Wlogout.qml index acaf3ca..e474f37 100644 --- a/modules/Wlogout.qml +++ b/modules/Wlogout.qml @@ -2,12 +2,8 @@ import QtQuick import Quickshell.Io import "." as M -Text { - text: "" - color: M.Theme.base05 - font.pixelSize: M.Theme.fontSize + 2 - font.family: M.Theme.fontFamily - verticalAlignment: Text.AlignVCenter +M.BarIcon { + icon: "" Process { id: proc diff --git a/nix/hm-module.nix b/nix/hm-module.nix index f7feb2d..bb785da 100644 --- a/nix/hm-module.nix +++ b/nix/hm-module.nix @@ -37,6 +37,7 @@ let ; }; fontFamily = f.sansSerif.name; + iconFontFamily = f.monospace.name; fontSize = f.sizes.desktop; barOpacity = 1.0 - config.stylix.opacity.desktop; }