Add a Caffeine inhibitor, app stream volumes and vertical bar sliders

CaffeineService holds a systemd-inhibit idle/sleep lock while active.
AudioService lists app playback streams and tracks their volume only
while a view holds a Demand on it. GlassBarSlider fills from the bottom
when vertical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mxandClaude Opus 5.5 committed 2026-10-17 20:52:14 +02:00
1 parent d6a6cf69f4
commit 0dcf37346c
4 files changed
+94 -18

No files matched your search

+28 -17
View File
@@ -3,30 +3,40 @@ import QtQuick.Controls
import "../theme" import "../theme"
// Thick pill slider with an icon inside the track (macOS Control Center style). // Thick pill slider with an icon inside the track (macOS Control Center style).
// Vertical sliders fill from the bottom with the icon at the foot.
Slider { Slider {
id: root id: root
property string glyph property string glyph
property string fallback property string fallback
implicitWidth: 220 implicitWidth: vertical ? 28 : 220
implicitHeight: 28 implicitHeight: vertical ? 220 : 28
padding: 0 padding: 0
background: Rectangle { background: Rectangle {
x: root.leftPadding x: root.leftPadding
y: root.topPadding + root.availableHeight / 2 - height / 2 y: root.topPadding + (root.vertical ? 0 : root.availableHeight / 2 - height / 2)
width: root.availableWidth width: root.availableWidth
height: root.availableHeight height: root.availableHeight
radius: height / 2 radius: Math.min(width, height) / 2
color: Theme.surfaceVariant color: Theme.surfaceVariant
border.width: root.activeFocus ? 1 : 0 border.width: root.activeFocus ? 1 : 0
border.color: Theme.accent border.color: Theme.accent
Rectangle { Rectangle {
readonly property real knob: parent.height readonly property real knob: root.vertical ? parent.width : parent.height
width: Math.max(knob, knob + root.visualPosition * (parent.width - knob)) readonly property real length: Math.max(knob, knob + root.position * ((root.vertical ? parent.height : parent.width) - knob))
height: parent.height y: root.vertical ? parent.height - height : 0
radius: height / 2 width: root.vertical ? parent.width : length
height: root.vertical ? length : parent.height
radius: knob / 2
color: root.enabled ? Qt.alpha(Theme.text, 0.92) : Qt.alpha(Theme.text, 0.35) color: root.enabled ? Qt.alpha(Theme.text, 0.92) : Qt.alpha(Theme.text, 0.35)
Behavior on width { Behavior on width {
enabled: !root.pressed enabled: !root.pressed && !root.vertical
NumberAnimation {
duration: Theme.duration / 2
easing.type: Easing.OutCubic
}
}
Behavior on height {
enabled: !root.pressed && root.vertical
NumberAnimation { NumberAnimation {
duration: Theme.duration / 2 duration: Theme.duration / 2
easing.type: Easing.OutCubic easing.type: Easing.OutCubic
@@ -34,20 +44,21 @@ Slider {
} }
} }
Text { Text {
anchors.left: parent.left readonly property real knob: root.vertical ? parent.width : parent.height
anchors.leftMargin: (parent.height - width) / 2 x: root.vertical ? (parent.width - width) / 2 : (knob - width) / 2
anchors.verticalCenter: parent.verticalCenter y: root.vertical ? parent.height - knob / 2 - height / 2 : (parent.height - height) / 2
text: Icons.available && root.glyph ? root.glyph : root.fallback text: Icons.available && root.glyph ? root.glyph : root.fallback
font.family: Icons.available && root.glyph ? Icons.family : "" font.family: Icons.available && root.glyph ? Icons.family : ""
font.pixelSize: Math.round(parent.height * 0.5) font.pixelSize: Math.round(knob * 0.5)
color: Theme.surface color: Theme.surface
} }
} }
handle: Rectangle { handle: Rectangle {
x: root.leftPadding + root.visualPosition * (root.availableWidth - width) readonly property real knob: root.vertical ? root.availableWidth : root.availableHeight
y: root.topPadding + root.availableHeight / 2 - height / 2 x: root.leftPadding + (root.vertical ? 0 : root.visualPosition * (root.availableWidth - width))
width: root.availableHeight y: root.topPadding + (root.vertical ? root.visualPosition * (root.availableHeight - height) : root.availableHeight / 2 - height / 2)
height: root.availableHeight width: knob
height: knob
radius: width / 2 radius: width / 2
color: root.enabled ? Theme.text : Qt.alpha(Theme.text, 0.5) color: root.enabled ? Theme.text : Qt.alpha(Theme.text, 0.5)
border.width: 1 border.width: 1
+28 -1
View File
@@ -10,9 +10,36 @@ Singleton {
readonly property var source: backend.defaultAudioSource readonly property var source: backend.defaultAudioSource
readonly property var outputs: backend.nodes.values.filter(n => n.audio && n.isSink && !n.isStream) readonly property var outputs: backend.nodes.values.filter(n => n.audio && n.isSink && !n.isStream)
readonly property var inputs: backend.nodes.values.filter(n => n.audio && !n.isSink && !n.isStream) readonly property var inputs: backend.nodes.values.filter(n => n.audio && !n.isSink && !n.isStream)
// App playback streams, e.g. the players EasyEffects processes.
readonly property var streams: backend.nodes.values.filter(n => n.audio && n.isStream && !n.isSink)
readonly property bool available: backend.ready readonly property bool available: backend.ready
// Views listing streams hold a Demand on this, so their volumes are only
// tracked while shown.
property int streamConsumers: 0
PwObjectTracker { PwObjectTracker {
objects: root.backend === Pipewire ? [root.sink, root.source].filter(n => n !== null) : [] objects: root.backend === Pipewire ? [root.sink, root.source].filter(n => n !== null).concat(root.streamConsumers > 0 ? root.streams : []) : []
}
function streamName(node) {
const p = node && node.properties || {};
return p["application.name"] || node.description || p["media.name"] || node.name || "Unknown";
}
// Icon path: the stream's own icon name, else its app's desktop entry.
function streamIcon(node) {
const p = node && node.properties || {};
const named = p["application.icon-name"] ? Quickshell.iconPath(p["application.icon-name"], true) : "";
return named || ApplicationsService.icon(ApplicationsService.byId(p["application.process.binary"] || "") || ApplicationsService.byId(p["application.name"] || ""));
}
function streamVolume(node, value) {
if (!node || !node.audio || !Number.isFinite(value))
return false;
node.audio.volume = Math.max(0, Math.min(1, value));
return true;
}
function streamMute(node) {
if (!node || !node.audio)
return false;
node.audio.muted = !node.audio.muted;
return true;
} }
function volume(input, value) { function volume(input, value) {
const node = input ? source : sink; const node = input ? source : sink;
+37
View File
@@ -0,0 +1,37 @@
pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
// Keeps the session awake while on: holds a systemd idle and sleep inhibitor,
// which hypridle and logind both honour. Off again after a shell restart.
Singleton {
id: root
property bool active: false
property var command: ["systemd-inhibit", "--what=idle:sleep", "--who=glassMxrph", "--why=Caffeine", "--mode=block", "sleep", "infinity"]
readonly property bool running: inhibitor.running
function toggle() {
active = !active;
return true;
}
Process {
id: inhibitor
command: root.command
running: root.active
// The inhibitor exiting on its own (logind refused it) turns the tile off.
onRunningChanged: if (!running && root.active)
root.active = false
}
IpcHandler {
target: "caffeine"
function toggle(): bool {
return root.toggle();
}
function status(): string {
return JSON.stringify({
active: root.active,
running: inhibitor.running
});
}
}
}
+1
View File
@@ -19,3 +19,4 @@ singleton PluginService 1.0 PluginService.qml
singleton NotificationService 1.0 NotificationService.qml singleton NotificationService 1.0 NotificationService.qml
singleton ClipboardService 1.0 ClipboardService.qml singleton ClipboardService 1.0 ClipboardService.qml
singleton EmojiService 1.0 EmojiService.qml singleton EmojiService 1.0 EmojiService.qml
singleton CaffeineService 1.0 CaffeineService.qml