From dd2df931a3be1a6518c1e9fbff438de4274456cd Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 11 Sep 2025 22:52:35 +0200 Subject: ... --- .../shell/quickshell-plugins/Systemd.hpp | 129 +++++++++++++++++++++ 1 file changed, 129 insertions(+) (limited to 'accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp') diff --git a/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp b/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp index f8841518..cf978fea 100644 --- a/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp +++ b/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp @@ -1,14 +1,143 @@ #pragma once +#include +#include +#include + #include +#include #include +#include "dbus_systemd_manager.h" +#include "dbus_logind_manager.h" +#include "dbus_logind_session.h" +#include "dbus_properties.h" + class Systemd : public QObject { Q_OBJECT; QML_SINGLETON; QML_ELEMENT; public: + explicit Systemd(QObject* parent = nullptr); + + Q_PROPERTY(bool idleHint READ idleHint WRITE setIdleHint NOTIFY idleHintChanged) + Q_PROPERTY(bool lockedHint READ lockedHint WRITE setLockedHint NOTIFY lockedHintChanged) + Q_INVOKABLE void stopUserUnit(const QString& unit, const QString& mode); Q_INVOKABLE void setBrightness(const QString& subsystem, const QString& name, quint32 brightness); + Q_INVOKABLE void setIdleHint(bool idle); + Q_INVOKABLE void setLockedHint(bool locked); + + bool idleHint(); + bool lockedHint(); + +signals: + void shutdown(bool before); + void sleep(bool before); + void lock(); + void unlock(); + void idleHintChanged(); + void lockedHintChanged(); + +private slots: + void onLogindSessionPropertiesChanged(const QString& interface_name, const QVariantMap& changed_properties, const QStringList& invalidated_properties); + +private: + DBusSystemdManager* systemdManager; + DBusLogindManager* logindManager; + DBusLogindSession* logindSession; + DBusProperties* logindSessionProperties; +}; + +class SystemdInhibitorParams : public QObject { + Q_OBJECT; + QML_ELEMENT; + QML_SINGLETON; + +public: + enum WhatItem : uint8_t { + Shutdown = 0b1, + Sleep = 0b10, + Idle = 0b100, + HandlePowerKey = 0b1000, + HandleSuspendKey = 0b10000, + HandleHibernateKey = 0b100000, + HandleLidSwitch = 0b1000000, + }; + Q_ENUM(WhatItem); + Q_DECLARE_FLAGS(What, WhatItem); + + enum Mode : uint8_t { + Block = 1, + BlockWeak = 2, + Delay = 3, + }; + Q_ENUM(Mode); + + Q_INVOKABLE static std::string toString(WhatItem what); + Q_INVOKABLE static std::string toString(What what); + Q_INVOKABLE static std::string toString(Mode mode); + + static constexpr WhatItem allWhatItems[] = { Shutdown, Sleep, Idle, HandlePowerKey, HandleSuspendKey, HandleHibernateKey, HandleLidSwitch }; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(SystemdInhibitorParams::What) + +class SystemdInhibitor : public QObject { + Q_OBJECT; + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged); + Q_PROPERTY(SystemdInhibitorParams::What what READ what WRITE setWhat NOTIFY whatChanged); + Q_PROPERTY(QString who READ who WRITE setWho NOTIFY whoChanged); + Q_PROPERTY(QString why READ why WRITE setWhy NOTIFY whyChanged); + Q_PROPERTY(SystemdInhibitorParams::Mode mode READ mode WRITE setMode NOTIFY modeChanged); + QML_ELEMENT; + +public: + explicit SystemdInhibitor(QObject* parent = nullptr): QObject(parent) {} + + bool enabled() const; + void setEnabled(bool enabled); + + SystemdInhibitorParams::What what() const; + void setWhat(SystemdInhibitorParams::What what); + + QString who() const; + void setWho(QString who); + + QString why() const; + void setWhy(QString why); + + SystemdInhibitorParams::Mode mode() const; + void setMode(SystemdInhibitorParams::Mode mode); + + Q_INVOKABLE void release(); + +signals: + void enabledChanged(); + void whatChanged(); + void whoChanged(); + void whyChanged(); + void modeChanged(); + +private: + class ActiveSystemdInhibitor { + public: + uint32_t fd = -1; + SystemdInhibitorParams::What what; + QString who; + QString why; + SystemdInhibitorParams::Mode mode; + + ActiveSystemdInhibitor(SystemdInhibitorParams::What what_, QString who_, QString why_, SystemdInhibitorParams::Mode mode_); + ~ActiveSystemdInhibitor(); + }; + + void update(); + + std::unique_ptr activeInhibitor; + SystemdInhibitorParams::What mWhat = static_cast(0); + QString mWho; + QString mWhy; + SystemdInhibitorParams::Mode mMode = static_cast(0); +}; + -- cgit v1.2.3