From 24b8eeb1f4cb334e6908c33811d2917e26b1888d Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Mon, 17 Nov 2025 10:16:33 +0800 Subject: [PATCH] feat: Optimize capsule color computation by using Style.qml property --- Commons/Style.qml | 3 +++ Modules/Bar/Extras/BarPillHorizontal.qml | 2 +- Modules/Bar/Extras/BarPillVertical.qml | 2 +- Modules/Bar/Widgets/ActiveWindow.qml | 2 +- Modules/Bar/Widgets/AudioVisualizer.qml | 2 +- Modules/Bar/Widgets/Clock.qml | 2 +- Modules/Bar/Widgets/ControlCenter.qml | 2 +- Modules/Bar/Widgets/DarkMode.qml | 2 +- Modules/Bar/Widgets/LockKeys.qml | 2 +- Modules/Bar/Widgets/MediaMini.qml | 2 +- Modules/Bar/Widgets/NightLight.qml | 2 +- Modules/Bar/Widgets/NoctaliaPerformance.qml | 2 +- Modules/Bar/Widgets/NotificationHistory.qml | 2 +- Modules/Bar/Widgets/PowerProfile.qml | 2 +- Modules/Bar/Widgets/ScreenRecorder.qml | 2 +- Modules/Bar/Widgets/SessionMenu.qml | 2 +- Modules/Bar/Widgets/SystemMonitor.qml | 2 +- Modules/Bar/Widgets/Taskbar.qml | 2 +- Modules/Bar/Widgets/TaskbarGrouped.qml | 2 +- Modules/Bar/Widgets/Tray.qml | 6 +++--- Modules/Bar/Widgets/WallpaperSelector.qml | 2 +- Modules/Bar/Widgets/Workspace.qml | 2 +- 22 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Commons/Style.qml b/Commons/Style.qml index 64e4e22b3..b27e4e65f 100644 --- a/Commons/Style.qml +++ b/Commons/Style.qml @@ -104,4 +104,7 @@ Singleton { return Math.round(barHeight * 0.82); } } + readonly property color capsuleColor: Settings.data.bar.showCapsule ? + Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : + Color.transparent } diff --git a/Modules/Bar/Extras/BarPillHorizontal.qml b/Modules/Bar/Extras/BarPillHorizontal.qml index 230eb0fe4..cb4b6e839 100644 --- a/Modules/Bar/Extras/BarPillHorizontal.qml +++ b/Modules/Bar/Extras/BarPillHorizontal.qml @@ -78,7 +78,7 @@ Item { width: root.width height: pillHeight radius: halfPillHeight - color: hovered ? Color.mHover : Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent + color: hovered ? Color.mHover : Style.capsuleColor anchors.verticalCenter: parent.verticalCenter readonly property int halfPillHeight: Math.round(pillHeight * 0.5) diff --git a/Modules/Bar/Extras/BarPillVertical.qml b/Modules/Bar/Extras/BarPillVertical.qml index fc5f2ecc9..66f32fdd5 100644 --- a/Modules/Bar/Extras/BarPillVertical.qml +++ b/Modules/Bar/Extras/BarPillVertical.qml @@ -89,7 +89,7 @@ Item { width: buttonSize height: revealed ? (buttonSize + maxPillHeight - pillOverlap) : buttonSize radius: halfButtonSize - color: hovered ? Color.mHover : Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent + color: hovered ? Color.mHover : Style.capsuleColor readonly property int halfButtonSize: Math.round(buttonSize * 0.5) diff --git a/Modules/Bar/Widgets/ActiveWindow.qml b/Modules/Bar/Widgets/ActiveWindow.qml index 712a537c8..cbd95315f 100644 --- a/Modules/Bar/Widgets/ActiveWindow.qml +++ b/Modules/Bar/Widgets/ActiveWindow.qml @@ -173,7 +173,7 @@ Item { width: isVerticalBar ? ((!hasFocusedWindow) && hideMode === "hidden" ? 0 : calculatedVerticalDimension()) : ((!hasFocusedWindow) && (hideMode === "hidden") ? 0 : dynamicWidth) height: isVerticalBar ? ((!hasFocusedWindow) && hideMode === "hidden" ? 0 : calculatedVerticalDimension()) : Style.capsuleHeight radius: isVerticalBar ? width / 2 : Style.radiusM - color: Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent + color: Style.capsuleColor // Smooth width transition Behavior on width { diff --git a/Modules/Bar/Widgets/AudioVisualizer.qml b/Modules/Bar/Widgets/AudioVisualizer.qml index e84c149ac..8623ca063 100644 --- a/Modules/Bar/Widgets/AudioVisualizer.qml +++ b/Modules/Bar/Widgets/AudioVisualizer.qml @@ -74,7 +74,7 @@ Item { id: background anchors.fill: parent radius: Style.radiusS - color: Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent + color: Style.capsuleColor } // Store visualizer type to force re-evaluation diff --git a/Modules/Bar/Widgets/Clock.qml b/Modules/Bar/Widgets/Clock.qml index adde48acc..6e9e183bb 100644 --- a/Modules/Bar/Widgets/Clock.qml +++ b/Modules/Bar/Widgets/Clock.qml @@ -46,7 +46,7 @@ Rectangle { implicitHeight: isBarVertical ? Math.round(verticalLoader.implicitHeight + Style.marginS * 2) : Style.capsuleHeight radius: Style.radiusS - color: Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent + color: Style.capsuleColor Item { id: clockContainer diff --git a/Modules/Bar/Widgets/ControlCenter.qml b/Modules/Bar/Widgets/ControlCenter.qml index de5599e8d..484e6bc1b 100644 --- a/Modules/Bar/Widgets/ControlCenter.qml +++ b/Modules/Bar/Widgets/ControlCenter.qml @@ -45,7 +45,7 @@ NIconButton { baseSize: Style.capsuleHeight applyUiScale: false density: Settings.data.bar.density - colorBg: (Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent) + colorBg: Style.capsuleColor colorFg: Color.mOnSurface colorBgHover: useDistroLogo ? Color.mSurfaceVariant : Color.mHover colorBorder: Color.transparent diff --git a/Modules/Bar/Widgets/DarkMode.qml b/Modules/Bar/Widgets/DarkMode.qml index 9dbe62016..28045f8bf 100644 --- a/Modules/Bar/Widgets/DarkMode.qml +++ b/Modules/Bar/Widgets/DarkMode.qml @@ -14,7 +14,7 @@ NIconButton { density: Settings.data.bar.density baseSize: Style.capsuleHeight applyUiScale: false - colorBg: Settings.data.colorSchemes.darkMode ? (Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent) : Color.mPrimary + colorBg: Settings.data.colorSchemes.darkMode ? Style.capsuleColor : Color.mPrimary colorFg: Settings.data.colorSchemes.darkMode ? Color.mOnSurface : Color.mOnPrimary colorBorder: Color.transparent colorBorderHover: Color.transparent diff --git a/Modules/Bar/Widgets/LockKeys.qml b/Modules/Bar/Widgets/LockKeys.qml index 840c18644..272953f93 100644 --- a/Modules/Bar/Widgets/LockKeys.qml +++ b/Modules/Bar/Widgets/LockKeys.qml @@ -45,7 +45,7 @@ Rectangle { Layout.alignment: Qt.AlignVCenter radius: Style.radiusM - color: Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent + color: Style.capsuleColor Item { id: layout diff --git a/Modules/Bar/Widgets/MediaMini.qml b/Modules/Bar/Widgets/MediaMini.qml index 5d0aac89a..8a5fa212d 100644 --- a/Modules/Bar/Widgets/MediaMini.qml +++ b/Modules/Bar/Widgets/MediaMini.qml @@ -170,7 +170,7 @@ Item { width: isVerticalBar ? ((shouldHideIdle || isEmptyForHideMode) ? 0 : calculatedVerticalDimension()) : ((shouldHideIdle || isEmptyForHideMode) ? 0 : dynamicWidth) height: isVerticalBar ? ((shouldHideIdle || isEmptyForHideMode) ? 0 : calculatedVerticalDimension()) : Style.capsuleHeight radius: isVerticalBar ? width / 2 : Style.radiusM - color: Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent + color: Style.capsuleColor // Smooth width transition Behavior on width { diff --git a/Modules/Bar/Widgets/NightLight.qml b/Modules/Bar/Widgets/NightLight.qml index a535544cd..7346e06d8 100644 --- a/Modules/Bar/Widgets/NightLight.qml +++ b/Modules/Bar/Widgets/NightLight.qml @@ -17,7 +17,7 @@ NIconButton { density: Settings.data.bar.density baseSize: Style.capsuleHeight applyUiScale: false - colorBg: Settings.data.nightLight.forced ? Color.mPrimary : (Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent) + colorBg: Settings.data.nightLight.forced ? Color.mPrimary : Style.capsuleColor colorFg: Settings.data.nightLight.forced ? Color.mOnPrimary : Color.mOnSurface colorBorder: Color.transparent colorBorderHover: Color.transparent diff --git a/Modules/Bar/Widgets/NoctaliaPerformance.qml b/Modules/Bar/Widgets/NoctaliaPerformance.qml index 9acbcfd6f..64e93b5aa 100644 --- a/Modules/Bar/Widgets/NoctaliaPerformance.qml +++ b/Modules/Bar/Widgets/NoctaliaPerformance.qml @@ -17,7 +17,7 @@ NIconButton { density: Settings.data.bar.density baseSize: Style.capsuleHeight applyUiScale: false - colorBg: PowerProfileService.noctaliaPerformanceMode ? Color.mPrimary : (Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent) + colorBg: PowerProfileService.noctaliaPerformanceMode ? Color.mPrimary : Style.capsuleColor colorFg: PowerProfileService.noctaliaPerformanceMode ? Color.mOnPrimary : Color.mOnSurface colorBorder: Color.transparent colorBorderHover: Color.transparent diff --git a/Modules/Bar/Widgets/NotificationHistory.qml b/Modules/Bar/Widgets/NotificationHistory.qml index 6cf49f147..08d13830d 100644 --- a/Modules/Bar/Widgets/NotificationHistory.qml +++ b/Modules/Bar/Widgets/NotificationHistory.qml @@ -51,7 +51,7 @@ NIconButton { icon: NotificationService.doNotDisturb ? "bell-off" : "bell" tooltipText: NotificationService.doNotDisturb ? I18n.tr("tooltips.open-notification-history-disable-dnd") : I18n.tr("tooltips.open-notification-history-enable-dnd") tooltipDirection: BarService.getTooltipDirection() - colorBg: (Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent) + colorBg: Style.capsuleColor colorFg: Color.mOnSurface colorBorder: Color.transparent colorBorderHover: Color.transparent diff --git a/Modules/Bar/Widgets/PowerProfile.qml b/Modules/Bar/Widgets/PowerProfile.qml index 822304ad7..d7711db98 100644 --- a/Modules/Bar/Widgets/PowerProfile.qml +++ b/Modules/Bar/Widgets/PowerProfile.qml @@ -21,7 +21,7 @@ NIconButton { "profile": PowerProfileService.getName() }) tooltipDirection: BarService.getTooltipDirection() - colorBg: (PowerProfileService.profile === PowerProfile.Balanced) ? (Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent) : Color.mPrimary + colorBg: (PowerProfileService.profile === PowerProfile.Balanced) ? Style.capsuleColor : Color.mPrimary colorFg: (PowerProfileService.profile === PowerProfile.Balanced) ? Color.mOnSurface : Color.mOnPrimary colorBorder: Color.transparent colorBorderHover: Color.transparent diff --git a/Modules/Bar/Widgets/ScreenRecorder.qml b/Modules/Bar/Widgets/ScreenRecorder.qml index f2ce17246..3bcacc823 100644 --- a/Modules/Bar/Widgets/ScreenRecorder.qml +++ b/Modules/Bar/Widgets/ScreenRecorder.qml @@ -17,7 +17,7 @@ NIconButton { density: Settings.data.bar.density baseSize: Style.capsuleHeight applyUiScale: false - colorBg: ScreenRecorderService.isRecording ? Color.mPrimary : (Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent) + colorBg: ScreenRecorderService.isRecording ? Color.mPrimary : Style.capsuleColor colorFg: ScreenRecorderService.isRecording ? Color.mOnPrimary : Color.mOnSurface colorBorder: Color.transparent colorBorderHover: Color.transparent diff --git a/Modules/Bar/Widgets/SessionMenu.qml b/Modules/Bar/Widgets/SessionMenu.qml index 9d03a0b73..9c3a25f04 100644 --- a/Modules/Bar/Widgets/SessionMenu.qml +++ b/Modules/Bar/Widgets/SessionMenu.qml @@ -51,7 +51,7 @@ NIconButton { icon: "power" tooltipText: I18n.tr("tooltips.session-menu") tooltipDirection: BarService.getTooltipDirection() - colorBg: (Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent) + colorBg: Style.capsuleColor colorFg: root.iconColor colorBorder: Color.transparent colorBorderHover: Color.transparent diff --git a/Modules/Bar/Widgets/SystemMonitor.qml b/Modules/Bar/Widgets/SystemMonitor.qml index 71a5fe0e6..09cd27a39 100644 --- a/Modules/Bar/Widgets/SystemMonitor.qml +++ b/Modules/Bar/Widgets/SystemMonitor.qml @@ -108,7 +108,7 @@ Rectangle { implicitWidth: isVertical ? Style.capsuleHeight : Math.round(mainGrid.implicitWidth + Style.marginM * 2) implicitHeight: isVertical ? Math.round(mainGrid.implicitHeight + Style.marginM * 2) : Style.capsuleHeight radius: Style.radiusM - color: Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent + color: Style.capsuleColor // Status indicator component definition Component { diff --git a/Modules/Bar/Widgets/Taskbar.qml b/Modules/Bar/Widgets/Taskbar.qml index 88de12fd4..651a7ff35 100644 --- a/Modules/Bar/Widgets/Taskbar.qml +++ b/Modules/Bar/Widgets/Taskbar.qml @@ -90,7 +90,7 @@ Rectangle { implicitWidth: visible ? (isVerticalBar ? Style.capsuleHeight : Math.round(taskbarLayout.implicitWidth + Style.marginM * 2)) : 0 implicitHeight: visible ? (isVerticalBar ? Math.round(taskbarLayout.implicitHeight + Style.marginM * 2) : Style.capsuleHeight) : 0 radius: Style.radiusM - color: Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent + color: Style.capsuleColor GridLayout { id: taskbarLayout diff --git a/Modules/Bar/Widgets/TaskbarGrouped.qml b/Modules/Bar/Widgets/TaskbarGrouped.qml index f8bdaf1f8..01254d5e0 100644 --- a/Modules/Bar/Widgets/TaskbarGrouped.qml +++ b/Modules/Bar/Widgets/TaskbarGrouped.qml @@ -211,7 +211,7 @@ Item { border.width: 1 width: (hasWindows ? iconsFlow.implicitWidth : root.itemSize * 0.8) + (root.isVerticalBar ? Style.marginXS : Style.marginL) height: (hasWindows ? iconsFlow.implicitHeight : root.itemSize * 0.8) + (root.isVerticalBar ? Style.marginL : Style.marginXS) - color: Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent + color: Style.capsuleColor MouseArea { anchors.fill: parent diff --git a/Modules/Bar/Widgets/Tray.qml b/Modules/Bar/Widgets/Tray.qml index cc140bf33..37bdf08b6 100644 --- a/Modules/Bar/Widgets/Tray.qml +++ b/Modules/Bar/Widgets/Tray.qml @@ -225,7 +225,7 @@ Rectangle { implicitWidth: isVertical ? Style.capsuleHeight : Math.round(trayFlow.implicitWidth) implicitHeight: isVertical ? Math.round(trayFlow.implicitHeight) : Style.capsuleHeight radius: Style.radiusM - color: Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent + color: Style.capsuleColor Flow { id: trayFlow @@ -241,7 +241,7 @@ Rectangle { density: Settings.data.bar.density baseSize: Style.capsuleHeight applyUiScale: false - colorBg: Settings.data.colorSchemes.darkMode ? (Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent) : Color.mPrimary + colorBg: Settings.data.colorSchemes.darkMode ? Style.capsuleColor : Color.mPrimary colorFg: Settings.data.colorSchemes.darkMode ? Color.mOnSurface : Color.mOnPrimary colorBorder: Color.transparent colorBorderHover: Color.transparent @@ -396,7 +396,7 @@ Rectangle { density: Settings.data.bar.density baseSize: Style.capsuleHeight applyUiScale: false - colorBg: Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent + colorBg: Style.capsuleColor colorFg: Color.mOnSurface colorBorder: Color.transparent colorBorderHover: Color.transparent diff --git a/Modules/Bar/Widgets/WallpaperSelector.qml b/Modules/Bar/Widgets/WallpaperSelector.qml index 2b8455d70..0e2a01180 100644 --- a/Modules/Bar/Widgets/WallpaperSelector.qml +++ b/Modules/Bar/Widgets/WallpaperSelector.qml @@ -16,7 +16,7 @@ NIconButton { icon: "wallpaper-selector" tooltipText: I18n.tr("tooltips.open-wallpaper-selector") tooltipDirection: BarService.getTooltipDirection() - colorBg: (Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent) + colorBg: Style.capsuleColor colorFg: Color.mOnSurface colorBorder: Color.transparent colorBorderHover: Color.transparent diff --git a/Modules/Bar/Widgets/Workspace.qml b/Modules/Bar/Widgets/Workspace.qml index bc09f2660..739eb82e4 100644 --- a/Modules/Bar/Widgets/Workspace.qml +++ b/Modules/Bar/Widgets/Workspace.qml @@ -225,7 +225,7 @@ Item { width: isVertical ? Style.capsuleHeight : parent.width height: isVertical ? parent.height : Style.capsuleHeight radius: Style.radiusM - color: Settings.data.bar.showCapsule ? Qt.alpha(Color.mSurfaceVariant, Settings.data.bar.capsuleOpacity) : Color.transparent + color: Style.capsuleColor anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter