From fb471f1023ab4991c124d0bc432028d95d7b7300 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sun, 4 May 2025 20:45:34 +1000 Subject: feat: audio osd --- modules/osd/Background.qml | 61 +++++++++++++++++++++++++++++++ modules/osd/Content.qml | 42 ++++++++++++++++++++++ modules/osd/Osd.qml | 89 ++++++++++++++++++++++++++++++++++++++++++++++ modules/osd/Wrapper.qml | 62 ++++++++++++++++++++++++++++++++ 4 files changed, 254 insertions(+) create mode 100644 modules/osd/Background.qml create mode 100644 modules/osd/Content.qml create mode 100644 modules/osd/Osd.qml create mode 100644 modules/osd/Wrapper.qml (limited to 'modules/osd') diff --git a/modules/osd/Background.qml b/modules/osd/Background.qml new file mode 100644 index 0000000..e0383f5 --- /dev/null +++ b/modules/osd/Background.qml @@ -0,0 +1,61 @@ +import "root:/config" +import QtQuick +import QtQuick.Shapes + +Shape { + id: root + + required property real realWrapperWidth + required property real wrapperHeight + readonly property int rounding: Appearance.rounding.large + readonly property int roundingX: Math.min(rounding, realWrapperWidth / 2) + readonly property real wrapperWidth: realWrapperWidth - 1 // Pixel issues :sob: + + preferredRendererType: Shape.CurveRenderer + opacity: Appearance.transparency.enabled ? Appearance.transparency.base : 1 + + ShapePath { + strokeWidth: -1 + fillColor: Appearance.colours.m3surfaceContainer + + startX: root.wrapperWidth + + PathArc { + relativeX: -root.roundingX + relativeY: root.rounding + radiusX: root.roundingX + radiusY: root.rounding + } + PathLine { + x: root.roundingX + relativeY: 0 + } + PathArc { + relativeX: -root.roundingX + relativeY: root.rounding + radiusX: root.roundingX + radiusY: root.rounding + direction: PathArc.Counterclockwise + } + PathLine { + y: root.wrapperHeight - root.rounding * 2 + } + PathArc { + relativeX: root.roundingX + relativeY: root.rounding + radiusX: root.roundingX + radiusY: root.rounding + direction: PathArc.Counterclockwise + } + PathLine { + x: root.wrapperWidth - root.roundingX + relativeY: 0 + } + PathArc { + relativeX: root.roundingX + relativeY: root.rounding + radiusX: root.roundingX + radiusY: root.rounding + } + } +} diff --git a/modules/osd/Content.qml b/modules/osd/Content.qml new file mode 100644 index 0000000..daab4e2 --- /dev/null +++ b/modules/osd/Content.qml @@ -0,0 +1,42 @@ +import "root:/widgets" +import "root:/services" +import "root:/config" +import Quickshell +import QtQuick + +Column { + id: root + + required property ShellScreen screen + + padding: Appearance.padding.large + + anchors.verticalCenter: parent.verticalCenter + anchors.right: parent.right + + spacing: Appearance.spacing.normal + + VerticalSlider { + icon: { + if (Audio.muted) + return "no_sound"; + if (value >= 0.5) + return "volume_up"; + if (value > 0) + return "volume_down"; + return "volume_mute"; + } + value: Audio.volume + onMoved: Audio.setVolume(value) + + implicitWidth: OsdConfig.sizes.sliderWidth + implicitHeight: OsdConfig.sizes.sliderHeight + } + + VerticalSlider { + icon: "brightness_6" + + implicitWidth: OsdConfig.sizes.sliderWidth + implicitHeight: OsdConfig.sizes.sliderHeight + } +} diff --git a/modules/osd/Osd.qml b/modules/osd/Osd.qml new file mode 100644 index 0000000..4d744f6 --- /dev/null +++ b/modules/osd/Osd.qml @@ -0,0 +1,89 @@ +import "root:/widgets" +import "root:/services" +import "root:/config" +import Quickshell +import QtQuick + +Scope { + id: root + + property bool osdVisible + + function show(): void { + root.osdVisible = true; + timer.restart(); + } + + Connections { + target: Audio + + function onMutedChanged(): void { + root.show(); + } + + function onVolumeChanged(): void { + root.show(); + } + } + + Timer { + id: timer + + interval: OsdConfig.hideDelay + onTriggered: root.osdVisible = false + } + + Variants { + model: Quickshell.screens + + LazyLoader { + loading: true + + required property ShellScreen modelData + + StyledWindow { + id: win + + screen: parent.modelData + name: "osd" + visible: wrapper.shouldBeVisible + + mask: Region { + item: wrapper + } + + anchors.left: true + anchors.right: true + height: wrapper.height + + Background { + id: bg + + anchors.verticalCenter: parent.verticalCenter + anchors.right: parent.right + + wrapperHeight: wrapper.height + realWrapperWidth: Math.min(wrapper.width, content.width) + } + + Wrapper { + id: wrapper + + anchors.verticalCenter: parent.verticalCenter + anchors.right: parent.right + + implicitHeight: content.height + bg.rounding * 2 + + osdVisible: root.osdVisible + contentWidth: content.width + + Content { + id: content + + screen: parent.modelData + } + } + } + } + } +} diff --git a/modules/osd/Wrapper.qml b/modules/osd/Wrapper.qml new file mode 100644 index 0000000..92bd3c2 --- /dev/null +++ b/modules/osd/Wrapper.qml @@ -0,0 +1,62 @@ +import "root:/config" +import QtQuick + +Item { + id: root + + required property bool osdVisible + required property real contentWidth + property bool shouldBeVisible + + width: 0 + clip: true + + states: State { + name: "visible" + when: root.osdVisible + + PropertyChanges { + root.width: contentWidth + root.shouldBeVisible: true + } + } + + transitions: [ + Transition { + from: "" + to: "visible" + + SequentialAnimation { + PropertyAction { + target: root + property: "shouldBeVisible" + } + NumberAnimation { + target: root + property: "width" + duration: Appearance.anim.durations.large + easing.type: Easing.BezierSpline + easing.bezierCurve: Appearance.anim.curves.emphasizedDecel + } + } + }, + Transition { + from: "visible" + to: "" + + SequentialAnimation { + NumberAnimation { + target: root + property: "width" + duration: Appearance.anim.durations.normal + easing.type: Easing.BezierSpline + easing.bezierCurve: Appearance.anim.curves.emphasizedAccel + } + PropertyAction { + target: root + property: "shouldBeVisible" + } + } + } + ] +} -- cgit v1.2.3-freya