diff --git a/Modules/Bar/Widgets/Spacer.qml b/Modules/Bar/Widgets/Spacer.qml new file mode 100644 index 0000000..5a62372 --- /dev/null +++ b/Modules/Bar/Widgets/Spacer.qml @@ -0,0 +1,56 @@ +import QtQuick +import QtQuick.Layouts +import Quickshell +import qs.Commons +import qs.Services +import qs.Widgets + +Item { + id: root + + // Widget properties passed from Bar.qml + property var screen + property real scaling: 1.0 + + property string barSection: "" + property int sectionWidgetIndex: -1 + property int sectionWidgetsCount: 0 + + // Get user settings from Settings data - make it reactive + property var widgetSettings: { + var section = barSection.replace("Section", "").toLowerCase() + if (section && sectionWidgetIndex >= 0) { + var widgets = Settings.data.bar.widgets[section] + if (widgets && sectionWidgetIndex < widgets.length) { + return widgets[sectionWidgetIndex] + } + } + return {} + } + + // Use settings or defaults from BarWidgetRegistry + readonly property int userWidth: { + var section = barSection.replace("Section", "").toLowerCase() + if (section && sectionWidgetIndex >= 0) { + var widgets = Settings.data.bar.widgets[section] + if (widgets && sectionWidgetIndex < widgets.length) { + return widgets[sectionWidgetIndex].width || BarWidgetRegistry.widgetMetadata["Spacer"].width + } + } + return BarWidgetRegistry.widgetMetadata["Spacer"].width + } + + // Set the width based on user settings + implicitWidth: userWidth * scaling + implicitHeight: Style.barHeight * scaling + width: implicitWidth + height: implicitHeight + + // Optional: Add a subtle visual indicator in debug mode + Rectangle { + anchors.fill: parent + color: Qt.rgba(1, 0, 0, 0.1) // Very subtle red tint + visible: Settings.data.general.debugMode || false + radius: 2 * scaling + } +} diff --git a/Modules/SettingsPanel/Extras/BarWidgetSettingsDialog.qml b/Modules/SettingsPanel/Extras/BarWidgetSettingsDialog.qml index cccacbb..f9aa98d 100644 --- a/Modules/SettingsPanel/Extras/BarWidgetSettingsDialog.qml +++ b/Modules/SettingsPanel/Extras/BarWidgetSettingsDialog.qml @@ -68,6 +68,8 @@ Popup { sourceComponent: { if (settingsPopup.widgetId === "CustomButton") { return customButtonSettings + } else if (settingsPopup.widgetId === "Spacer") { + return spacerSettings } // Add more widget settings components here as needed return null @@ -157,4 +159,28 @@ Popup { } } } + + // Spacer settings component + Component { + id: spacerSettings + + ColumnLayout { + spacing: Style.marginM * scaling + + function saveSettings() { + var settings = Object.assign({}, settingsPopup.widgetData) + settings.width = parseInt(widthInput.text) || 20 + return settings + } + + NTextInput { + id: widthInput + Layout.fillWidth: true + label: "Width (pixels)" + description: "Width of the spacer in pixels." + text: settingsPopup.widgetData.width || "20" + placeholderText: "Enter width in pixels" + } + } + } } diff --git a/Services/BarWidgetRegistry.qml b/Services/BarWidgetRegistry.qml index 65897a6..39afcd3 100644 --- a/Services/BarWidgetRegistry.qml +++ b/Services/BarWidgetRegistry.qml @@ -28,6 +28,7 @@ Singleton { "PowerToggle": powerToggleComponent, "ScreenRecorderIndicator": screenRecorderIndicatorComponent, "SidePanelToggle": sidePanelToggleComponent, + "Spacer": spacerComponent, "SystemMonitor": systemMonitorComponent, "Taskbar": taskbarComponent, "Tray": trayComponent, @@ -43,6 +44,11 @@ Singleton { "leftClickExec": "", "rightClickExec": "", "middleClickExec": "" + }, + "Spacer": { + "allowUserSettings": true, + "icon": "space_bar", + "width": 20 } }) @@ -101,6 +107,9 @@ Singleton { property Component sidePanelToggleComponent: Component { SidePanelToggle {} } + property Component spacerComponent: Component { + Spacer {} + } property Component systemMonitorComponent: Component { SystemMonitor {} }