idle inhibitor: show blocking inhibitors in tooltip, poll only while hovered

This commit is contained in:
Damocles 2026-04-13 15:11:48 +02:00
parent 0b09f9ad62
commit 22ea9b0df1

View file

@ -1,23 +1,47 @@
import QtQuick import QtQuick
import Quickshell
import Quickshell.Io import Quickshell.Io
import "." as M import "." as M
M.BarIcon { M.BarIcon {
id: root id: root
color: root.active ? (parent?.accentColor ?? M.Theme.base05) : M.Theme.base04 color: root.active ? (parent?.accentColor ?? M.Theme.base05) : M.Theme.base04
tooltip: "Idle inhibition: " + (root.active ? "active" : "inactive") tooltip: {
const parts = ["Idle inhibition: " + (root.active ? "active" : "inactive")];
if (root._inhibitors)
parts.push(root._inhibitors);
return parts.join("\n");
}
property bool active: false property bool active: false
property string _inhibitors: ""
icon: root.active ? "\uF06E" : "\uF070" icon: root.active ? "\uF06E" : "\uF070"
// The inhibitor process stays running while active
Process { Process {
id: inhibitor id: inhibitor
command: ["systemd-inhibit", "--what=idle", "--who=nova-shell", "--why=user", "sleep", "infinity"] command: ["systemd-inhibit", "--what=idle", "--who=nova-shell", "--why=user", "sleep", "infinity"]
running: root.active running: root.active
} }
// Poll current inhibitors
Process {
id: listProc
running: true
command: ["sh", "-c", "systemd-inhibit --list 2>/dev/null | grep -i idle | awk '{print $NF}' | sort -u | tr '\\n' ', ' | sed 's/, $//'"]
stdout: StdioCollector {
onStreamFinished: root._inhibitors = text.trim() ? "Blocked by: " + text.trim() : ""
}
}
Timer {
interval: 5000
running: root._hovered
repeat: true
triggeredOnStart: true
onTriggered: listProc.running = true
}
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor