Lift setting / vertical / barSize onto BarWidget
Six widgets (clock, daytime, keyboardLayout, lockKeys, activeWindow, media) shipped identical copies of `function setting(name, fallback)`. Eight widgets reimplemented `readonly property bool vertical`, and three reimplemented `readonly property int barSize`. Move all three onto the BarWidget base so widgets read the same wiring everyone else gets for free. While in here, drop the dead `setting()` declaration on media.qml — it was defined but never called.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
|
import qs.Commons
|
||||||
|
|
||||||
// Base item every bar widget extends. Codifies the three properties the
|
// Base item every bar widget extends. Codifies the three properties the
|
||||||
// bar host injects into each widget slot:
|
// bar host injects into each widget slot:
|
||||||
@@ -14,4 +15,19 @@ Item {
|
|||||||
property QtObject bar: null
|
property QtObject bar: null
|
||||||
property string moduleName: ""
|
property string moduleName: ""
|
||||||
property var settings: ({})
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,20 +9,13 @@ BarWidget {
|
|||||||
moduleName: "activeWindow"
|
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 var toplevel: ToplevelManager.activeToplevel
|
||||||
readonly property string title: toplevel ? (toplevel.title || toplevel.appId || "") : ""
|
readonly property string title: toplevel ? (toplevel.title || toplevel.appId || "") : ""
|
||||||
readonly property int maxLabelWidth: Number(setting("maxWidth", 280))
|
readonly property int maxLabelWidth: Number(setting("maxWidth", 280))
|
||||||
|
|
||||||
readonly property bool vertical: bar ? bar.vertical : false
|
|
||||||
|
|
||||||
visible: title !== "" && !vertical
|
visible: title !== "" && !vertical
|
||||||
implicitWidth: visible ? Math.min(maxLabelWidth, labelText.implicitWidth) + Style.spacing.controlPaddingX * 2 : 0
|
implicitWidth: visible ? Math.min(maxLabelWidth, labelText.implicitWidth) + Style.spacing.controlPaddingX * 2 : 0
|
||||||
implicitHeight: bar ? bar.barSize : 26
|
implicitHeight: barSize
|
||||||
|
|
||||||
Behavior on implicitWidth {
|
Behavior on implicitWidth {
|
||||||
NumberAnimation { duration: 180; easing.type: Easing.OutCubic }
|
NumberAnimation { duration: 180; easing.type: Easing.OutCubic }
|
||||||
|
|||||||
@@ -9,11 +9,6 @@ BarWidget {
|
|||||||
|
|
||||||
property bool alt: false
|
property bool alt: false
|
||||||
|
|
||||||
function setting(name, fallback) {
|
|
||||||
var value = settings ? settings[name] : undefined
|
|
||||||
return value === undefined || value === null ? fallback : value
|
|
||||||
}
|
|
||||||
|
|
||||||
function label() {
|
function label() {
|
||||||
if (alt) return Qt.formatDateTime(clock.date, String(setting("formatAlt", "dd MMMM 'W'ww yyyy")))
|
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")))
|
if (bar && bar.vertical) return Qt.formatDateTime(clock.date, String(setting("verticalFormat", "HH\n—\nmm")))
|
||||||
|
|||||||
@@ -9,11 +9,6 @@ BarWidget {
|
|||||||
|
|
||||||
property date now: new Date()
|
property date now: new Date()
|
||||||
|
|
||||||
function setting(name, fallback) {
|
|
||||||
var value = settings ? settings[name] : undefined
|
|
||||||
return value === undefined || value === null ? fallback : value
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatLabel() {
|
function formatLabel() {
|
||||||
if (!bar) return ""
|
if (!bar) return ""
|
||||||
var fmt = bar.vertical
|
var fmt = bar.vertical
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ BarWidget {
|
|||||||
id: root
|
id: root
|
||||||
moduleName: "indicators"
|
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 indicatorSlotExtent: Style.space(22)
|
||||||
readonly property int inactiveSlotExtent: indicatorEntries.length * indicatorSlotExtent
|
readonly property int inactiveSlotExtent: indicatorEntries.length * indicatorSlotExtent
|
||||||
readonly property var indicatorEntries: indicatorEntriesFromSettings(settings)
|
readonly property var indicatorEntries: indicatorEntriesFromSettings(settings)
|
||||||
|
|||||||
@@ -13,11 +13,6 @@ BarWidget {
|
|||||||
property string layoutLabel: ""
|
property string layoutLabel: ""
|
||||||
property string layoutFull: ""
|
property string layoutFull: ""
|
||||||
|
|
||||||
function setting(name, fallback) {
|
|
||||||
var value = settings ? settings[name] : undefined
|
|
||||||
return value === undefined || value === null ? fallback : value
|
|
||||||
}
|
|
||||||
|
|
||||||
function refresh() {
|
function refresh() {
|
||||||
if (!queryProc.running) queryProc.running = true
|
if (!queryProc.running) queryProc.running = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,6 @@ BarWidget {
|
|||||||
property bool scrollOn: false
|
property bool scrollOn: false
|
||||||
property bool hideWhenOff: true
|
property bool hideWhenOff: true
|
||||||
|
|
||||||
function setting(name, fallback) {
|
|
||||||
var value = settings ? settings[name] : undefined
|
|
||||||
return value === undefined || value === null ? fallback : value
|
|
||||||
}
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
hideWhenOff = setting("hideWhenOff", true) === true
|
hideWhenOff = setting("hideWhenOff", true) === true
|
||||||
refresh()
|
refresh()
|
||||||
@@ -58,10 +53,8 @@ BarWidget {
|
|||||||
readonly property bool anyOn: capsOn || numOn || scrollOn
|
readonly property bool anyOn: capsOn || numOn || scrollOn
|
||||||
visible: ledsAvailable && (hideWhenOff ? anyOn : true)
|
visible: ledsAvailable && (hideWhenOff ? anyOn : true)
|
||||||
|
|
||||||
readonly property bool vertical: bar ? bar.vertical : false
|
implicitWidth: vertical ? barSize : (lay.item ? lay.item.implicitWidth + Style.spacing.controlGap : 0)
|
||||||
|
implicitHeight: vertical ? (lay.item ? lay.item.implicitHeight + Style.spacing.controlGap : 0) : barSize
|
||||||
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)
|
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
id: lay
|
id: lay
|
||||||
|
|||||||
@@ -9,11 +9,6 @@ BarWidget {
|
|||||||
moduleName: "media"
|
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 players: Mpris.players ? Mpris.players.values : []
|
||||||
readonly property var activePlayer: {
|
readonly property var activePlayer: {
|
||||||
var playing = null
|
var playing = null
|
||||||
@@ -38,7 +33,7 @@ BarWidget {
|
|||||||
|
|
||||||
visible: hasMedia
|
visible: hasMedia
|
||||||
implicitWidth: hasMedia ? row.implicitWidth + Style.space(14) : 0
|
implicitWidth: hasMedia ? row.implicitWidth + Style.space(14) : 0
|
||||||
implicitHeight: bar ? bar.barSize : 26
|
implicitHeight: barSize
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
id: row
|
id: row
|
||||||
|
|||||||
@@ -5,11 +5,9 @@ BarWidget {
|
|||||||
id: root
|
id: root
|
||||||
moduleName: "spacer"
|
moduleName: "spacer"
|
||||||
|
|
||||||
|
|
||||||
readonly property bool vertical: bar ? bar.vertical : false
|
|
||||||
readonly property int span: settings && settings.size !== undefined ? Number(settings.size) : 12
|
readonly property int span: settings && settings.size !== undefined ? Number(settings.size) : 12
|
||||||
|
|
||||||
implicitWidth: vertical ? (bar ? bar.barSize : 28) : span
|
implicitWidth: vertical ? barSize : span
|
||||||
implicitHeight: vertical ? span : (bar ? bar.barSize : 26)
|
implicitHeight: vertical ? span : barSize
|
||||||
visible: span > 0
|
visible: span > 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,8 +116,7 @@ BarWidget {
|
|||||||
onTriggered: root.refresh()
|
onTriggered: root.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly property bool vertical: bar ? bar.vertical : false
|
readonly property color statColor: bar ? bar.foreground : Color.foreground
|
||||||
readonly property color statColor: bar ? bar.foreground : "#cacccc"
|
|
||||||
|
|
||||||
implicitWidth: button.implicitWidth
|
implicitWidth: button.implicitWidth
|
||||||
implicitHeight: button.implicitHeight
|
implicitHeight: button.implicitHeight
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ BarWidget {
|
|||||||
|
|
||||||
property bool expanded: false
|
property bool expanded: false
|
||||||
property bool managePopupOpen: 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 color foreground: bar ? bar.foreground : Color.foreground
|
||||||
readonly property string fontFamily: bar ? bar.fontFamily : Style.font.family
|
readonly property string fontFamily: bar ? bar.fontFamily : Style.font.family
|
||||||
readonly property var pinnedIds: Array.isArray(settings.pinned) ? settings.pinned : []
|
readonly property var pinnedIds: Array.isArray(settings.pinned) ? settings.pinned : []
|
||||||
|
|||||||
@@ -8,9 +8,6 @@ BarWidget {
|
|||||||
id: root
|
id: root
|
||||||
moduleName: "workspaces"
|
moduleName: "workspaces"
|
||||||
|
|
||||||
readonly property bool vertical: bar ? bar.vertical : false
|
|
||||||
readonly property int barSize: bar ? bar.barSize : Style.bar.sizeHorizontal
|
|
||||||
|
|
||||||
function workspaceById(id) {
|
function workspaceById(id) {
|
||||||
var values = Hyprland.workspaces.values
|
var values = Hyprland.workspaces.values
|
||||||
for (var i = 0; i < values.length; i++) {
|
for (var i = 0; i < values.length; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user