diff --git a/quickshell/Common/SettingsData.qml b/quickshell/Common/SettingsData.qml index ee80be90..c4153be1 100644 --- a/quickshell/Common/SettingsData.qml +++ b/quickshell/Common/SettingsData.qml @@ -14,7 +14,7 @@ import "settings/SettingsStore.js" as Store Singleton { id: root - readonly property int settingsConfigVersion: 2 + readonly property int settingsConfigVersion: 3 readonly property bool isGreeterMode: Quickshell.env("DMS_RUN_GREETER") === "1" || Quickshell.env("DMS_RUN_GREETER") === "true" diff --git a/quickshell/Common/settings/Lists.qml b/quickshell/Common/settings/Lists.qml index cdc785fb..4ec977b3 100644 --- a/quickshell/Common/settings/Lists.qml +++ b/quickshell/Common/settings/Lists.qml @@ -1,5 +1,4 @@ pragma Singleton - pragma ComponentBehavior: Bound import Quickshell @@ -17,40 +16,67 @@ Singleton { pciId: "", mountPath: "/", minimumWidth: true, - showSwap: false - } - leftModel.append(dummy) - centerModel.append(dummy) - rightModel.append(dummy) + showSwap: false, + mediaSize: 1, + showNetworkIcon: true, + showBluetoothIcon: true, + showAudioIcon: true, + showVpnIcon: true, + showBrightnessIcon: false, + showMicIcon: false, + showBatteryIcon: false, + showPrinterIcon: false + }; + leftModel.append(dummy); + centerModel.append(dummy); + rightModel.append(dummy); - update(leftModel, left) - update(centerModel, center) - update(rightModel, right) + update(leftModel, left); + update(centerModel, center); + update(rightModel, right); } function update(model, order) { - model.clear() + model.clear(); for (var i = 0; i < order.length; i++) { - var widgetId = typeof order[i] === "string" ? order[i] : order[i].id - var enabled = typeof order[i] === "string" ? true : order[i].enabled - var size = typeof order[i] === "string" ? undefined : order[i].size - var selectedGpuIndex = typeof order[i] === "string" ? undefined : order[i].selectedGpuIndex - var pciId = typeof order[i] === "string" ? undefined : order[i].pciId - var mountPath = typeof order[i] === "string" ? undefined : order[i].mountPath - var minimumWidth = typeof order[i] === "string" ? undefined : order[i].minimumWidth - var showSwap = typeof order[i] === "string" ? undefined : order[i].showSwap + var isObj = typeof order[i] !== "string"; + var widgetId = isObj ? order[i].id : order[i]; var item = { widgetId: widgetId, - enabled: enabled - } - if (size !== undefined) item.size = size - if (selectedGpuIndex !== undefined) item.selectedGpuIndex = selectedGpuIndex - if (pciId !== undefined) item.pciId = pciId - if (mountPath !== undefined) item.mountPath = mountPath - if (minimumWidth !== undefined) item.minimumWidth = minimumWidth - if (showSwap !== undefined) item.showSwap = showSwap + enabled: isObj ? order[i].enabled : true + }; + if (isObj && order[i].size !== undefined) + item.size = order[i].size; + if (isObj && order[i].selectedGpuIndex !== undefined) + item.selectedGpuIndex = order[i].selectedGpuIndex; + if (isObj && order[i].pciId !== undefined) + item.pciId = order[i].pciId; + if (isObj && order[i].mountPath !== undefined) + item.mountPath = order[i].mountPath; + if (isObj && order[i].minimumWidth !== undefined) + item.minimumWidth = order[i].minimumWidth; + if (isObj && order[i].showSwap !== undefined) + item.showSwap = order[i].showSwap; + if (isObj && order[i].mediaSize !== undefined) + item.mediaSize = order[i].mediaSize; + if (isObj && order[i].showNetworkIcon !== undefined) + item.showNetworkIcon = order[i].showNetworkIcon; + if (isObj && order[i].showBluetoothIcon !== undefined) + item.showBluetoothIcon = order[i].showBluetoothIcon; + if (isObj && order[i].showAudioIcon !== undefined) + item.showAudioIcon = order[i].showAudioIcon; + if (isObj && order[i].showVpnIcon !== undefined) + item.showVpnIcon = order[i].showVpnIcon; + if (isObj && order[i].showBrightnessIcon !== undefined) + item.showBrightnessIcon = order[i].showBrightnessIcon; + if (isObj && order[i].showMicIcon !== undefined) + item.showMicIcon = order[i].showMicIcon; + if (isObj && order[i].showBatteryIcon !== undefined) + item.showBatteryIcon = order[i].showBatteryIcon; + if (isObj && order[i].showPrinterIcon !== undefined) + item.showPrinterIcon = order[i].showPrinterIcon; - model.append(item) + model.append(item); } } } diff --git a/quickshell/Common/settings/SettingsStore.js b/quickshell/Common/settings/SettingsStore.js index 5c68f83b..777f4956 100644 --- a/quickshell/Common/settings/SettingsStore.js +++ b/quickshell/Common/settings/SettingsStore.js @@ -113,6 +113,12 @@ function migrateToVersion(obj, targetVersion) { settings.configVersion = 2; } + if (currentVersion < 3) { + console.info("Migrating settings from version", currentVersion, "to version 3"); + console.info("Per-widget controlCenterButton config now supported via widgetData properties"); + settings.configVersion = 3; + } + return settings; } diff --git a/quickshell/Modules/DankBar/Widgets/ControlCenterButton.qml b/quickshell/Modules/DankBar/Widgets/ControlCenterButton.qml index 97f18076..d79b1f3c 100644 --- a/quickshell/Modules/DankBar/Widgets/ControlCenterButton.qml +++ b/quickshell/Modules/DankBar/Widgets/ControlCenterButton.qml @@ -13,14 +13,14 @@ BasePill { property var widgetData: null property string screenName: "" property string screenModel: "" - property bool showNetworkIcon: SettingsData.controlCenterShowNetworkIcon - property bool showBluetoothIcon: SettingsData.controlCenterShowBluetoothIcon - property bool showAudioIcon: SettingsData.controlCenterShowAudioIcon - property bool showVpnIcon: SettingsData.controlCenterShowVpnIcon - property bool showBrightnessIcon: SettingsData.controlCenterShowBrightnessIcon - property bool showMicIcon: SettingsData.controlCenterShowMicIcon - property bool showBatteryIcon: SettingsData.controlCenterShowBatteryIcon - property bool showPrinterIcon: SettingsData.controlCenterShowPrinterIcon + property bool showNetworkIcon: widgetData?.showNetworkIcon !== undefined ? widgetData.showNetworkIcon : SettingsData.controlCenterShowNetworkIcon + property bool showBluetoothIcon: widgetData?.showBluetoothIcon !== undefined ? widgetData.showBluetoothIcon : SettingsData.controlCenterShowBluetoothIcon + property bool showAudioIcon: widgetData?.showAudioIcon !== undefined ? widgetData.showAudioIcon : SettingsData.controlCenterShowAudioIcon + property bool showVpnIcon: widgetData?.showVpnIcon !== undefined ? widgetData.showVpnIcon : SettingsData.controlCenterShowVpnIcon + property bool showBrightnessIcon: widgetData?.showBrightnessIcon !== undefined ? widgetData.showBrightnessIcon : SettingsData.controlCenterShowBrightnessIcon + property bool showMicIcon: widgetData?.showMicIcon !== undefined ? widgetData.showMicIcon : SettingsData.controlCenterShowMicIcon + property bool showBatteryIcon: widgetData?.showBatteryIcon !== undefined ? widgetData.showBatteryIcon : SettingsData.controlCenterShowBatteryIcon + property bool showPrinterIcon: widgetData?.showPrinterIcon !== undefined ? widgetData.showPrinterIcon : SettingsData.controlCenterShowPrinterIcon Loader { active: root.showPrinterIcon diff --git a/quickshell/Modules/Settings/WidgetsTab.qml b/quickshell/Modules/Settings/WidgetsTab.qml index cc2a6e97..406321cf 100644 --- a/quickshell/Modules/Settings/WidgetsTab.qml +++ b/quickshell/Modules/Settings/WidgetsTab.qml @@ -371,9 +371,14 @@ Item { widgetObj.pciId = ""; } if (widgetId === "controlCenterButton") { - widgetObj.showNetworkIcon = true; - widgetObj.showBluetoothIcon = true; - widgetObj.showAudioIcon = true; + widgetObj.showNetworkIcon = SettingsData.controlCenterShowNetworkIcon; + widgetObj.showBluetoothIcon = SettingsData.controlCenterShowBluetoothIcon; + widgetObj.showAudioIcon = SettingsData.controlCenterShowAudioIcon; + widgetObj.showVpnIcon = SettingsData.controlCenterShowVpnIcon; + widgetObj.showBrightnessIcon = SettingsData.controlCenterShowBrightnessIcon; + widgetObj.showMicIcon = SettingsData.controlCenterShowMicIcon; + widgetObj.showBatteryIcon = SettingsData.controlCenterShowBatteryIcon; + widgetObj.showPrinterIcon = SettingsData.controlCenterShowPrinterIcon; } if (widgetId === "diskUsage") widgetObj.mountPath = "/"; @@ -423,9 +428,14 @@ Item { else if (widget.id === "gpuTemp") newWidget.pciId = ""; if (widget.id === "controlCenterButton") { - newWidget.showNetworkIcon = widget.showNetworkIcon ?? true; - newWidget.showBluetoothIcon = widget.showBluetoothIcon ?? true; - newWidget.showAudioIcon = widget.showAudioIcon ?? true; + newWidget.showNetworkIcon = widget.showNetworkIcon ?? SettingsData.controlCenterShowNetworkIcon; + newWidget.showBluetoothIcon = widget.showBluetoothIcon ?? SettingsData.controlCenterShowBluetoothIcon; + newWidget.showAudioIcon = widget.showAudioIcon ?? SettingsData.controlCenterShowAudioIcon; + newWidget.showVpnIcon = widget.showVpnIcon ?? SettingsData.controlCenterShowVpnIcon; + newWidget.showBrightnessIcon = widget.showBrightnessIcon ?? SettingsData.controlCenterShowBrightnessIcon; + newWidget.showMicIcon = widget.showMicIcon ?? SettingsData.controlCenterShowMicIcon; + newWidget.showBatteryIcon = widget.showBatteryIcon ?? SettingsData.controlCenterShowBatteryIcon; + newWidget.showPrinterIcon = widget.showPrinterIcon ?? SettingsData.controlCenterShowPrinterIcon; } widgets[i] = newWidget; break; @@ -471,9 +481,14 @@ Item { if (widget.pciId !== undefined) newWidget.pciId = widget.pciId; if (widget.id === "controlCenterButton") { - newWidget.showNetworkIcon = widget.showNetworkIcon ?? true; - newWidget.showBluetoothIcon = widget.showBluetoothIcon ?? true; - newWidget.showAudioIcon = widget.showAudioIcon ?? true; + newWidget.showNetworkIcon = widget.showNetworkIcon ?? SettingsData.controlCenterShowNetworkIcon; + newWidget.showBluetoothIcon = widget.showBluetoothIcon ?? SettingsData.controlCenterShowBluetoothIcon; + newWidget.showAudioIcon = widget.showAudioIcon ?? SettingsData.controlCenterShowAudioIcon; + newWidget.showVpnIcon = widget.showVpnIcon ?? SettingsData.controlCenterShowVpnIcon; + newWidget.showBrightnessIcon = widget.showBrightnessIcon ?? SettingsData.controlCenterShowBrightnessIcon; + newWidget.showMicIcon = widget.showMicIcon ?? SettingsData.controlCenterShowMicIcon; + newWidget.showBatteryIcon = widget.showBatteryIcon ?? SettingsData.controlCenterShowBatteryIcon; + newWidget.showPrinterIcon = widget.showPrinterIcon ?? SettingsData.controlCenterShowPrinterIcon; } widgets[widgetIndex] = newWidget; setWidgetsForSection(sectionId, widgets); @@ -541,41 +556,48 @@ Item { if (widget.pciId !== undefined) newWidget.pciId = widget.pciId; if (widget.id === "controlCenterButton") { - newWidget.showNetworkIcon = widget.showNetworkIcon ?? true; - newWidget.showBluetoothIcon = widget.showBluetoothIcon ?? true; - newWidget.showAudioIcon = widget.showAudioIcon ?? true; + newWidget.showNetworkIcon = widget.showNetworkIcon ?? SettingsData.controlCenterShowNetworkIcon; + newWidget.showBluetoothIcon = widget.showBluetoothIcon ?? SettingsData.controlCenterShowBluetoothIcon; + newWidget.showAudioIcon = widget.showAudioIcon ?? SettingsData.controlCenterShowAudioIcon; + newWidget.showVpnIcon = widget.showVpnIcon ?? SettingsData.controlCenterShowVpnIcon; + newWidget.showBrightnessIcon = widget.showBrightnessIcon ?? SettingsData.controlCenterShowBrightnessIcon; + newWidget.showMicIcon = widget.showMicIcon ?? SettingsData.controlCenterShowMicIcon; + newWidget.showBatteryIcon = widget.showBatteryIcon ?? SettingsData.controlCenterShowBatteryIcon; + newWidget.showPrinterIcon = widget.showPrinterIcon ?? SettingsData.controlCenterShowPrinterIcon; } widgets[widgetIndex] = newWidget; setWidgetsForSection(sectionId, widgets); } function handleControlCenterSettingChanged(sectionId, widgetIndex, settingName, value) { - switch (settingName) { - case "showNetworkIcon": - SettingsData.set("controlCenterShowNetworkIcon", value); - break; - case "showBluetoothIcon": - SettingsData.set("controlCenterShowBluetoothIcon", value); - break; - case "showAudioIcon": - SettingsData.set("controlCenterShowAudioIcon", value); - break; - case "showVpnIcon": - SettingsData.set("controlCenterShowVpnIcon", value); - break; - case "showBrightnessIcon": - SettingsData.set("controlCenterShowBrightnessIcon", value); - break; - case "showMicIcon": - SettingsData.set("controlCenterShowMicIcon", value); - break; - case "showBatteryIcon": - SettingsData.set("controlCenterShowBatteryIcon", value); - break; - case "showPrinterIcon": - SettingsData.set("controlCenterShowPrinterIcon", value); - break; + var widgets = getWidgetsForSection(sectionId).slice(); + if (widgetIndex < 0 || widgetIndex >= widgets.length) + return; + + var widget = widgets[widgetIndex]; + if (typeof widget === "string") { + widget = { + "id": widget, + "enabled": true + }; } + + var newWidget = { + "id": widget.id, + "enabled": widget.enabled !== undefined ? widget.enabled : true, + "showNetworkIcon": widget.showNetworkIcon ?? SettingsData.controlCenterShowNetworkIcon, + "showBluetoothIcon": widget.showBluetoothIcon ?? SettingsData.controlCenterShowBluetoothIcon, + "showAudioIcon": widget.showAudioIcon ?? SettingsData.controlCenterShowAudioIcon, + "showVpnIcon": widget.showVpnIcon ?? SettingsData.controlCenterShowVpnIcon, + "showBrightnessIcon": widget.showBrightnessIcon ?? SettingsData.controlCenterShowBrightnessIcon, + "showMicIcon": widget.showMicIcon ?? SettingsData.controlCenterShowMicIcon, + "showBatteryIcon": widget.showBatteryIcon ?? SettingsData.controlCenterShowBatteryIcon, + "showPrinterIcon": widget.showPrinterIcon ?? SettingsData.controlCenterShowPrinterIcon + }; + newWidget[settingName] = value; + + widgets[widgetIndex] = newWidget; + setWidgetsForSection(sectionId, widgets); } function handlePrivacySettingChanged(sectionId, widgetIndex, settingName, value) { @@ -626,9 +648,14 @@ Item { if (widget.showSwap !== undefined) newWidget.showSwap = widget.showSwap; if (widget.id === "controlCenterButton") { - newWidget.showNetworkIcon = widget.showNetworkIcon ?? true; - newWidget.showBluetoothIcon = widget.showBluetoothIcon ?? true; - newWidget.showAudioIcon = widget.showAudioIcon ?? true; + newWidget.showNetworkIcon = widget.showNetworkIcon ?? SettingsData.controlCenterShowNetworkIcon; + newWidget.showBluetoothIcon = widget.showBluetoothIcon ?? SettingsData.controlCenterShowBluetoothIcon; + newWidget.showAudioIcon = widget.showAudioIcon ?? SettingsData.controlCenterShowAudioIcon; + newWidget.showVpnIcon = widget.showVpnIcon ?? SettingsData.controlCenterShowVpnIcon; + newWidget.showBrightnessIcon = widget.showBrightnessIcon ?? SettingsData.controlCenterShowBrightnessIcon; + newWidget.showMicIcon = widget.showMicIcon ?? SettingsData.controlCenterShowMicIcon; + newWidget.showBatteryIcon = widget.showBatteryIcon ?? SettingsData.controlCenterShowBatteryIcon; + newWidget.showPrinterIcon = widget.showPrinterIcon ?? SettingsData.controlCenterShowPrinterIcon; } widgets[widgetIndex] = newWidget; setWidgetsForSection(sectionId, widgets); @@ -678,9 +705,14 @@ Item { if (widget.keyboardLayoutNameCompactMode !== undefined) newWidget.keyboardLayoutNameCompactMode = widget.keyboardLayoutNameCompactMode; if (widget.id === "controlCenterButton") { - newWidget.showNetworkIcon = widget.showNetworkIcon ?? true; - newWidget.showBluetoothIcon = widget.showBluetoothIcon ?? true; - newWidget.showAudioIcon = widget.showAudioIcon ?? true; + newWidget.showNetworkIcon = widget.showNetworkIcon ?? SettingsData.controlCenterShowNetworkIcon; + newWidget.showBluetoothIcon = widget.showBluetoothIcon ?? SettingsData.controlCenterShowBluetoothIcon; + newWidget.showAudioIcon = widget.showAudioIcon ?? SettingsData.controlCenterShowAudioIcon; + newWidget.showVpnIcon = widget.showVpnIcon ?? SettingsData.controlCenterShowVpnIcon; + newWidget.showBrightnessIcon = widget.showBrightnessIcon ?? SettingsData.controlCenterShowBrightnessIcon; + newWidget.showMicIcon = widget.showMicIcon ?? SettingsData.controlCenterShowMicIcon; + newWidget.showBatteryIcon = widget.showBatteryIcon ?? SettingsData.controlCenterShowBatteryIcon; + newWidget.showPrinterIcon = widget.showPrinterIcon ?? SettingsData.controlCenterShowPrinterIcon; } widgets[widgetIndex] = newWidget; setWidgetsForSection(sectionId, widgets); @@ -730,9 +762,14 @@ Item { if (widget.keyboardLayoutNameCompactMode !== undefined) newWidget.keyboardLayoutNameCompactMode = widget.keyboardLayoutNameCompactMode; if (widget.id === "controlCenterButton") { - newWidget.showNetworkIcon = widget.showNetworkIcon ?? true; - newWidget.showBluetoothIcon = widget.showBluetoothIcon ?? true; - newWidget.showAudioIcon = widget.showAudioIcon ?? true; + newWidget.showNetworkIcon = widget.showNetworkIcon ?? SettingsData.controlCenterShowNetworkIcon; + newWidget.showBluetoothIcon = widget.showBluetoothIcon ?? SettingsData.controlCenterShowBluetoothIcon; + newWidget.showAudioIcon = widget.showAudioIcon ?? SettingsData.controlCenterShowAudioIcon; + newWidget.showVpnIcon = widget.showVpnIcon ?? SettingsData.controlCenterShowVpnIcon; + newWidget.showBrightnessIcon = widget.showBrightnessIcon ?? SettingsData.controlCenterShowBrightnessIcon; + newWidget.showMicIcon = widget.showMicIcon ?? SettingsData.controlCenterShowMicIcon; + newWidget.showBatteryIcon = widget.showBatteryIcon ?? SettingsData.controlCenterShowBatteryIcon; + newWidget.showPrinterIcon = widget.showPrinterIcon ?? SettingsData.controlCenterShowPrinterIcon; } widgets[i] = newWidget; widget = newWidget; @@ -789,6 +826,16 @@ Item { item.showBluetoothIcon = widget.showBluetoothIcon; if (widget.showAudioIcon !== undefined) item.showAudioIcon = widget.showAudioIcon; + if (widget.showVpnIcon !== undefined) + item.showVpnIcon = widget.showVpnIcon; + if (widget.showBrightnessIcon !== undefined) + item.showBrightnessIcon = widget.showBrightnessIcon; + if (widget.showMicIcon !== undefined) + item.showMicIcon = widget.showMicIcon; + if (widget.showBatteryIcon !== undefined) + item.showBatteryIcon = widget.showBatteryIcon; + if (widget.showPrinterIcon !== undefined) + item.showPrinterIcon = widget.showPrinterIcon; if (widget.minimumWidth !== undefined) item.minimumWidth = widget.minimumWidth; if (widget.showSwap !== undefined) diff --git a/quickshell/Modules/Settings/WidgetsTabSection.qml b/quickshell/Modules/Settings/WidgetsTabSection.qml index fb64ee1c..2c84933b 100644 --- a/quickshell/Modules/Settings/WidgetsTabSection.qml +++ b/quickshell/Modules/Settings/WidgetsTabSection.qml @@ -806,50 +806,42 @@ Column { { icon: "lan", label: I18n.tr("Network"), - setting: "showNetworkIcon", - checked: SettingsData.controlCenterShowNetworkIcon + setting: "showNetworkIcon" }, { icon: "vpn_lock", label: I18n.tr("VPN"), - setting: "showVpnIcon", - checked: SettingsData.controlCenterShowVpnIcon + setting: "showVpnIcon" }, { icon: "bluetooth", label: I18n.tr("Bluetooth"), - setting: "showBluetoothIcon", - checked: SettingsData.controlCenterShowBluetoothIcon + setting: "showBluetoothIcon" }, { icon: "volume_up", label: I18n.tr("Audio"), - setting: "showAudioIcon", - checked: SettingsData.controlCenterShowAudioIcon + setting: "showAudioIcon" }, { icon: "mic", label: I18n.tr("Microphone"), - setting: "showMicIcon", - checked: SettingsData.controlCenterShowMicIcon + setting: "showMicIcon" }, { icon: "brightness_high", label: I18n.tr("Brightness"), - setting: "showBrightnessIcon", - checked: SettingsData.controlCenterShowBrightnessIcon + setting: "showBrightnessIcon" }, { icon: "battery_full", label: I18n.tr("Battery"), - setting: "showBatteryIcon", - checked: SettingsData.controlCenterShowBatteryIcon + setting: "showBatteryIcon" }, { icon: "print", label: I18n.tr("Printer"), - setting: "showPrinterIcon", - checked: SettingsData.controlCenterShowPrinterIcon + setting: "showPrinterIcon" } ] @@ -857,6 +849,30 @@ Column { required property var modelData required property int index + function getCheckedState() { + var wd = controlCenterContextMenu.widgetData; + switch (modelData.setting) { + case "showNetworkIcon": + return wd?.showNetworkIcon ?? SettingsData.controlCenterShowNetworkIcon; + case "showVpnIcon": + return wd?.showVpnIcon ?? SettingsData.controlCenterShowVpnIcon; + case "showBluetoothIcon": + return wd?.showBluetoothIcon ?? SettingsData.controlCenterShowBluetoothIcon; + case "showAudioIcon": + return wd?.showAudioIcon ?? SettingsData.controlCenterShowAudioIcon; + case "showMicIcon": + return wd?.showMicIcon ?? SettingsData.controlCenterShowMicIcon; + case "showBrightnessIcon": + return wd?.showBrightnessIcon ?? SettingsData.controlCenterShowBrightnessIcon; + case "showBatteryIcon": + return wd?.showBatteryIcon ?? SettingsData.controlCenterShowBatteryIcon; + case "showPrinterIcon": + return wd?.showPrinterIcon ?? SettingsData.controlCenterShowPrinterIcon; + default: + return false; + } + } + width: menuColumn.width height: 32 radius: Theme.cornerRadius @@ -891,7 +907,7 @@ Column { anchors.verticalCenter: parent.verticalCenter width: 40 height: 20 - checked: modelData.checked + checked: getCheckedState() onToggled: { root.controlCenterSettingChanged(controlCenterContextMenu.sectionId, controlCenterContextMenu.widgetIndex, modelData.setting, toggled); }