From d3717cae4b1b3a7645c205ce5aa07b9f3dc130e3 Mon Sep 17 00:00:00 2001 From: Nydragon Date: Sat, 21 Sep 2024 19:33:02 +0200 Subject: [PATCH] feat: declare inhibitor process as singleton to synchronize multi display bars --- src/provider/Inhibitor.qml | 17 +++++++++++++++++ src/widgets/caffeine/Caffeine.qml | 16 ++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 src/provider/Inhibitor.qml diff --git a/src/provider/Inhibitor.qml b/src/provider/Inhibitor.qml new file mode 100644 index 0000000..ff9be38 --- /dev/null +++ b/src/provider/Inhibitor.qml @@ -0,0 +1,17 @@ +pragma Singleton + +import Quickshell.Io +import Quickshell + +Singleton { + id: inhibitor + property var toggle: () => { + active = !active; + } + property bool active: false + + Process { + running: inhibitor.active + command: ["systemd-inhibit", "sleep", "infinity"] + } +} diff --git a/src/widgets/caffeine/Caffeine.qml b/src/widgets/caffeine/Caffeine.qml index 497c3ee..cd104cb 100644 --- a/src/widgets/caffeine/Caffeine.qml +++ b/src/widgets/caffeine/Caffeine.qml @@ -1,12 +1,12 @@ import "root:base" +import "root:provider" + import QtQuick -import Quickshell.Io import Quickshell.Widgets import Quickshell BRectangle { id: caffeine - property bool inhibiting: false MouseArea { anchors.fill: parent @@ -14,17 +14,9 @@ BRectangle { IconImage { anchors.fill: parent anchors.margins: 4 - source: caffeine.inhibiting ? "root:assets/eye-open.svg" : "root:assets/eye-closed.svg" + source: Inhibitor.active ? "root:assets/eye-open.svg" : "root:assets/eye-closed.svg" } - onClicked: () => { - caffeine.inhibiting = !caffeine.inhibiting; - } - - Process { - id: inhibitor - running: caffeine.inhibiting - command: ["systemd-inhibit", "sleep", "infinity"] - } + onClicked: () => Inhibitor.toggle() } }