diff --git a/Modules/Bar/Bar.qml b/Modules/Bar/Bar.qml index 81d5241..f9673d0 100644 --- a/Modules/Bar/Bar.qml +++ b/Modules/Bar/Bar.qml @@ -109,7 +109,7 @@ Variants { "section": "left", "sectionWidgetIndex": index, "sectionWidgetsCount": Settings.data.bar.widgets.left.length, - "barPosition": Settings.data.bar.position + "barPosition": BarService.position } anchors.horizontalCenter: parent.horizontalCenter } @@ -134,7 +134,7 @@ Variants { "section": "center", "sectionWidgetIndex": index, "sectionWidgetsCount": Settings.data.bar.widgets.center.length, - "barPosition": Settings.data.bar.position + "barPosition": BarService.position } anchors.horizontalCenter: parent.horizontalCenter } @@ -160,7 +160,7 @@ Variants { "section": "right", "sectionWidgetIndex": index, "sectionWidgetsCount": Settings.data.bar.widgets.right.length, - "barPosition": Settings.data.bar.position + "barPosition": BarService.position } anchors.horizontalCenter: parent.horizontalCenter } @@ -182,7 +182,7 @@ Variants { anchors.left: parent.left anchors.leftMargin: Style.marginS * root.scaling anchors.verticalCenter: parent.verticalCenter - spacing: 0 + spacing: Style.marginS * root.scaling Repeater { model: Settings.data.bar.widgets.left @@ -195,7 +195,7 @@ Variants { "section": "left", "sectionWidgetIndex": index, "sectionWidgetsCount": Settings.data.bar.widgets.left.length, - "barPosition": Settings.data.bar.position + "barPosition": BarService.position } anchors.verticalCenter: parent.verticalCenter } @@ -222,7 +222,7 @@ Variants { "section": "center", "sectionWidgetIndex": index, "sectionWidgetsCount": Settings.data.bar.widgets.center.length, - "barPosition": Settings.data.bar.position + "barPosition": BarService.position } anchors.verticalCenter: parent.verticalCenter } @@ -250,7 +250,7 @@ Variants { "section": "right", "sectionWidgetIndex": index, "sectionWidgetsCount": Settings.data.bar.widgets.right.length, - "barPosition": Settings.data.bar.position + "barPosition": BarService.position } anchors.verticalCenter: parent.verticalCenter } diff --git a/Modules/Bar/Widgets/ActiveWindow.qml b/Modules/Bar/Widgets/ActiveWindow.qml index b956e14..2447fef 100644 --- a/Modules/Bar/Widgets/ActiveWindow.qml +++ b/Modules/Bar/Widgets/ActiveWindow.qml @@ -19,6 +19,21 @@ Item { 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) : 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: { @@ -82,8 +97,7 @@ Item { total += titleWidth } - // Add extra margin for spacing between widgets in the bar - total += Style.marginM * scaling * 2 // widget-to-widget spacing + // Row layout handles spacing between widgets return Math.max(total, Style.capsuleHeight * scaling) // Minimum width } diff --git a/Modules/Bar/Widgets/MediaMini.qml b/Modules/Bar/Widgets/MediaMini.qml index c3f333a..458095c 100644 --- a/Modules/Bar/Widgets/MediaMini.qml +++ b/Modules/Bar/Widgets/MediaMini.qml @@ -19,6 +19,21 @@ Item { 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) : 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: { @@ -48,13 +63,14 @@ Item { } function calculatedHorizontalWidth() { - let total = Style.marginM * 2 * scaling // padding + let total = Style.marginM * 2 * scaling // internal padding if (showAlbumArt) { - total += 18 * scaling + Style.marginS * scaling // album art + spacing + total += 18 * scaling + 2 * scaling // album art + spacing } else { - total += Style.fontSizeL * scaling + Style.marginS * scaling // icon + spacing + total += Style.fontSizeL * scaling + 2 * scaling // icon + spacing } total += Math.min(fullTitleMetrics.contentWidth, maxWidth * scaling) // title text + // Row layout handles spacing between widgets return total } @@ -74,18 +90,10 @@ Item { Rectangle { id: mediaMini visible: root.visible - - // For vertical bars, use anchors to center in parent - anchors.centerIn: (barPosition === "left" || barPosition === "right") ? parent : undefined - - // For horizontal bars, use Layout properties - Layout.preferredWidth: (barPosition === "left" || barPosition === "right") ? Math.round(Style.baseWidgetSize * 0.8 * scaling) : (rowLayout.implicitWidth + Style.marginM * 2 * scaling) - Layout.preferredHeight: (barPosition === "left" || barPosition === "right") ? Math.round(Style.baseWidgetSize * 0.8 * scaling) : Math.round(Style.capsuleHeight * scaling) - Layout.alignment: (barPosition === "left" || barPosition === "right") ? undefined : Qt.AlignVCenter - - width: (barPosition === "left" || barPosition === "right") ? Math.round(Style.baseWidgetSize * 0.8 * scaling) : undefined - height: (barPosition === "left" || barPosition === "right") ? Math.round(Style.baseWidgetSize * 0.8 * scaling) : undefined - + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + width: (barPosition === "left" || barPosition === "right") ? Math.round(Style.baseWidgetSize * 0.8 * scaling) : (rowLayout.implicitWidth + Style.marginM * 2 * scaling) + height: (barPosition === "left" || barPosition === "right") ? Math.round(Style.baseWidgetSize * 0.8 * scaling) : Math.round(Style.capsuleHeight * scaling) radius: (barPosition === "left" || barPosition === "right") ? width / 2 : Math.round(Style.radiusM * scaling) color: Color.mSurfaceVariant diff --git a/Modules/Bar/Widgets/SystemMonitor.qml b/Modules/Bar/Widgets/SystemMonitor.qml index 45a576c..41d1a06 100644 --- a/Modules/Bar/Widgets/SystemMonitor.qml +++ b/Modules/Bar/Widgets/SystemMonitor.qml @@ -17,6 +17,21 @@ Item { 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) : 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: { @@ -121,8 +136,7 @@ Item { total += (visibleCount - 1) * Style.marginXS * scaling } - // Add extra margin for spacing between widgets in the bar - total += Style.marginM * scaling * 2 // widget-to-widget spacing + // Row layout handles spacing between widgets return Math.max(total, Style.capsuleHeight * scaling) } diff --git a/Modules/Bar/Widgets/Workspace.qml b/Modules/Bar/Widgets/Workspace.qml index 34dce9b..150981c 100644 --- a/Modules/Bar/Widgets/Workspace.qml +++ b/Modules/Bar/Widgets/Workspace.qml @@ -20,6 +20,21 @@ Item { 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: { diff --git a/Modules/SettingsPanel/Tabs/BarTab.qml b/Modules/SettingsPanel/Tabs/BarTab.qml index 5c1d11e..17b07d9 100644 --- a/Modules/SettingsPanel/Tabs/BarTab.qml +++ b/Modules/SettingsPanel/Tabs/BarTab.qml @@ -51,8 +51,8 @@ ColumnLayout { name: "Right" } } - currentKey: Settings.data.bar.position - onSelected: key => Settings.data.bar.position = key + currentKey: BarService.position + onSelected: key => BarService.setPosition(key) } } diff --git a/Services/BarService.qml b/Services/BarService.qml new file mode 100644 index 0000000..ec89662 --- /dev/null +++ b/Services/BarService.qml @@ -0,0 +1,36 @@ +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 + } +}