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"
// 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 {
id: root
property string glyph
property string fallback
implicitWidth: 220
implicitHeight: 28
implicitWidth: vertical ? 28 : 220
implicitHeight: vertical ? 220 : 28
padding: 0
background: Rectangle {
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
height: root.availableHeight
radius: height / 2
radius: Math.min(width, height) / 2
color: Theme.surfaceVariant
border.width: root.activeFocus ? 1 : 0
border.color: Theme.accent
Rectangle {
readonly property real knob: parent.height
width: Math.max(knob, knob + root.visualPosition * (parent.width - knob))
height: parent.height
radius: height / 2
readonly property real knob: root.vertical ? parent.width : parent.height
readonly property real length: Math.max(knob, knob + root.position * ((root.vertical ? parent.height : parent.width) - knob))
y: root.vertical ? parent.height - height : 0
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)
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 {
duration: Theme.duration / 2
easing.type: Easing.OutCubic
@@ -34,20 +44,21 @@ Slider {
}
}
Text {
anchors.left: parent.left
anchors.leftMargin: (parent.height - width) / 2
anchors.verticalCenter: parent.verticalCenter
readonly property real knob: root.vertical ? parent.width : parent.height
x: root.vertical ? (parent.width - width) / 2 : (knob - width) / 2
y: root.vertical ? parent.height - knob / 2 - height / 2 : (parent.height - height) / 2
text: Icons.available && root.glyph ? root.glyph : root.fallback
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
}
}
handle: Rectangle {
x: root.leftPadding + root.visualPosition * (root.availableWidth - width)
y: root.topPadding + root.availableHeight / 2 - height / 2
width: root.availableHeight
height: root.availableHeight
readonly property real knob: root.vertical ? root.availableWidth : root.availableHeight
x: root.leftPadding + (root.vertical ? 0 : root.visualPosition * (root.availableWidth - width))
y: root.topPadding + (root.vertical ? root.visualPosition * (root.availableHeight - height) : root.availableHeight / 2 - height / 2)
width: knob
height: knob
radius: width / 2
color: root.enabled ? Theme.text : Qt.alpha(Theme.text, 0.5)
border.width: 1
+28 -1
View File
@@ -10,9 +10,36 @@ Singleton {
readonly property var source: backend.defaultAudioSource
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)
// 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
// Views listing streams hold a Demand on this, so their volumes are only
// tracked while shown.
property int streamConsumers: 0
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) {
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 ClipboardService 1.0 ClipboardService.qml
singleton EmojiService 1.0 EmojiService.qml
singleton CaffeineService 1.0 CaffeineService.qml