This repository has been archived on 2026-11-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
dotfiles/mutable_config/quickshell/components/OSD/OSD.qml
T

126 lines
3.7 KiB
QML

import QtQuick
import Quickshell
import Quickshell.Wayland
import Quickshell.Services.Pipewire
import Quickshell.Io
import "../Shared"
PanelWindow {
id: osdWindow
// API
function show(newMode) {
mode = newMode;
if (mode === "brightness") {
brightnessProcess.restart();
}
visibleTimer.restart();
}
property string mode: "volume" // "volume" or "brightness"
property real brightnessLevel: 0.5
// Pipewire Audio Binding
property QtObject sink: Pipewire.defaultAudioSink
// Ensure sink and audio are valid before trying to read volume
property bool sinkReady: sink !== null && sink.ready && sink.audio !== null
property real volumeLevel: sinkReady ? sink.audio.volume : 0.0
property bool isMuted: sinkReady ? sink.audio.muted : false
PwObjectTracker {
objects: sink !== null ? [sink] : []
}
anchors {
bottom: true
left: true
right: true
}
margins {
bottom: visibleTimer.running ? Theme.geometry.padding * 4 : -implicitHeight - 50
}
Behavior on margins.bottom {
NumberAnimation {
duration: Theme.animation.durationNormal
easing.type: Easing.OutBack
}
}
exclusiveZone: 0
color: "transparent"
implicitHeight: 60
WlrLayershell.layer: WlrLayer.Overlay
WlrLayershell.namespace: "quickshell-osd"
Timer {
id: visibleTimer
interval: 2000
}
Process {
id: brightnessProcess
// brightnessctl -m outputs: intel_backlight,backlight,12000,100%,12000
command: ["bash", "-c", "brightnessctl -m 2>/dev/null | awk -F, '{print $4}' | tr -d '%'"]
running: false
function restart() { running = false; running = true; }
stdout: StdioCollector {
onStreamFinished: {
let val = parseInt(this.text);
if (!isNaN(val)) {
brightnessLevel = val / 100.0;
}
}
}
}
Surface {
width: 300
height: 60
anchors.centerIn: parent
radius: Theme.geometry.pillRadius
tint: osdWindow.levelColor
glow: true
Item {
anchors.fill: parent
anchors.margins: Theme.geometry.padding
Text {
id: iconText
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
text: {
if (mode === "volume") {
if (isMuted) return ""; // nf-fa-volume_off
if (volumeLevel < 0.5) return ""; // nf-fa-volume_down
return ""; // nf-fa-volume_up
} else {
return ""; // nf-fa-sun_o
}
}
color: osdWindow.levelColor
font.family: Theme.font.family
font.pixelSize: 18
}
ProgressBar {
anchors.left: iconText.right
anchors.leftMargin: Theme.geometry.spacing
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
value: mode === "volume" ? volumeLevel : brightnessLevel
fillColor: osdWindow.levelColor
}
}
}
// Volume gets the primary accent, brightness gets a warm warning-ish
// tint (sun-colored), muted volume falls back to a neutral color.
readonly property color levelColor: (mode === "volume" && isMuted)
? Theme.colors.textMuted
: (mode === "volume" ? Theme.colors.primary : Theme.colors.warning)
}