move stuff into components

This commit is contained in:
Damocles 2026-04-12 00:56:17 +02:00
parent 6370732e4e
commit 14292e6683
17 changed files with 81 additions and 149 deletions

View file

@ -1,12 +1,12 @@
import QtQuick import QtQuick
import Quickshell.Io import Quickshell.Io
import QtQuick.Controls
import "." as M import "." as M
Row { M.BarSection {
id: root id: root
spacing: 4 spacing: 4
visible: percent > 0 visible: percent > 0
tooltip: "Brightness: " + root.percent + "%"
property int percent: 0 property int percent: 0
@ -53,9 +53,4 @@ Row {
WheelHandler { WheelHandler {
onWheel: event => root.adjust(event.angleDelta.y) onWheel: event => root.adjust(event.angleDelta.y)
} }
HoverHandler { id: hover }
ToolTip {
visible: hover.hovered
text: "Brightness: " + root.percent + "%"
}
} }

View file

@ -1,12 +1,20 @@
import QtQuick import QtQuick
import QtQuick.Controls
import "." as M import "." as M
Text { Text {
property string icon: "" property string icon: ""
property string tooltip: ""
text: icon text: icon
color: M.Theme.base05 color: M.Theme.base05
font.pixelSize: M.Theme.fontSize + 1 font.pixelSize: M.Theme.fontSize + 1
font.family: M.Theme.iconFontFamily font.family: M.Theme.iconFontFamily
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
HoverHandler { id: _hover }
ToolTip {
visible: _hover.hovered && parent.tooltip !== ""
text: parent.tooltip
}
} }

12
modules/BarSection.qml Normal file
View file

@ -0,0 +1,12 @@
import QtQuick
import QtQuick.Controls
Row {
property string tooltip: ""
HoverHandler { id: _hover }
ToolTip {
visible: _hover.hovered && parent.tooltip !== ""
text: parent.tooltip
}
}

View file

@ -1,12 +1,18 @@
import QtQuick import QtQuick
import QtQuick.Controls
import Quickshell.Services.UPower import Quickshell.Services.UPower
import "." as M import "." as M
Row { M.BarSection {
id: root id: root
spacing: 4 spacing: 4
visible: UPower.displayDevice?.isLaptopBattery ?? false visible: UPower.displayDevice?.isLaptopBattery ?? false
tooltip: {
const state = root.charging ? "Charging" : "Discharging";
const t = root.charging ? root.dev?.timeToFull : root.dev?.timeToEmpty;
const mins = t ? Math.round(t / 60) : 0;
const timeStr = mins > 0 ? "\n" + Math.floor(mins / 60) + "h " + (mins % 60) + "m " + (root.charging ? "until full" : "remaining") : "";
return state + " \u2014 " + Math.round(root.pct) + "%" + timeStr;
}
readonly property var dev: UPower.displayDevice readonly property var dev: UPower.displayDevice
readonly property real pct: (dev?.percentage ?? 0) * 100 readonly property real pct: (dev?.percentage ?? 0) * 100
@ -27,16 +33,4 @@ Row {
color: root.pct < 15 ? M.Theme.base08 : M.Theme.base05 color: root.pct < 15 ? M.Theme.base08 : M.Theme.base05
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
HoverHandler { id: hover }
ToolTip {
visible: hover.hovered
text: {
const state = root.charging ? "Charging" : "Discharging";
const t = root.charging ? root.dev?.timeToFull : root.dev?.timeToEmpty;
const mins = t ? Math.round(t / 60) : 0;
const timeStr = mins > 0 ? "\n" + Math.floor(mins / 60) + "h " + (mins % 60) + "m " + (root.charging ? "until full" : "remaining") : "";
return state + " — " + Math.round(root.pct) + "%" + timeStr;
}
}
} }

View file

@ -1,11 +1,11 @@
import QtQuick import QtQuick
import Quickshell.Io import Quickshell.Io
import QtQuick.Controls
import "." as M import "." as M
Row { M.BarSection {
id: root id: root
spacing: 4 spacing: 4
tooltip: root.status === "connected" ? "Bluetooth: " + root.device : "Bluetooth: on"
property string status: "off" property string status: "off"
property string device: "" property string device: ""
@ -42,9 +42,4 @@ Row {
font.family: M.Theme.fontFamily font.family: M.Theme.fontFamily
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
HoverHandler { id: hover }
ToolTip {
visible: hover.hovered
text: root.status === "connected" ? "Bluetooth: " + root.device : "Bluetooth: on"
}
} }

View file

@ -1,15 +1,14 @@
import QtQuick import QtQuick
import Quickshell.Io import Quickshell.Io
import QtQuick.Controls
import "." as M import "." as M
Row { M.BarSection {
id: root id: root
spacing: 2 spacing: 2
tooltip: "CPU: " + root.usage + "%\n" + root.freqGhz.toFixed(2) + " GHz"
property int usage: 0 property int usage: 0
property real freqGhz: 0 property real freqGhz: 0
property var _prev: null property var _prev: null
FileView { FileView {
@ -26,10 +25,7 @@ Row {
if (dTotal > 0) if (dTotal > 0)
root.usage = Math.round((1 - dIdle / dTotal) * 100); root.usage = Math.round((1 - dIdle / dTotal) * 100);
} }
root._prev = { root._prev = { idle, total };
idle,
total
};
} }
} }
FileView { FileView {
@ -37,8 +33,7 @@ Row {
path: "/proc/cpuinfo" path: "/proc/cpuinfo"
onLoaded: { onLoaded: {
const lines = text().split("\n").filter(l => l.startsWith("cpu MHz")); const lines = text().split("\n").filter(l => l.startsWith("cpu MHz"));
if (lines.length === 0) if (lines.length === 0) return;
return;
const sum = lines.reduce((a, l) => a + parseFloat(l.split(":")[1]), 0); const sum = lines.reduce((a, l) => a + parseFloat(l.split(":")[1]), 0);
root.freqGhz = sum / lines.length / 1000; root.freqGhz = sum / lines.length / 1000;
} }
@ -47,10 +42,7 @@ Row {
interval: 1000 interval: 1000
running: true running: true
repeat: true repeat: true
onTriggered: { onTriggered: { stat.reload(); cpuinfo.reload(); }
stat.reload();
cpuinfo.reload();
}
} }
M.BarIcon { M.BarIcon {
@ -64,9 +56,4 @@ Row {
font.family: M.Theme.fontFamily font.family: M.Theme.fontFamily
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
HoverHandler { id: hover }
ToolTip {
visible: hover.hovered
text: "CPU: " + root.usage + "%\n" + root.freqGhz.toFixed(2) + " GHz"
}
} }

View file

@ -1,11 +1,11 @@
import QtQuick import QtQuick
import Quickshell.Io import Quickshell.Io
import QtQuick.Controls
import "." as M import "." as M
Row { M.BarSection {
id: root id: root
spacing: 2 spacing: 2
tooltip: root.freePct + "% free of " + root.totalTb.toFixed(1) + " TB"
property int freePct: 0 property int freePct: 0
property real totalTb: 0 property real totalTb: 0
@ -43,9 +43,4 @@ Row {
font.family: M.Theme.fontFamily font.family: M.Theme.fontFamily
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
HoverHandler { id: hover }
ToolTip {
visible: hover.hovered
text: root.freePct + "% free of " + root.totalTb.toFixed(1) + " TB"
}
} }

View file

@ -1,10 +1,10 @@
import QtQuick import QtQuick
import Quickshell.Io import Quickshell.Io
import QtQuick.Controls
import "." as M import "." as M
M.BarIcon { M.BarIcon {
id: root id: root
tooltip: "Idle inhibition: " + (root.active ? "active" : "inactive")
property bool active: false property bool active: false
@ -23,9 +23,4 @@ M.BarIcon {
toggle.running = true; toggle.running = true;
} }
} }
HoverHandler { id: hover }
ToolTip {
visible: hover.hovered
text: "Idle inhibition: " + (root.active ? "active" : "inactive")
}
} }

View file

@ -1,11 +1,11 @@
import QtQuick import QtQuick
import Quickshell.Io import Quickshell.Io
import QtQuick.Controls
import "." as M import "." as M
Row { M.BarSection {
id: root id: root
spacing: 2 spacing: 2
tooltip: "Memory: " + root.percent + "% used"
property int percent: 0 property int percent: 0
@ -16,8 +16,7 @@ Row {
const m = {}; const m = {};
text().split("\n").forEach(l => { text().split("\n").forEach(l => {
const [k, v] = l.split(":"); const [k, v] = l.split(":");
if (v) if (v) m[k.trim()] = parseInt(v.trim());
m[k.trim()] = parseInt(v.trim());
}); });
const total = m.MemTotal; const total = m.MemTotal;
const avail = m.MemAvailable; const avail = m.MemAvailable;
@ -43,9 +42,4 @@ Row {
font.family: M.Theme.fontFamily font.family: M.Theme.fontFamily
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
HoverHandler { id: hover }
ToolTip {
visible: hover.hovered
text: "Memory: " + root.percent + "% used"
}
} }

View file

@ -1,12 +1,20 @@
import QtQuick import QtQuick
import QtQuick.Controls
import Quickshell.Services.Mpris import Quickshell.Services.Mpris
import "." as M import "." as M
Row { M.BarSection {
id: root id: root
spacing: 4 spacing: 4
visible: player !== null visible: player !== null
tooltip: {
const p = root.player;
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);
return parts.join("\n") || p.identity;
}
readonly property MprisPlayer player: Mpris.players.values[0] ?? null readonly property MprisPlayer player: Mpris.players.values[0] ?? null
readonly property bool playing: player?.playbackState === MprisPlaybackState.Playing readonly property bool playing: player?.playbackState === MprisPlaybackState.Playing
@ -20,20 +28,6 @@ Row {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
HoverHandler { id: hover }
ToolTip {
visible: hover.hovered
text: {
const p = root.player;
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);
return parts.join("\n") || p.identity;
}
}
TapHandler { TapHandler {
onTapped: root.player?.togglePlaying() onTapped: root.player?.togglePlaying()
} }

View file

@ -1,11 +1,16 @@
import QtQuick import QtQuick
import QtQuick.Controls
import Quickshell.Io import Quickshell.Io
import "." as M import "." as M
Row { M.BarSection {
id: root id: root
spacing: 4 spacing: 4
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;
return "Disconnected";
}
property string ifname: "" property string ifname: ""
property string essid: "" property string essid: ""
@ -45,12 +50,9 @@ Row {
M.BarIcon { M.BarIcon {
icon: { icon: {
if (root.state === "wifi") if (root.state === "wifi") return "\uF1EB";
return "\uF1EB"; if (root.state === "eth") return "\uDB80\uDE00";
if (root.state === "eth") if (root.state === "linked") return "\uDB85\uDE16";
return "\uDB80\uDE00";
if (root.state === "linked")
return "\uDB85\uDE16";
return "\uDB82\uDCFD"; return "\uDB82\uDCFD";
} }
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@ -63,15 +65,4 @@ Row {
font.family: M.Theme.fontFamily font.family: M.Theme.fontFamily
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
HoverHandler { id: hover }
ToolTip {
visible: hover.hovered
text: {
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";
}
}
} }

View file

@ -1,11 +1,16 @@
import QtQuick import QtQuick
import QtQuick.Controls
import Quickshell.Io import Quickshell.Io
import "." as M import "." as M
Row { M.BarSection {
id: root id: root
spacing: 4 spacing: 4
tooltip: {
const parts = [root.count + " notification" + (root.count !== 1 ? "s" : "")];
if (root.dnd) parts.push("Do not disturb");
if (root.inhibited) parts.push("Inhibited");
return parts.join("\n");
}
property int count: 0 property int count: 0
property bool dnd: false property bool dnd: false
@ -56,18 +61,5 @@ Row {
clicker.running = true; clicker.running = true;
} }
} }
Process { Process { id: clicker }
id: clicker
}
HoverHandler { id: hover }
ToolTip {
visible: hover.hovered
text: {
const parts = [];
parts.push(root.count + " notification" + (root.count !== 1 ? "s" : ""));
if (root.dnd) parts.push("Do not disturb");
if (root.inhibited) parts.push("Inhibited");
return parts.join("\n");
}
}
} }

View file

@ -1,10 +1,10 @@
import QtQuick import QtQuick
import Quickshell.Io import Quickshell.Io
import QtQuick.Controls
import "." as M import "." as M
M.BarIcon { M.BarIcon {
id: root id: root
tooltip: "Power profile: " + (root.profile || "unknown")
property string profile: "" property string profile: ""
@ -45,9 +45,4 @@ M.BarIcon {
setter.running = true; setter.running = true;
} }
} }
HoverHandler { id: hover }
ToolTip {
visible: hover.hovered
text: "Power profile: " + (root.profile || "unknown")
}
} }

View file

@ -1,11 +1,11 @@
import QtQuick import QtQuick
import Quickshell.Io import Quickshell.Io
import QtQuick.Controls
import "." as M import "." as M
Row { M.BarSection {
id: root id: root
spacing: 2 spacing: 2
tooltip: "Temperature: " + root.celsius + "\u00B0C"
property int celsius: 0 property int celsius: 0
@ -27,15 +27,10 @@ Row {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
Text { Text {
text: root.celsius + "°C" text: root.celsius + "\u00B0C"
color: root.celsius > 80 ? M.Theme.base08 : M.Theme.base05 color: root.celsius > 80 ? M.Theme.base08 : M.Theme.base05
font.pixelSize: M.Theme.fontSize font.pixelSize: M.Theme.fontSize
font.family: M.Theme.fontFamily font.family: M.Theme.fontFamily
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
HoverHandler { id: hover }
ToolTip {
visible: hover.hovered
text: "Temperature: " + root.celsius + "\u00B0C"
}
} }

View file

@ -1,11 +1,13 @@
import QtQuick import QtQuick
import QtQuick.Controls
import Quickshell.Services.Pipewire import Quickshell.Services.Pipewire
import "." as M import "." as M
Row { M.BarSection {
id: root id: root
spacing: 4 spacing: 4
tooltip: (root.sink?.description ?? root.sink?.name ?? "Unknown sink") +
"\nVolume: " + Math.round(root.volume * 100) + "%" +
(root.muted ? "\nMuted" : "")
PwObjectTracker { PwObjectTracker {
objects: [Pipewire.defaultAudioSink] objects: [Pipewire.defaultAudioSink]
@ -24,14 +26,6 @@ Row {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
HoverHandler { id: hover }
ToolTip {
visible: hover.hovered
text: (root.sink?.description ?? root.sink?.name ?? "Unknown sink") +
"\nVolume: " + Math.round(root.volume * 100) + "%" +
(root.muted ? "\nMuted" : "")
}
TapHandler { 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
} }

View file

@ -1,10 +1,10 @@
import QtQuick import QtQuick
import Quickshell.Io import Quickshell.Io
import QtQuick.Controls
import "." as M import "." as M
M.BarIcon { M.BarIcon {
icon: "\uF011" icon: "\uF011"
tooltip: "Open logout menu"
Process { Process {
id: proc id: proc
@ -16,9 +16,4 @@ M.BarIcon {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: proc.running = true onClicked: proc.running = true
} }
HoverHandler { id: hover }
ToolTip {
visible: hover.hovered
text: "Open logout menu"
}
} }

View file

@ -1,6 +1,7 @@
module modules module modules
singleton Theme 1.0 Theme.qml singleton Theme 1.0 Theme.qml
Bar 1.0 Bar.qml Bar 1.0 Bar.qml
BarSection 1.0 BarSection.qml
Workspaces 1.0 Workspaces.qml Workspaces 1.0 Workspaces.qml
WindowTitle 1.0 WindowTitle.qml WindowTitle 1.0 WindowTitle.qml
Clock 1.0 Clock.qml Clock 1.0 Clock.qml