From 101e3125a95c6a73ef33b01650fdb5293a1b524d Mon Sep 17 00:00:00 2001 From: LemmyCook Date: Sat, 13 Sep 2025 13:06:17 -0400 Subject: [PATCH] Vertical bar: simpler management --- Modules/Bar/Bar.qml | 20 ++++++--------- Modules/Bar/Widgets/ActiveWindow.qml | 16 +----------- Modules/Bar/Widgets/Clock.qml | 13 ++-------- Modules/Bar/Widgets/MediaMini.qml | 19 +++----------- Modules/Bar/Widgets/SystemMonitor.qml | 18 ++------------ Modules/Bar/Widgets/Tray.qml | 13 +--------- Modules/Bar/Widgets/Workspace.qml | 21 +++------------- Modules/SettingsPanel/Tabs/BarTab.qml | 4 +-- Services/BarService.qml | 36 --------------------------- Widgets/NPanel.qml | 1 + Widgets/NTooltip.qml | 3 ++- 11 files changed, 25 insertions(+), 139 deletions(-) delete mode 100644 Services/BarService.qml diff --git a/Modules/Bar/Bar.qml b/Modules/Bar/Bar.qml index 5972252..80c6a21 100644 --- a/Modules/Bar/Bar.qml +++ b/Modules/Bar/Bar.qml @@ -108,8 +108,7 @@ Variants { "widgetId": modelData.id, "section": "left", "sectionWidgetIndex": index, - "sectionWidgetsCount": Settings.data.bar.widgets.left.length, - "barPosition": BarService.position + "sectionWidgetsCount": Settings.data.bar.widgets.left.length } anchors.horizontalCenter: parent.horizontalCenter } @@ -133,8 +132,7 @@ Variants { "widgetId": modelData.id, "section": "center", "sectionWidgetIndex": index, - "sectionWidgetsCount": Settings.data.bar.widgets.center.length, - "barPosition": BarService.position + "sectionWidgetsCount": Settings.data.bar.widgets.center.length } anchors.horizontalCenter: parent.horizontalCenter } @@ -159,8 +157,7 @@ Variants { "widgetId": modelData.id, "section": "right", "sectionWidgetIndex": index, - "sectionWidgetsCount": Settings.data.bar.widgets.right.length, - "barPosition": BarService.position + "sectionWidgetsCount": Settings.data.bar.widgets.right.length } anchors.horizontalCenter: parent.horizontalCenter } @@ -193,8 +190,7 @@ Variants { "widgetId": modelData.id, "section": "left", "sectionWidgetIndex": index, - "sectionWidgetsCount": Settings.data.bar.widgets.left.length, - "barPosition": BarService.position + "sectionWidgetsCount": Settings.data.bar.widgets.left.length } } } @@ -218,8 +214,7 @@ Variants { "widgetId": modelData.id, "section": "center", "sectionWidgetIndex": index, - "sectionWidgetsCount": Settings.data.bar.widgets.center.length, - "barPosition": BarService.position + "sectionWidgetsCount": Settings.data.bar.widgets.center.length } } } @@ -244,8 +239,7 @@ Variants { "widgetId": modelData.id, "section": "right", "sectionWidgetIndex": index, - "sectionWidgetsCount": Settings.data.bar.widgets.right.length, - "barPosition": BarService.position + "sectionWidgetsCount": Settings.data.bar.widgets.right.length } } } @@ -255,4 +249,4 @@ Variants { } } } -} +} \ No newline at end of file diff --git a/Modules/Bar/Widgets/ActiveWindow.qml b/Modules/Bar/Widgets/ActiveWindow.qml index cdb8c44..007cb61 100644 --- a/Modules/Bar/Widgets/ActiveWindow.qml +++ b/Modules/Bar/Widgets/ActiveWindow.qml @@ -18,22 +18,7 @@ Item { property string section: "" property int sectionWidgetIndex: -1 property int sectionWidgetsCount: 0 - property string barPosition: "top" - // Listen to BarService position changes - Connections { - target: BarService - function onBarPositionChanged(newPosition) { - barPosition = newPosition - // Force re-evaluation of implicit sizing - implicitWidth = Qt.binding(function () { - return (barPosition === "left" || barPosition === "right") ? Math.round(Style.baseWidgetSize * 0.8 * scaling) : (horizontalLayout.implicitWidth + Style.marginM * 2 * scaling) - }) - implicitHeight = Qt.binding(function () { - return (barPosition === "left" || barPosition === "right") ? calculatedVerticalHeight() : Math.round(Style.barHeight * scaling) - }) - } - } property var widgetMetadata: BarWidgetRegistry.widgetMetadata[widgetId] property var widgetSettings: { @@ -52,6 +37,7 @@ Item { readonly property real minWidth: Math.max(1, screen.width * 0.06) readonly property real maxWidth: minWidth * 2 + readonly property string barPosition: Settings.data.bar.position implicitHeight: (barPosition === "left" || barPosition === "right") ? calculatedVerticalHeight() : Math.round(Style.barHeight * scaling) implicitWidth: (barPosition === "left" || barPosition === "right") ? Math.round(Style.baseWidgetSize * 0.8 * scaling) : (horizontalLayout.implicitWidth + Style.marginM * 2 * scaling) diff --git a/Modules/Bar/Widgets/Clock.qml b/Modules/Bar/Widgets/Clock.qml index e23836e..bfb912a 100644 --- a/Modules/Bar/Widgets/Clock.qml +++ b/Modules/Bar/Widgets/Clock.qml @@ -16,7 +16,6 @@ Rectangle { property string section: "" property int sectionWidgetIndex: -1 property int sectionWidgetsCount: 0 - property string barPosition: "top" property var widgetMetadata: BarWidgetRegistry.widgetMetadata[widgetId] property var widgetSettings: { @@ -29,6 +28,8 @@ Rectangle { return {} } + readonly property string barPosition: Settings.data.bar.position + // Resolve settings: try user settings or defaults from BarWidgetRegistry readonly property bool use12h: widgetSettings.use12HourClock !== undefined ? widgetSettings.use12HourClock : widgetMetadata.use12HourClock readonly property bool reverseDayMonth: widgetSettings.reverseDayMonth !== undefined ? widgetSettings.reverseDayMonth : widgetMetadata.reverseDayMonth @@ -40,16 +41,6 @@ Rectangle { implicitWidth: useCompactMode ? Math.round(Style.capsuleHeight * scaling) : Math.round(layout.implicitWidth + Style.marginM * 2 * scaling) implicitHeight: useCompactMode ? Math.round(Style.capsuleHeight * 2.5 * scaling) : Math.round(Style.capsuleHeight * scaling) - // React to bar position changes - Connections { - target: BarService - function onBarPositionChanged(newPosition) { - root.barPosition = newPosition - // Force re-evaluation of implicitWidth and implicitHeight - root.implicitWidth = Qt.binding(() => useCompactMode ? Math.round(Style.capsuleHeight * scaling) : Math.round(layout.implicitWidth + Style.marginM * 2 * scaling)) - root.implicitHeight = Qt.binding(() => useCompactMode ? Math.round(Style.capsuleHeight * 2.5 * scaling) : Math.round(Style.capsuleHeight * scaling)) - } - } radius: Math.round(Style.radiusS * scaling) color: Color.mSurfaceVariant diff --git a/Modules/Bar/Widgets/MediaMini.qml b/Modules/Bar/Widgets/MediaMini.qml index 9f97017..652a2f1 100644 --- a/Modules/Bar/Widgets/MediaMini.qml +++ b/Modules/Bar/Widgets/MediaMini.qml @@ -18,22 +18,6 @@ Item { property string section: "" property int sectionWidgetIndex: -1 property int sectionWidgetsCount: 0 - property string barPosition: "top" - - // Listen to BarService position changes - Connections { - target: BarService - function onBarPositionChanged(newPosition) { - barPosition = newPosition - // Force re-evaluation of implicit sizing - implicitWidth = Qt.binding(function () { - return (barPosition === "left" || barPosition === "right") ? Math.round(Style.baseWidgetSize * 0.8 * scaling) : (rowLayout.implicitWidth + Style.marginM * 2 * scaling) - }) - implicitHeight = Qt.binding(function () { - return (barPosition === "left" || barPosition === "right") ? calculatedVerticalHeight() : Math.round(Style.barHeight * scaling) - }) - } - } property var widgetMetadata: BarWidgetRegistry.widgetMetadata[widgetId] property var widgetSettings: { @@ -46,6 +30,9 @@ Item { return {} } + + readonly property string barPosition: Settings.data.bar.position + readonly property bool showAlbumArt: (widgetSettings.showAlbumArt !== undefined) ? widgetSettings.showAlbumArt : widgetMetadata.showAlbumArt readonly property bool showVisualizer: (widgetSettings.showVisualizer !== undefined) ? widgetSettings.showVisualizer : widgetMetadata.showVisualizer readonly property string visualizerType: (widgetSettings.visualizerType !== undefined && widgetSettings.visualizerType !== "") ? widgetSettings.visualizerType : widgetMetadata.visualizerType diff --git a/Modules/Bar/Widgets/SystemMonitor.qml b/Modules/Bar/Widgets/SystemMonitor.qml index f9d8956..a19bc59 100644 --- a/Modules/Bar/Widgets/SystemMonitor.qml +++ b/Modules/Bar/Widgets/SystemMonitor.qml @@ -16,22 +16,6 @@ Item { property string section: "" property int sectionWidgetIndex: -1 property int sectionWidgetsCount: 0 - property string barPosition: "top" - - // Listen to BarService position changes - Connections { - target: BarService - function onBarPositionChanged(newPosition) { - barPosition = newPosition - // Force re-evaluation of implicit sizing - implicitWidth = Qt.binding(function () { - return (barPosition === "left" || barPosition === "right") ? Math.round(Style.capsuleHeight * scaling) : (horizontalLayout.implicitWidth + Style.marginL * 2 * scaling) - }) - implicitHeight = Qt.binding(function () { - return (barPosition === "left" || barPosition === "right") ? calculatedVerticalHeight() : Math.round(Style.barHeight * scaling) - }) - } - } property var widgetMetadata: BarWidgetRegistry.widgetMetadata[widgetId] property var widgetSettings: { @@ -44,6 +28,8 @@ Item { return {} } + readonly property string barPosition: Settings.data.bar.position + readonly property bool showCpuUsage: (widgetSettings.showCpuUsage !== undefined) ? widgetSettings.showCpuUsage : widgetMetadata.showCpuUsage readonly property bool showCpuTemp: (widgetSettings.showCpuTemp !== undefined) ? widgetSettings.showCpuTemp : widgetMetadata.showCpuTemp readonly property bool showMemoryUsage: (widgetSettings.showMemoryUsage !== undefined) ? widgetSettings.showMemoryUsage : widgetMetadata.showMemoryUsage diff --git a/Modules/Bar/Widgets/Tray.qml b/Modules/Bar/Widgets/Tray.qml index b0f0f71..7ce5659 100644 --- a/Modules/Bar/Widgets/Tray.qml +++ b/Modules/Bar/Widgets/Tray.qml @@ -15,9 +15,9 @@ Rectangle { property ShellScreen screen property real scaling: 1.0 - property string barPosition: "top" readonly property real itemSize: 24 * scaling + readonly property string barPosition: Settings.data.bar.position function onLoaded() { // When the widget is fully initialized with its props @@ -27,17 +27,6 @@ Rectangle { } } - // React to bar position changes - Connections { - target: BarService - function onBarPositionChanged(newPosition) { - root.barPosition = newPosition - // Force re-evaluation of implicitWidth and implicitHeight - root.implicitWidth = Qt.binding(() => (barPosition === "left" || barPosition === "right") ? Math.round(Style.capsuleHeight * scaling) : (trayLayout.implicitWidth + Style.marginM * scaling * 2)) - root.implicitHeight = Qt.binding(() => (barPosition === "left" || barPosition === "right") ? Math.round(trayLayout.implicitHeight + Style.marginM * scaling * 2) : Math.round(Style.capsuleHeight * scaling)) - } - } - visible: SystemTray.items.values.length > 0 implicitWidth: (barPosition === "left" || barPosition === "right") ? Math.round(Style.capsuleHeight * scaling) : (trayLayout.implicitWidth + Style.marginM * scaling * 2) implicitHeight: (barPosition === "left" || barPosition === "right") ? Math.round(trayLayout.implicitHeight + Style.marginM * scaling * 2) : Math.round(Style.capsuleHeight * scaling) diff --git a/Modules/Bar/Widgets/Workspace.qml b/Modules/Bar/Widgets/Workspace.qml index dd50db2..561cba3 100644 --- a/Modules/Bar/Widgets/Workspace.qml +++ b/Modules/Bar/Widgets/Workspace.qml @@ -19,23 +19,7 @@ Item { property string section: "" property int sectionWidgetIndex: -1 property int sectionWidgetsCount: 0 - property string barPosition: "top" - - // Listen to BarService position changes - Connections { - target: BarService - function onBarPositionChanged(newPosition) { - barPosition = newPosition - // Force re-evaluation of implicit sizing - implicitWidth = Qt.binding(function () { - return (barPosition === "left" || barPosition === "right") ? Math.round(Style.barHeight * scaling) : calculatedHorizontalWidth() - }) - implicitHeight = Qt.binding(function () { - return (barPosition === "left" || barPosition === "right") ? calculatedVerticalHeight() : Math.round(Style.barHeight * scaling) - }) - } - } - + property var widgetMetadata: BarWidgetRegistry.widgetMetadata[widgetId] property var widgetSettings: { if (section && sectionWidgetIndex >= 0) { @@ -47,6 +31,9 @@ Item { return {} } + + readonly property string barPosition: Settings.data.bar.position + readonly property string labelMode: (widgetSettings.labelMode !== undefined) ? widgetSettings.labelMode : widgetMetadata.labelMode readonly property bool hideUnoccupied: (widgetSettings.hideUnoccupied !== undefined) ? widgetSettings.hideUnoccupied : widgetMetadata.hideUnoccupied diff --git a/Modules/SettingsPanel/Tabs/BarTab.qml b/Modules/SettingsPanel/Tabs/BarTab.qml index 17b07d9..5c1d11e 100644 --- a/Modules/SettingsPanel/Tabs/BarTab.qml +++ b/Modules/SettingsPanel/Tabs/BarTab.qml @@ -51,8 +51,8 @@ ColumnLayout { name: "Right" } } - currentKey: BarService.position - onSelected: key => BarService.setPosition(key) + currentKey: Settings.data.bar.position + onSelected: key => Settings.data.bar.position = key } } diff --git a/Services/BarService.qml b/Services/BarService.qml deleted file mode 100644 index ec89662..0000000 --- a/Services/BarService.qml +++ /dev/null @@ -1,36 +0,0 @@ -pragma Singleton - -import QtQuick -import Quickshell -import qs.Commons - -Singleton { - id: root - - // Bar position property - property string position: Settings.data.bar.position - - // Signal emitted when bar position changes - signal barPositionChanged(string newPosition) - - // Watch for changes in Settings.data.bar.position - Connections { - target: Settings - function onDataChanged() { - if (Settings.data.bar.position !== root.position) { - root.position = Settings.data.bar.position - root.barPositionChanged(root.position) - } - } - } - - // Also watch for direct changes to the position property - onPositionChanged: { - root.barPositionChanged(position) - } - - // Function to change bar position - function setPosition(newPosition) { - Settings.data.bar.position = newPosition - } -} diff --git a/Widgets/NPanel.qml b/Widgets/NPanel.qml index 98b613f..ae66038 100644 --- a/Widgets/NPanel.qml +++ b/Widgets/NPanel.qml @@ -40,6 +40,7 @@ Loader { property real opacityValue: originalOpacity property alias isClosing: hideTimer.running + readonly property string barPosition: Settings.data.bar.position signal opened signal closed diff --git a/Widgets/NTooltip.qml b/Widgets/NTooltip.qml index 176551a..eb8afd1 100644 --- a/Widgets/NTooltip.qml +++ b/Widgets/NTooltip.qml @@ -13,6 +13,8 @@ Window { property bool positionLeft: false property bool positionRight: false + readonly property string barPosition: Settings.data.bar.position + flags: Qt.ToolTip | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint color: Color.transparent visible: false @@ -53,7 +55,6 @@ Window { // If no explicit positioning is set, auto-detect based on bar position if (!positionLeft && !positionRight && !positionAbove) { - var barPosition = BarService.position if (barPosition === "left") { shouldPositionRight = true } else if (barPosition === "right") {