From 1ba98534ebc5ca06f105b5d318260760ea42d571 Mon Sep 17 00:00:00 2001 From: Kat Inskip Date: Sun, 7 Dec 2025 23:37:25 -0800 Subject: [PATCH] feat: battery, refactor --- quickshell/Components/Battery.qml | 96 +++++++++++++++++++ .../NotificationActions.qml | 0 .../NotificationDisplay.qml | 0 .../NotificationHeader.qml | 0 .../NotificationImage.qml | 0 .../NotificationItem.qml | 0 .../NotificationWindow.qml | 0 .../NotificationWindowHeader.qml | 0 .../{ => SystemTray}/SystemTray.qml | 0 .../{ => SystemTray}/SystemTrayButton.qml | 0 .../{ => SystemTray}/SystemTraySeparator.qml | 0 .../{ => SystemTray}/SystemTrayWrapper.qml | 7 +- .../WorkspaceButton.qml | 0 .../{ => WorkspaceControl}/Workspaces.qml | 0 quickshell/Modules/Bar.qml | 25 ++++- 15 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 quickshell/Components/Battery.qml rename quickshell/Components/{NotificationSystem => NotificationArea}/NotificationActions.qml (100%) rename quickshell/Components/{NotificationSystem => NotificationArea}/NotificationDisplay.qml (100%) rename quickshell/Components/{NotificationSystem => NotificationArea}/NotificationHeader.qml (100%) rename quickshell/Components/{NotificationSystem => NotificationArea}/NotificationImage.qml (100%) rename quickshell/Components/{NotificationSystem => NotificationArea}/NotificationItem.qml (100%) rename quickshell/Components/{NotificationSystem => NotificationArea}/NotificationWindow.qml (100%) rename quickshell/Components/{NotificationSystem => NotificationArea}/NotificationWindowHeader.qml (100%) rename quickshell/Components/{ => SystemTray}/SystemTray.qml (100%) rename quickshell/Components/{ => SystemTray}/SystemTrayButton.qml (100%) rename quickshell/Components/{ => SystemTray}/SystemTraySeparator.qml (100%) rename quickshell/Components/{ => SystemTray}/SystemTrayWrapper.qml (89%) rename quickshell/Components/{ => WorkspaceControl}/WorkspaceButton.qml (100%) rename quickshell/Components/{ => WorkspaceControl}/Workspaces.qml (100%) diff --git a/quickshell/Components/Battery.qml b/quickshell/Components/Battery.qml new file mode 100644 index 00000000..0ce4e84b --- /dev/null +++ b/quickshell/Components/Battery.qml @@ -0,0 +1,96 @@ +import QtQuick +import QtQuick.Controls +import Quickshell +import Quickshell.Widgets +import Quickshell.Services.UPower +import "root:/DataSources" + +Loader { + property UPowerDevice mainBat: UPower.displayDevice + active: mainBat.isLaptopBattery + sourceComponent: batIcon + + function findClosestIndex(percent) { + return Math.round(percent/10) + } + + property list percentIcons: [ + "󰂎", + "󰁺", + "󰁼", + "󰁼", + "󰁽", + "󰁾", + "󰁿", + "󰂀", + "󰂁", + "󰂂", + "󰁹" + ] + + property string chargingIcon: "󰂄" + + function getIcon(percent) { + if (mainBat.timeToEmpty == 0) { + return chargingIcon + } else { + var percentIcon = percentIcons[findClosestIndex(percent)]; + return percentIcon + } + } + + function getTimeLeft(allSeconds, filling) { + const hours = Math.floor(allSeconds / 3600) + const minutes = Math.floor((allSeconds % 3600) / 60) + const seconds = Math.floor((allSeconds % 3600) / 60) / 60 + const fillString = filling ? "full" : "empty" + + return `${hours}h${minutes}m${seconds}s remain until ${fillString}` + } + + function getTimeLeftT() { + if (mainBat.timeToEmpty == 0) { + return getTimeLeft(mainBat.timeToEmpty, false) + } else if (mainBat.timeToFull == 0) { + return getTimeLeft(mainBat.timeToFull, true) + } + } + + function changeRate() { + return `${Math.round(mainBat.changeRate)}W` + } + + function energyLeft() { + return `${Math.round(mainBat.energy)}Wh` + } + + function getTooltip() { + return `${getTimeLeftT()}, ${energyLeft()}, ${changeRate()}` + } + + Component { + id: batIcon + Item { + MarginWrapperManager { margin: 10 } + Text { + color: Stylix.base05 + text: `${getIcon(mainBat.percentage)} ${Math.round(mainBat.percentage)} %` + + ToolTip { + id: dismissTooltip + visible: false + delay: 500 + timeout: 1000 + text: getTooltip() + } + + HoverHandler { + id: dismissHover + onHoveredChanged: { + dismissTooltip.visible = hovered + } + } + } + } + } +} diff --git a/quickshell/Components/NotificationSystem/NotificationActions.qml b/quickshell/Components/NotificationArea/NotificationActions.qml similarity index 100% rename from quickshell/Components/NotificationSystem/NotificationActions.qml rename to quickshell/Components/NotificationArea/NotificationActions.qml diff --git a/quickshell/Components/NotificationSystem/NotificationDisplay.qml b/quickshell/Components/NotificationArea/NotificationDisplay.qml similarity index 100% rename from quickshell/Components/NotificationSystem/NotificationDisplay.qml rename to quickshell/Components/NotificationArea/NotificationDisplay.qml diff --git a/quickshell/Components/NotificationSystem/NotificationHeader.qml b/quickshell/Components/NotificationArea/NotificationHeader.qml similarity index 100% rename from quickshell/Components/NotificationSystem/NotificationHeader.qml rename to quickshell/Components/NotificationArea/NotificationHeader.qml diff --git a/quickshell/Components/NotificationSystem/NotificationImage.qml b/quickshell/Components/NotificationArea/NotificationImage.qml similarity index 100% rename from quickshell/Components/NotificationSystem/NotificationImage.qml rename to quickshell/Components/NotificationArea/NotificationImage.qml diff --git a/quickshell/Components/NotificationSystem/NotificationItem.qml b/quickshell/Components/NotificationArea/NotificationItem.qml similarity index 100% rename from quickshell/Components/NotificationSystem/NotificationItem.qml rename to quickshell/Components/NotificationArea/NotificationItem.qml diff --git a/quickshell/Components/NotificationSystem/NotificationWindow.qml b/quickshell/Components/NotificationArea/NotificationWindow.qml similarity index 100% rename from quickshell/Components/NotificationSystem/NotificationWindow.qml rename to quickshell/Components/NotificationArea/NotificationWindow.qml diff --git a/quickshell/Components/NotificationSystem/NotificationWindowHeader.qml b/quickshell/Components/NotificationArea/NotificationWindowHeader.qml similarity index 100% rename from quickshell/Components/NotificationSystem/NotificationWindowHeader.qml rename to quickshell/Components/NotificationArea/NotificationWindowHeader.qml diff --git a/quickshell/Components/SystemTray.qml b/quickshell/Components/SystemTray/SystemTray.qml similarity index 100% rename from quickshell/Components/SystemTray.qml rename to quickshell/Components/SystemTray/SystemTray.qml diff --git a/quickshell/Components/SystemTrayButton.qml b/quickshell/Components/SystemTray/SystemTrayButton.qml similarity index 100% rename from quickshell/Components/SystemTrayButton.qml rename to quickshell/Components/SystemTray/SystemTrayButton.qml diff --git a/quickshell/Components/SystemTraySeparator.qml b/quickshell/Components/SystemTray/SystemTraySeparator.qml similarity index 100% rename from quickshell/Components/SystemTraySeparator.qml rename to quickshell/Components/SystemTray/SystemTraySeparator.qml diff --git a/quickshell/Components/SystemTrayWrapper.qml b/quickshell/Components/SystemTray/SystemTrayWrapper.qml similarity index 89% rename from quickshell/Components/SystemTrayWrapper.qml rename to quickshell/Components/SystemTray/SystemTrayWrapper.qml index f5f78a83..8510e3dd 100644 --- a/quickshell/Components/SystemTrayWrapper.qml +++ b/quickshell/Components/SystemTray/SystemTrayWrapper.qml @@ -33,16 +33,15 @@ Item { property real clicky id: wrapperPopup anchor.window: root.QsWindow.window - anchor.rect.y: parentWindow.height + anchor.rect.y: parentWindow?.height ?? 0 anchor.rect.x: clicky implicitWidth: systray.width + 10 - implicitHeight: systray.height + 10 + implicitHeight: systray?.height + 10 color: "transparent" Rectangle { anchors.fill: parent color: Stylix.base01 - bottomLeftRadius: 5 - bottomRightRadius: 5 + radius: 5 SystemTray { id: systray } diff --git a/quickshell/Components/WorkspaceButton.qml b/quickshell/Components/WorkspaceControl/WorkspaceButton.qml similarity index 100% rename from quickshell/Components/WorkspaceButton.qml rename to quickshell/Components/WorkspaceControl/WorkspaceButton.qml diff --git a/quickshell/Components/Workspaces.qml b/quickshell/Components/WorkspaceControl/Workspaces.qml similarity index 100% rename from quickshell/Components/Workspaces.qml rename to quickshell/Components/WorkspaceControl/Workspaces.qml diff --git a/quickshell/Modules/Bar.qml b/quickshell/Modules/Bar.qml index c7a10577..88fc1a6c 100644 --- a/quickshell/Modules/Bar.qml +++ b/quickshell/Modules/Bar.qml @@ -1,11 +1,14 @@ import Quickshell import Quickshell.Io +import Quickshell.Widgets import QtQuick import QtQuick.Layouts import QtQuick.Controls import "root:/DataSources" import "root:/Components" -import "root:/Components/NotificationSystem" +import "root:/Components/WorkspaceControl" +import "root:/Components/SystemTray" +import "root:/Components/NotificationArea" Scope { id: root @@ -34,7 +37,13 @@ Scope { Rectangle { id: bar - anchors.fill: parent + anchors { + top: parent.top + left: parent.left + bottom: parent.bottom + } + + MarginWrapperManager { margin: 10 } radius: 10 color: Stylix.base00 @@ -54,11 +63,22 @@ Scope { } FocusedWindow {} } + } RowLayout { anchors.centerIn: parent spacing: 20 } + Rectangle { + MarginWrapperManager { margin: 10 } + id: bar3 + radius: 10 + color: Stylix.base00 + anchors { + top: parent.top + right: parent.right + bottom: parent.bottom + } RowLayout { anchors { @@ -71,6 +91,7 @@ Scope { spacing: 15 + Battery {} SystemTrayWrapper {} Clock {} NotificationDisplay {}