From 564853110a6e1367cc379bd8418d874829302d00 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 11 Sep 2025 23:17:57 +0200 Subject: ... --- .../shell/quickshell-plugins/Systemd.cpp | 4 +- .../shell/quickshell-plugins/Systemd.hpp | 1 + accounts/gkleen@sif/shell/quickshell/Bar.qml | 7 +++ .../shell/quickshell/LidSwitchInhibitorWidget.qml | 46 ++++++++++++++++++ .../shell/quickshell/Services/InhibitorState.qml | 22 +++++++++ .../shell/quickshell/WaylandInhibitorWidget.qml | 55 ++++++++++++++++++++++ accounts/gkleen@sif/shell/quickshell/shell.qml | 1 + 7 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 accounts/gkleen@sif/shell/quickshell/LidSwitchInhibitorWidget.qml create mode 100644 accounts/gkleen@sif/shell/quickshell/Services/InhibitorState.qml create mode 100644 accounts/gkleen@sif/shell/quickshell/WaylandInhibitorWidget.qml (limited to 'accounts') diff --git a/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.cpp b/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.cpp index 790f514f..884ea17f 100644 --- a/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.cpp +++ b/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.cpp @@ -118,6 +118,8 @@ std::string SystemdInhibitorParams::toString(SystemdInhibitorParams::Mode mode) bool SystemdInhibitor::enabled() const { return static_cast(this->activeInhibitor); } void SystemdInhibitor::setEnabled(bool enabled) { + this->mEnabled = enabled; + if (enabled) this->update(); else @@ -173,7 +175,7 @@ void SystemdInhibitor::release() { } void SystemdInhibitor::update() { - if (!this->mWhat || this->mWho.isEmpty() || this->mWhy.isEmpty() || !this->mMode) + if (!this->mWhat || this->mWho.isEmpty() || this->mWhy.isEmpty() || !this->mMode || !this->mEnabled) if (this->activeInhibitor) this->release(); else diff --git a/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp b/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp index cf978fea..84752d76 100644 --- a/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp +++ b/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp @@ -134,6 +134,7 @@ private: void update(); + bool mEnabled = true; std::unique_ptr activeInhibitor; SystemdInhibitorParams::What mWhat = static_cast(0); QString mWho; diff --git a/accounts/gkleen@sif/shell/quickshell/Bar.qml b/accounts/gkleen@sif/shell/quickshell/Bar.qml index 52b9b344..6952c658 100644 --- a/accounts/gkleen@sif/shell/quickshell/Bar.qml +++ b/accounts/gkleen@sif/shell/quickshell/Bar.qml @@ -5,6 +5,7 @@ PanelWindow { id: bar required property var screen + required property var inhibitorState anchors { top: true @@ -83,6 +84,12 @@ PanelWindow { KeyboardLayout {} + LidSwitchInhibitorWidget {} + + WaylandInhibitorWidget { + window: bar + } + Item { height: parent.height width: 8 - 4 diff --git a/accounts/gkleen@sif/shell/quickshell/LidSwitchInhibitorWidget.qml b/accounts/gkleen@sif/shell/quickshell/LidSwitchInhibitorWidget.qml new file mode 100644 index 00000000..2be0692a --- /dev/null +++ b/accounts/gkleen@sif/shell/quickshell/LidSwitchInhibitorWidget.qml @@ -0,0 +1,46 @@ +import Quickshell +import QtQuick +import Quickshell.Widgets +import qs.Services + +Item { + id: root + + width: icon.width + 8 + height: parent.height + anchors.verticalCenter: parent.verticalCenter + + WrapperMouseArea { + id: widgetMouseArea + + anchors.fill: parent + + hoverEnabled: true + + onClicked: InhibitorState.lidSwitchInhibited = !InhibitorState.lidSwitchInhibited + + Rectangle { + anchors.fill: parent + color: { + if (widgetMouseArea.containsMouse) { + return "#33808080"; + } + return "transparent"; + } + + Item { + anchors.fill: parent + + MaterialDesignIcon { + id: icon + + implicitSize: 14 + anchors.centerIn: parent + + icon: InhibitorState.lidSwitchInhibited ? "laptop-off" : "laptop" + color: InhibitorState.lidSwitchInhibited ? "#f28a21" : "#555" + } + } + } + } +} diff --git a/accounts/gkleen@sif/shell/quickshell/Services/InhibitorState.qml b/accounts/gkleen@sif/shell/quickshell/Services/InhibitorState.qml new file mode 100644 index 00000000..fe48fd7f --- /dev/null +++ b/accounts/gkleen@sif/shell/quickshell/Services/InhibitorState.qml @@ -0,0 +1,22 @@ +pragma Singleton + +import Quickshell +import Custom as Custom + +Singleton { + id: inhibitorState + + property bool waylandIdleInhibited: false + property alias lidSwitchInhibited: lidSwitchInhibitor.enabled + + Custom.SystemdInhibitor { + id: lidSwitchInhibitor + + enabled: false + + what: Custom.SystemdInhibitorParams.HandleLidSwitch + who: "quickshell" + why: "User request" + mode: Custom.SystemdInhibitorParams.BlockWeak + } +} diff --git a/accounts/gkleen@sif/shell/quickshell/WaylandInhibitorWidget.qml b/accounts/gkleen@sif/shell/quickshell/WaylandInhibitorWidget.qml new file mode 100644 index 00000000..0633f350 --- /dev/null +++ b/accounts/gkleen@sif/shell/quickshell/WaylandInhibitorWidget.qml @@ -0,0 +1,55 @@ +import Quickshell +import QtQuick +import Quickshell.Widgets +import Quickshell.Wayland +import qs.Services + +Item { + id: root + + required property var window + + width: icon.width + 8 + height: parent.height + anchors.verticalCenter: parent.verticalCenter + + IdleInhibitor { + id: inhibitor + enabled: InhibitorState.waylandIdleInhibited + window: root.window + } + + WrapperMouseArea { + id: widgetMouseArea + + anchors.fill: parent + + hoverEnabled: true + + onClicked: InhibitorState.waylandIdleInhibited = !InhibitorState.waylandIdleInhibited + + Rectangle { + anchors.fill: parent + color: { + if (widgetMouseArea.containsMouse) { + return "#33808080"; + } + return "transparent"; + } + + Item { + anchors.fill: parent + + MaterialDesignIcon { + id: icon + + implicitSize: 14 + anchors.centerIn: parent + + icon: inhibitor.enabled ? "eye" : "eye-off" + color: inhibitor.enabled ? "white" : "#555" + } + } + } + } +} diff --git a/accounts/gkleen@sif/shell/quickshell/shell.qml b/accounts/gkleen@sif/shell/quickshell/shell.qml index 693d741f..ccb4e82e 100644 --- a/accounts/gkleen@sif/shell/quickshell/shell.qml +++ b/accounts/gkleen@sif/shell/quickshell/shell.qml @@ -36,6 +36,7 @@ ShellRoot { Bar { screen: screenScope.modelData + inhibitorState: inhibitorState } } } -- cgit v1.2.3