cava + nix

This commit is contained in:
Zacharias-Brohn
2026-02-26 16:27:05 +01:00
parent 09a93d9420
commit afb736102d
11 changed files with 311 additions and 237 deletions
+24 -4
View File
@@ -4,6 +4,7 @@ import qs.Config
Item { Item {
id: root id: root
property bool animate: false
property color color: DynamicColors.palette.m3onSurface property color color: DynamicColors.palette.m3onSurface
property int fadeStrengthAnimMs: 180 property int fadeStrengthAnimMs: 180
property real fadeStrengthIdle: 0.0 property real fadeStrengthIdle: 0.0
@@ -27,6 +28,19 @@ Item {
return Math.max(1, Math.round(Math.abs(px) / root.pixelsPerSecond * 1000)); return Math.max(1, Math.round(Math.abs(px) / root.pixelsPerSecond * 1000));
} }
function resetMarquee() {
// stop + reset all state immediately
marqueeAnim.stop();
strip.x = 0;
root.sliding = false;
root.leftFadeEnabled = false;
// restart after bindings/layout settle
if (root.marqueeEnabled && root.overflowing && root.visible) {
marqueeAnim.restart();
}
}
clip: true clip: true
implicitHeight: elideText.implicitHeight implicitHeight: elideText.implicitHeight
@@ -39,10 +53,10 @@ Item {
} }
} }
onTextChanged: strip.x = 0 onTextChanged: resetMarquee()
onVisibleChanged: if (!visible) onVisibleChanged: if (!visible)
strip.x = 0 resetMarquee()
onWidthChanged: strip.x = 0 onWidthChanged: resetMarquee()
TextMetrics { TextMetrics {
id: metrics id: metrics
@@ -55,8 +69,10 @@ Item {
id: elideText id: elideText
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
animate: root.animate
animateProp: "scale,opacity"
color: root.color color: root.color
elide: Text.ElideRight elide: Text.ElideNone
visible: !root.overflowing visible: !root.overflowing
width: root.width width: root.width
} }
@@ -84,6 +100,8 @@ Item {
CustomText { CustomText {
id: t1 id: t1
animate: root.animate
animateProp: "opacity"
color: root.color color: root.color
text: elideText.text text: elideText.text
} }
@@ -91,6 +109,8 @@ Item {
CustomText { CustomText {
id: t2 id: t2
animate: root.animate
animateProp: "opacity"
color: root.color color: root.color
text: t1.text text: t1.text
x: t1.width + root.gap x: t1.width + root.gap
+4
View File
@@ -11,6 +11,10 @@ JsonObject {
id: "audio", id: "audio",
enabled: true enabled: true
}, },
{
id: "media",
enabled: true
},
{ {
id: "resources", id: "resources",
enabled: true enabled: true
+6 -32
View File
@@ -24,35 +24,20 @@ Item {
} }
} }
Rectangle { CustomRect {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
color: DynamicColors.tPalette.m3surfaceContainer color: DynamicColors.tPalette.m3surfaceContainer
height: 22 height: 22
radius: height / 2 radius: height / 2
Behavior on color {
CAnim {
}
}
Rectangle {
anchors.centerIn: parent
border.color: "#30ffffff"
border.width: 0
color: "transparent"
height: parent.height
radius: width / 2
width: parent.width
} }
RowLayout { RowLayout {
id: layout id: layout
anchors.left: parent.left anchors.fill: parent
anchors.leftMargin: Appearance.padding.small anchors.leftMargin: Appearance.padding.small
anchors.right: parent.right
anchors.rightMargin: Appearance.padding.small * 2 anchors.rightMargin: Appearance.padding.small * 2
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@@ -63,24 +48,19 @@ Item {
text: Audio.muted ? "volume_off" : "volume_up" text: Audio.muted ? "volume_off" : "volume_up"
} }
Rectangle { CustomRect {
Layout.fillWidth: true Layout.fillWidth: true
color: "#50ffffff" color: "#50ffffff"
implicitHeight: 4 implicitHeight: 4
radius: 20 radius: 20
Rectangle { CustomRect {
id: sinkVolumeBar id: sinkVolumeBar
color: Audio.muted ? DynamicColors.palette.m3error : root.barColor color: Audio.muted ? DynamicColors.palette.m3error : root.barColor
implicitWidth: parent.width * (Audio.volume ?? 0) implicitWidth: parent.width * (Audio.volume ?? 0)
radius: parent.radius radius: parent.radius
Behavior on color {
CAnim {
}
}
anchors { anchors {
bottom: parent.bottom bottom: parent.bottom
left: parent.left left: parent.left
@@ -96,24 +76,19 @@ Item {
text: Audio.sourceMuted ? "mic_off" : "mic" text: Audio.sourceMuted ? "mic_off" : "mic"
} }
Rectangle { CustomRect {
Layout.fillWidth: true Layout.fillWidth: true
color: "#50ffffff" color: "#50ffffff"
implicitHeight: 4 implicitHeight: 4
radius: 20 radius: 20
Rectangle { CustomRect {
id: sourceVolumeBar id: sourceVolumeBar
color: (Audio.sourceMuted ?? false) ? DynamicColors.palette.m3error : root.barColor color: (Audio.sourceMuted ?? false) ? DynamicColors.palette.m3error : root.barColor
implicitWidth: parent.width * (Audio.sourceVolume ?? 0) implicitWidth: parent.width * (Audio.sourceVolume ?? 0)
radius: parent.radius radius: parent.radius
Behavior on color {
CAnim {
}
}
anchors { anchors {
bottom: parent.bottom bottom: parent.bottom
left: parent.left left: parent.left
@@ -123,4 +98,3 @@ Item {
} }
} }
} }
}
+9 -8
View File
@@ -206,14 +206,15 @@ RowLayout {
} }
} }
} }
// DelegateChoice {
// roleValue: "dash" DelegateChoice {
// delegate: WrappedLoader { roleValue: "media"
// sourceComponent: DashWidget {
// visibilities: root.visibilities delegate: WrappedLoader {
// } sourceComponent: MediaWidget {
// } }
// } }
}
} }
} }
+32 -3
View File
@@ -217,7 +217,7 @@ Item {
width: parent.width - Appearance.padding.large * 4 width: parent.width - Appearance.padding.large * 4
} }
Row { RowLayout {
id: controls id: controls
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
@@ -260,20 +260,48 @@ Item {
required property bool canUse required property bool canUse
required property string icon required property string icon
property int level: 1
property string set_color: "Secondary"
function onClicked(): void { function onClicked(): void {
} }
Layout.preferredWidth: implicitWidth + (controlState.pressed ? Appearance.padding.normal * 2 : 0)
color: canUse ? DynamicColors.palette[`m3${set_color.toLowerCase()}`] : DynamicColors.palette[`m3${set_color.toLowerCase()}Container`]
implicitHeight: implicitWidth implicitHeight: implicitWidth
implicitWidth: Math.max(icon.implicitHeight, icon.implicitHeight) + Appearance.padding.small implicitWidth: Math.max(icon.implicitHeight, icon.implicitHeight) + Appearance.padding.small
radius: Appearance.rounding.full
Behavior on Layout.preferredWidth {
Anim {
duration: Appearance.anim.durations.expressiveFastSpatial
easing.bezierCurve: Appearance.anim.curves.expressiveFastSpatial
}
}
Behavior on radius {
Anim {
duration: Appearance.anim.durations.expressiveFastSpatial
easing.bezierCurve: Appearance.anim.curves.expressiveFastSpatial
}
}
Elevation {
anchors.fill: parent
level: controlState.containsMouse && !controlState.pressed ? control.level + 1 : control.level
radius: parent.radius
z: -1
}
StateLayer { StateLayer {
id: controlState
function onClicked(): void { function onClicked(): void {
control.onClicked(); control.onClicked();
} }
color: control.canUse ? DynamicColors.palette[`m3on${control.set_color}`] : DynamicColors.palette[`m3on${control.set_color}Container`]
disabled: !control.canUse disabled: !control.canUse
radius: Appearance.rounding.full // radius: Appearance.rounding.full
} }
MaterialIcon { MaterialIcon {
@@ -282,7 +310,8 @@ Item {
anchors.centerIn: parent anchors.centerIn: parent
anchors.verticalCenterOffset: font.pointSize * 0.05 anchors.verticalCenterOffset: font.pointSize * 0.05
animate: true animate: true
color: control.canUse ? DynamicColors.palette.m3onSurface : DynamicColors.palette.m3outline color: control.canUse ? DynamicColors.palette[`m3on${control.set_color}`] : DynamicColors.palette[`m3on${control.set_color}Container`]
fill: control.canUse ? 1 : 0
font.pointSize: Appearance.font.size.large font.pointSize: Appearance.font.size.large
text: control.icon text: control.icon
} }
+3 -3
View File
@@ -121,9 +121,9 @@ Item {
active: Players.active?.isPlaying ?? false active: Players.active?.isPlaying ?? false
animate: true animate: true
colour: "Primary"
icon: active ? "pause" : "play_arrow" icon: active ? "pause" : "play_arrow"
level: active ? 2 : 1 level: active ? 2 : 1
set_color: "Primary"
} }
PlayerControl { PlayerControl {
@@ -142,15 +142,15 @@ Item {
property bool active property bool active
property alias animate: controlIcon.animate property alias animate: controlIcon.animate
property string colour: "Secondary"
property alias icon: controlIcon.text property alias icon: controlIcon.text
property int level: 1 property int level: 1
property string set_color: "Secondary"
function onClicked(): void { function onClicked(): void {
} }
Layout.preferredWidth: implicitWidth + (controlState.pressed ? Appearance.padding.normal * 2 : active ? Appearance.padding.small * 2 : 0) Layout.preferredWidth: implicitWidth + (controlState.pressed ? Appearance.padding.normal * 2 : active ? Appearance.padding.small * 2 : 0)
color: active ? DynamicColors.palette[`m3${colour.toLowerCase()}`] : DynamicColors.palette[`m3${colour.toLowerCase()}Container`] color: active ? DynamicColors.palette[`m3${set_color.toLowerCase()}`] : DynamicColors.palette[`m3${set_color.toLowerCase()}Container`]
implicitHeight: controlIcon.implicitHeight + Appearance.padding.normal * 2 implicitHeight: controlIcon.implicitHeight + Appearance.padding.normal * 2
implicitWidth: controlIcon.implicitWidth + Appearance.padding.large * 2 implicitWidth: controlIcon.implicitWidth + Appearance.padding.large * 2
radius: active || controlState.pressed ? Appearance.rounding.small : Appearance.rounding.normal radius: active || controlState.pressed ? Appearance.rounding.small : Appearance.rounding.normal
+73
View File
@@ -0,0 +1,73 @@
import QtQuick
import QtQuick.Layouts
import qs.Components
import qs.Daemons
import qs.Config
import qs.Helpers
Item {
id: root
readonly property string currentMedia: (Players.active?.trackTitle ?? qsTr("No media")) || qsTr("Unknown title")
readonly property int textWidth: Math.min(metrics.width, 200)
anchors.bottom: parent.bottom
anchors.top: parent.top
implicitWidth: layout.implicitWidth + Appearance.padding.normal * 2
Behavior on implicitWidth {
Anim {
}
}
CustomRect {
anchors.left: parent.left
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
color: DynamicColors.tPalette.m3surfaceContainer
implicitHeight: 22
radius: Appearance.rounding.full
}
TextMetrics {
id: metrics
font: mediatext.font
text: mediatext.text
}
RowLayout {
id: layout
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.left: parent.left
anchors.leftMargin: Appearance.padding.normal
anchors.top: parent.top
Behavior on implicitWidth {
Anim {
}
}
MaterialIcon {
animate: true
color: Players.active?.isPlaying ? DynamicColors.palette.m3primary : DynamicColors.palette.m3onSurface
font.pointSize: 14
text: Players.active?.isPlaying ? "music_note" : "music_off"
}
MarqueeText {
id: mediatext
Layout.preferredWidth: root.textWidth
animate: true
color: Players.active?.isPlaying ? DynamicColors.palette.m3primary : DynamicColors.palette.m3onSurface
font.pointSize: Appearance.font.size.normal
horizontalAlignment: Text.AlignHCenter
pauseMs: 4000
text: root.currentMedia
width: root.textWidth
}
}
}
+2 -7
View File
@@ -16,23 +16,19 @@ Item {
implicitHeight: 34 implicitHeight: 34
implicitWidth: rowLayout.implicitWidth + Appearance.padding.small * 2 implicitWidth: rowLayout.implicitWidth + Appearance.padding.small * 2
Rectangle { CustomRect {
id: backgroundRect id: backgroundRect
color: DynamicColors.tPalette.m3surfaceContainer color: DynamicColors.tPalette.m3surfaceContainer
implicitHeight: 22 implicitHeight: 22
radius: height / 2 radius: height / 2
Behavior on color {
CAnim {
}
}
anchors { anchors {
left: parent.left left: parent.left
right: parent.right right: parent.right
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
} }
}
RowLayout { RowLayout {
id: rowLayout id: rowLayout
@@ -92,4 +88,3 @@ Item {
} }
} }
} }
}
+1 -9
View File
@@ -27,25 +27,17 @@ Item {
id: contentRow id: contentRow
anchors.centerIn: parent anchors.centerIn: parent
implicitHeight: 22
spacing: Appearance.spacing.small spacing: Appearance.spacing.small
MaterialIcon { MaterialIcon {
Layout.alignment: Qt.AlignVCenter
font.pointSize: 14 font.pointSize: 14
text: "package_2" text: "package_2"
} }
TextMetrics {
id: textMetrics
text: root.countUpdates
}
CustomText { CustomText {
color: root.textColor color: root.textColor
font.pointSize: 12 font.pointSize: 12
text: textMetrics.text text: root.countUpdates
} }
} }
} }
+12 -29
View File
@@ -4,7 +4,6 @@
#include "audioprovider.hpp" #include "audioprovider.hpp"
#include <algorithm> #include <algorithm>
#include <cava/cavacore.h> #include <cava/cavacore.h>
#include <cmath>
#include <cstddef> #include <cstddef>
#include <qdebug.h> #include <qdebug.h>
@@ -40,35 +39,19 @@ void CavaProcessor::process() {
values[i] = std::clamp(m_out[i], 0.0, 1.0); values[i] = std::clamp(m_out[i], 0.0, 1.0);
} }
// --- spectral contrast (removes the "everything rises together" effect) // Left to right pass
// QVector<double> tmp = values; // const double inv = 1.0 / 1.5;
// auto* b = tmp.data(); // double carry = 0.0;
// auto* e = b + tmp.size();
//
// auto pct = [&](double p) -> double {
// const qsizetype n = tmp.size();
// if (n <= 0) return 0.0;
//
// // p in [0,1] -> index in [0, n-1]
// const double pos = p * double(n - 1);
// qsizetype k = static_cast<qsizetype>(std::llround(pos));
// k = std::clamp<qsizetype>(k, 0, n - 1);
//
// auto first = tmp.begin();
// auto nth = first + k;
// std::nth_element(first, nth, tmp.end());
// return *nth;
// };
//
// const double floor = pct(0.25);
// const double ceil = pct(0.95);
// const double range = std::max(1e-6, ceil - floor);
//
// const double gamma = 1.6; // 1.3..2.2 range; higher = more contrast
// for (int i = 0; i < m_bars; ++i) { // for (int i = 0; i < m_bars; ++i) {
// double x = (values[i] - floor) / range; // carry = std::max(m_out[i], carry * inv);
// x = std::clamp(x, 0.0, 1.0); // values[i] = carry;
// values[i] = std::pow(x, gamma); // }
//
// // Right to left pass and combine
// carry = 0.0;
// for (int i = m_bars - 1; i >= 0; --i) {
// carry = std::max(m_out[i], carry * inv);
// values[i] = std::max(values[i], carry);
// } // }
// Update values // Update values
+8 -5
View File
@@ -1,4 +1,6 @@
{ {
fftw,
libcava,
rev, rev,
lib, lib,
stdenv, stdenv,
@@ -23,7 +25,8 @@
pkg-config, pkg-config,
pythonEnv, pythonEnv,
zshell-cli, zshell-cli,
}: let }:
let
version = "1.0.0"; version = "1.0.0";
runtimeDeps = [ runtimeDeps = [
@@ -74,11 +77,12 @@
libqalculate libqalculate
pipewire pipewire
aubio aubio
libcava
fftw
]; ];
dontWrapQtApps = true; dontWrapQtApps = true;
cmakeFlags = cmakeFlags = [
[
(lib.cmakeFeature "ENABLE_MODULES" "plugin") (lib.cmakeFeature "ENABLE_MODULES" "plugin")
(lib.cmakeFeature "INSTALL_QMLDIR" qt6.qtbase.qtQmlPrefix) (lib.cmakeFeature "INSTALL_QMLDIR" qt6.qtbase.qtQmlPrefix)
] ]
@@ -104,8 +108,7 @@ in
]; ];
propagatedBuildInputs = runtimeDeps; propagatedBuildInputs = runtimeDeps;
cmakeFlags = cmakeFlags = [
[
(lib.cmakeFeature "ENABLE_MODULES" "shell") (lib.cmakeFeature "ENABLE_MODULES" "shell")
(lib.cmakeFeature "INSTALL_QSCONFDIR" "${placeholder "out"}/share/ZShell") (lib.cmakeFeature "INSTALL_QSCONFDIR" "${placeholder "out"}/share/ZShell")
] ]