diff --git a/shell/Ui/BarWidget.qml b/shell/Ui/BarWidget.qml index 1cf3e256..10e9c324 100644 --- a/shell/Ui/BarWidget.qml +++ b/shell/Ui/BarWidget.qml @@ -1,4 +1,5 @@ import QtQuick +import qs.Commons // Base item every bar widget extends. Codifies the three properties the // bar host injects into each widget slot: @@ -14,4 +15,19 @@ Item { property QtObject bar: null property string moduleName: "" property var settings: ({}) + + // Bar geometry, lifted off the host. Widgets read these constantly to pick + // between horizontal/vertical layouts; defining them on the base keeps the + // `bar ? bar.x : fallback` ternary out of every widget body. + readonly property bool vertical: bar ? bar.vertical : false + readonly property int barSize: bar ? bar.barSize : Style.bar.sizeHorizontal + + // Read a single value from this widget's inline shell.json entry, with a + // fallback for missing/null values. Every widget that takes user-tunable + // settings needs this; defining it once on the base keeps the wiring + // consistent. + function setting(name, fallback) { + var value = settings ? settings[name] : undefined + return value === undefined || value === null ? fallback : value + } } diff --git a/shell/plugins/bar/widgets/activeWindow.qml b/shell/plugins/bar/widgets/activeWindow.qml index 8f9d0137..49ef4f72 100644 --- a/shell/plugins/bar/widgets/activeWindow.qml +++ b/shell/plugins/bar/widgets/activeWindow.qml @@ -9,20 +9,13 @@ BarWidget { moduleName: "activeWindow" - function setting(name, fallback) { - var value = settings ? settings[name] : undefined - return value === undefined || value === null ? fallback : value - } - readonly property var toplevel: ToplevelManager.activeToplevel readonly property string title: toplevel ? (toplevel.title || toplevel.appId || "") : "" readonly property int maxLabelWidth: Number(setting("maxWidth", 280)) - readonly property bool vertical: bar ? bar.vertical : false - visible: title !== "" && !vertical implicitWidth: visible ? Math.min(maxLabelWidth, labelText.implicitWidth) + Style.spacing.controlPaddingX * 2 : 0 - implicitHeight: bar ? bar.barSize : 26 + implicitHeight: barSize Behavior on implicitWidth { NumberAnimation { duration: 180; easing.type: Easing.OutCubic } diff --git a/shell/plugins/bar/widgets/clock.qml b/shell/plugins/bar/widgets/clock.qml index 2820bb3f..eee8ef46 100644 --- a/shell/plugins/bar/widgets/clock.qml +++ b/shell/plugins/bar/widgets/clock.qml @@ -9,11 +9,6 @@ BarWidget { property bool alt: false - function setting(name, fallback) { - var value = settings ? settings[name] : undefined - return value === undefined || value === null ? fallback : value - } - function label() { if (alt) return Qt.formatDateTime(clock.date, String(setting("formatAlt", "dd MMMM 'W'ww yyyy"))) if (bar && bar.vertical) return Qt.formatDateTime(clock.date, String(setting("verticalFormat", "HH\n—\nmm"))) diff --git a/shell/plugins/bar/widgets/daytime.qml b/shell/plugins/bar/widgets/daytime.qml index e85b0ff3..ec368e8c 100644 --- a/shell/plugins/bar/widgets/daytime.qml +++ b/shell/plugins/bar/widgets/daytime.qml @@ -9,11 +9,6 @@ BarWidget { property date now: new Date() - function setting(name, fallback) { - var value = settings ? settings[name] : undefined - return value === undefined || value === null ? fallback : value - } - function formatLabel() { if (!bar) return "" var fmt = bar.vertical diff --git a/shell/plugins/bar/widgets/indicators.qml b/shell/plugins/bar/widgets/indicators.qml index e44be26d..afd4825e 100644 --- a/shell/plugins/bar/widgets/indicators.qml +++ b/shell/plugins/bar/widgets/indicators.qml @@ -8,8 +8,6 @@ BarWidget { id: root moduleName: "indicators" - readonly property bool vertical: bar ? bar.vertical : false - readonly property int barSize: bar ? bar.barSize : Style.bar.sizeHorizontal readonly property int indicatorSlotExtent: Style.space(22) readonly property int inactiveSlotExtent: indicatorEntries.length * indicatorSlotExtent readonly property var indicatorEntries: indicatorEntriesFromSettings(settings) diff --git a/shell/plugins/bar/widgets/keyboardLayout.qml b/shell/plugins/bar/widgets/keyboardLayout.qml index f2ff8a56..b8220e5d 100644 --- a/shell/plugins/bar/widgets/keyboardLayout.qml +++ b/shell/plugins/bar/widgets/keyboardLayout.qml @@ -13,11 +13,6 @@ BarWidget { property string layoutLabel: "" property string layoutFull: "" - function setting(name, fallback) { - var value = settings ? settings[name] : undefined - return value === undefined || value === null ? fallback : value - } - function refresh() { if (!queryProc.running) queryProc.running = true } diff --git a/shell/plugins/bar/widgets/lockKeys.qml b/shell/plugins/bar/widgets/lockKeys.qml index 3704ff4d..272bb594 100644 --- a/shell/plugins/bar/widgets/lockKeys.qml +++ b/shell/plugins/bar/widgets/lockKeys.qml @@ -14,11 +14,6 @@ BarWidget { property bool scrollOn: false property bool hideWhenOff: true - function setting(name, fallback) { - var value = settings ? settings[name] : undefined - return value === undefined || value === null ? fallback : value - } - Component.onCompleted: { hideWhenOff = setting("hideWhenOff", true) === true refresh() @@ -58,10 +53,8 @@ BarWidget { readonly property bool anyOn: capsOn || numOn || scrollOn visible: ledsAvailable && (hideWhenOff ? anyOn : true) - readonly property bool vertical: bar ? bar.vertical : false - - implicitWidth: vertical ? (bar ? bar.barSize : Style.bar.sizeVertical) : (lay.item ? lay.item.implicitWidth + Style.spacing.controlGap : 0) - implicitHeight: vertical ? (lay.item ? lay.item.implicitHeight + Style.spacing.controlGap : 0) : (bar ? bar.barSize : Style.bar.sizeHorizontal) + implicitWidth: vertical ? barSize : (lay.item ? lay.item.implicitWidth + Style.spacing.controlGap : 0) + implicitHeight: vertical ? (lay.item ? lay.item.implicitHeight + Style.spacing.controlGap : 0) : barSize Loader { id: lay diff --git a/shell/plugins/bar/widgets/media.qml b/shell/plugins/bar/widgets/media.qml index 3a79c26a..c9957162 100644 --- a/shell/plugins/bar/widgets/media.qml +++ b/shell/plugins/bar/widgets/media.qml @@ -9,11 +9,6 @@ BarWidget { moduleName: "media" - function setting(name, fallback) { - var value = settings ? settings[name] : undefined - return value === undefined || value === null ? fallback : value - } - readonly property var players: Mpris.players ? Mpris.players.values : [] readonly property var activePlayer: { var playing = null @@ -38,7 +33,7 @@ BarWidget { visible: hasMedia implicitWidth: hasMedia ? row.implicitWidth + Style.space(14) : 0 - implicitHeight: bar ? bar.barSize : 26 + implicitHeight: barSize Row { id: row diff --git a/shell/plugins/bar/widgets/spacer.qml b/shell/plugins/bar/widgets/spacer.qml index 744a1856..5cb38c6a 100644 --- a/shell/plugins/bar/widgets/spacer.qml +++ b/shell/plugins/bar/widgets/spacer.qml @@ -5,11 +5,9 @@ BarWidget { id: root moduleName: "spacer" - - readonly property bool vertical: bar ? bar.vertical : false readonly property int span: settings && settings.size !== undefined ? Number(settings.size) : 12 - implicitWidth: vertical ? (bar ? bar.barSize : 28) : span - implicitHeight: vertical ? span : (bar ? bar.barSize : 26) + implicitWidth: vertical ? barSize : span + implicitHeight: vertical ? span : barSize visible: span > 0 } diff --git a/shell/plugins/bar/widgets/systemStats.qml b/shell/plugins/bar/widgets/systemStats.qml index 520f07f4..31e020cc 100644 --- a/shell/plugins/bar/widgets/systemStats.qml +++ b/shell/plugins/bar/widgets/systemStats.qml @@ -116,8 +116,7 @@ BarWidget { onTriggered: root.refresh() } - readonly property bool vertical: bar ? bar.vertical : false - readonly property color statColor: bar ? bar.foreground : "#cacccc" + readonly property color statColor: bar ? bar.foreground : Color.foreground implicitWidth: button.implicitWidth implicitHeight: button.implicitHeight diff --git a/shell/plugins/bar/widgets/tray.qml b/shell/plugins/bar/widgets/tray.qml index d53f2ba6..b88287db 100644 --- a/shell/plugins/bar/widgets/tray.qml +++ b/shell/plugins/bar/widgets/tray.qml @@ -10,8 +10,6 @@ BarWidget { property bool expanded: false property bool managePopupOpen: false - readonly property bool vertical: bar ? bar.vertical : false - readonly property int barSize: bar ? bar.barSize : Style.bar.sizeHorizontal readonly property color foreground: bar ? bar.foreground : Color.foreground readonly property string fontFamily: bar ? bar.fontFamily : Style.font.family readonly property var pinnedIds: Array.isArray(settings.pinned) ? settings.pinned : [] diff --git a/shell/plugins/bar/widgets/workspaces.qml b/shell/plugins/bar/widgets/workspaces.qml index b0d7e304..b26e5e56 100644 --- a/shell/plugins/bar/widgets/workspaces.qml +++ b/shell/plugins/bar/widgets/workspaces.qml @@ -8,9 +8,6 @@ BarWidget { id: root moduleName: "workspaces" - readonly property bool vertical: bar ? bar.vertical : false - readonly property int barSize: bar ? bar.barSize : Style.bar.sizeHorizontal - function workspaceById(id) { var values = Hyprland.workspaces.values for (var i = 0; i < values.length; i++) {