From c29041aa9e15eaa298cc5ad5863791cb239816f3 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Fri, 11 Apr 2025 16:03:54 +0200 Subject: [PATCH] bar: resources/music: dynamic show/hide --- .config/quickshell/modules/bar/Battery.qml | 1 - .config/quickshell/modules/bar/Media.qml | 2 +- .config/quickshell/modules/bar/Resource.qml | 64 +++++++++++++------ .config/quickshell/modules/bar/Resources.qml | 15 ++++- .../quickshell/modules/common/Appearance.qml | 2 +- .../modules/common/ConfigOptions.qml | 4 ++ .config/quickshell/shell.qml | 3 + 7 files changed, 65 insertions(+), 26 deletions(-) diff --git a/.config/quickshell/modules/bar/Battery.qml b/.config/quickshell/modules/bar/Battery.qml index b4cbea1f3..dc3b0d057 100644 --- a/.config/quickshell/modules/bar/Battery.qml +++ b/.config/quickshell/modules/bar/Battery.qml @@ -80,7 +80,6 @@ Rectangle { NumberAnimation { duration: Appearance.animation.elementDecel.duration easing.type: Appearance.animation.elementDecel.type - easing.bezierCurve: Appearance.animation.elementDecel.bezierCurve } } diff --git a/.config/quickshell/modules/bar/Media.qml b/.config/quickshell/modules/bar/Media.qml index 44431f016..e681140ad 100644 --- a/.config/quickshell/modules/bar/Media.qml +++ b/.config/quickshell/modules/bar/Media.qml @@ -77,7 +77,7 @@ Rectangle { horizontalAlignment: Text.AlignHCenter elide: Text.ElideRight // Truncates the text on the right color: Appearance.colors.colOnLayer1 - text: `${cleanedTitle} • ${activePlayer?.trackArtist}` + text: `${cleanedTitle}${activePlayer?.trackArtist ? ' • ' + activePlayer.trackArtist : ''}` } } diff --git a/.config/quickshell/modules/bar/Resource.qml b/.config/quickshell/modules/bar/Resource.qml index 4f231835e..3b7f83bfc 100644 --- a/.config/quickshell/modules/bar/Resource.qml +++ b/.config/quickshell/modules/bar/Resource.qml @@ -5,32 +5,56 @@ import QtQuick.Layouts import Quickshell import Quickshell.Io -RowLayout { +Rectangle { required property string iconName required property double percentage - spacing: 4 + property bool shown: true + clip: true + implicitWidth: resourceRowLayout.x < 0 ? 0 : childrenRect.width + implicitHeight: childrenRect.height + color: "transparent" - CircularProgress { - Layout.alignment: Qt.AlignVCenter - lineWidth: 2 - value: percentage - size: 26 - secondaryColor: Appearance.m3colors.m3secondaryContainer - primaryColor: Appearance.m3colors.m3onSecondaryContainer + RowLayout { + spacing: 4 + id: resourceRowLayout + x: shown ? 0 : -resourceRowLayout.width - MaterialSymbol { - anchors.centerIn: parent - text: iconName - font.pointSize: Appearance.font.pointSize.normal - color: Appearance.m3colors.m3onSecondaryContainer + CircularProgress { + Layout.alignment: Qt.AlignVCenter + lineWidth: 2 + value: percentage + size: 26 + secondaryColor: Appearance.m3colors.m3secondaryContainer + primaryColor: Appearance.m3colors.m3onSecondaryContainer + + MaterialSymbol { + anchors.centerIn: parent + text: iconName + font.pointSize: Appearance.font.pointSize.normal + color: Appearance.m3colors.m3onSecondaryContainer + } + + } + + StyledText { + Layout.alignment: Qt.AlignVCenter + color: Appearance.colors.colOnLayer1 + text: `${Math.round(percentage * 100)}%` + } + + Behavior on x { + NumberAnimation { + duration: Appearance.animation.elementDecel.duration + easing.type: Appearance.animation.elementDecel.type + } } } - StyledText { - Layout.alignment: Qt.AlignVCenter - color: Appearance.colors.colOnLayer1 - text: `${Math.round(percentage * 100)}%` + Behavior on implicitWidth { + NumberAnimation { + duration: Appearance.animation.elementDecel.duration + easing.type: Appearance.animation.elementDecel.type + } } - -} +} \ No newline at end of file diff --git a/.config/quickshell/modules/bar/Resources.qml b/.config/quickshell/modules/bar/Resources.qml index ea64c8ce6..4528f8b48 100644 --- a/.config/quickshell/modules/bar/Resources.qml +++ b/.config/quickshell/modules/bar/Resources.qml @@ -4,9 +4,10 @@ import QtQuick import QtQuick.Layouts import Quickshell import Quickshell.Io +import Quickshell.Services.Mpris Rectangle { - implicitWidth: rowLayout.implicitWidth + rowLayout.spacing * 2 + implicitWidth: rowLayout.implicitWidth + rowLayout.anchors.leftMargin + rowLayout.anchors.rightMargin implicitHeight: 32 color: Appearance.colors.colLayer1 radius: Appearance.rounding.small @@ -14,20 +15,28 @@ Rectangle { RowLayout { id: rowLayout - spacing: 4 - anchors.centerIn: parent + spacing: 0 + anchors.fill: parent + anchors.leftMargin: 4 + anchors.rightMargin: 4 Resource { iconName: "memory" percentage: ResourceUsage.memoryUsedPercentage } + Resource { iconName: "swap_horiz" percentage: ResourceUsage.swapUsedPercentage + shown: ConfigOptions.bar.resources.alwaysShowSwap || (MprisController.activePlayer == null) + Layout.leftMargin: shown ? 4 : 0 } + Resource { iconName: "settings_slow_motion" percentage: ResourceUsage.cpuUsage + shown: ConfigOptions.bar.resources.alwaysShowCpu || (MprisController.activePlayer == null) + Layout.leftMargin: shown ? 4 : 0 } } diff --git a/.config/quickshell/modules/common/Appearance.qml b/.config/quickshell/modules/common/Appearance.qml index d0b62f3a4..404656565 100644 --- a/.config/quickshell/modules/common/Appearance.qml +++ b/.config/quickshell/modules/common/Appearance.qml @@ -146,7 +146,7 @@ Singleton { } property QtObject menuDecel: QtObject { property int duration: 350 - property int type: Easing.OutQuint + property int type: Easing.OutExpo } } diff --git a/.config/quickshell/modules/common/ConfigOptions.qml b/.config/quickshell/modules/common/ConfigOptions.qml index df7f5e154..d86fb96a8 100644 --- a/.config/quickshell/modules/common/ConfigOptions.qml +++ b/.config/quickshell/modules/common/ConfigOptions.qml @@ -6,6 +6,10 @@ Singleton { property QtObject bar: QtObject { property int workspacesShown: 10 property int batteryLowThreshold: 20 + property QtObject resources: QtObject { + property bool alwaysShowSwap: true + property bool alwaysShowCpu: false + } } property QtObject resources: QtObject { property int updateInterval: 3000 diff --git a/.config/quickshell/shell.qml b/.config/quickshell/shell.qml index aeb4b2ba1..ceec43fd5 100644 --- a/.config/quickshell/shell.qml +++ b/.config/quickshell/shell.qml @@ -4,8 +4,11 @@ import QtQuick.Layouts import Quickshell import "./modules/bar" +import QtQuick.Window + ShellRoot { Bar { } + }