diff options
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp')
| -rw-r--r-- | accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp | 129 |
1 files changed, 129 insertions, 0 deletions
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 @@ | |||
| 1 | #pragma once | 1 | #pragma once |
| 2 | 2 | ||
| 3 | #include <cstdint> | ||
| 4 | #include <memory> | ||
| 5 | #include <string> | ||
| 6 | |||
| 3 | #include <QObject> | 7 | #include <QObject> |
| 8 | #include <QDBusInterface> | ||
| 4 | #include <QtQmlIntegration/qqmlintegration.h> | 9 | #include <QtQmlIntegration/qqmlintegration.h> |
| 5 | 10 | ||
| 11 | #include "dbus_systemd_manager.h" | ||
| 12 | #include "dbus_logind_manager.h" | ||
| 13 | #include "dbus_logind_session.h" | ||
| 14 | #include "dbus_properties.h" | ||
| 15 | |||
| 6 | class Systemd : public QObject { | 16 | class Systemd : public QObject { |
| 7 | Q_OBJECT; | 17 | Q_OBJECT; |
| 8 | QML_SINGLETON; | 18 | QML_SINGLETON; |
| 9 | QML_ELEMENT; | 19 | QML_ELEMENT; |
| 10 | 20 | ||
| 11 | public: | 21 | public: |
| 22 | explicit Systemd(QObject* parent = nullptr); | ||
| 23 | |||
| 24 | Q_PROPERTY(bool idleHint READ idleHint WRITE setIdleHint NOTIFY idleHintChanged) | ||
| 25 | Q_PROPERTY(bool lockedHint READ lockedHint WRITE setLockedHint NOTIFY lockedHintChanged) | ||
| 26 | |||
| 12 | Q_INVOKABLE void stopUserUnit(const QString& unit, const QString& mode); | 27 | Q_INVOKABLE void stopUserUnit(const QString& unit, const QString& mode); |
| 13 | Q_INVOKABLE void setBrightness(const QString& subsystem, const QString& name, quint32 brightness); | 28 | Q_INVOKABLE void setBrightness(const QString& subsystem, const QString& name, quint32 brightness); |
| 29 | Q_INVOKABLE void setIdleHint(bool idle); | ||
| 30 | Q_INVOKABLE void setLockedHint(bool locked); | ||
| 31 | |||
| 32 | bool idleHint(); | ||
| 33 | bool lockedHint(); | ||
| 34 | |||
| 35 | signals: | ||
| 36 | void shutdown(bool before); | ||
| 37 | void sleep(bool before); | ||
| 38 | void lock(); | ||
| 39 | void unlock(); | ||
| 40 | void idleHintChanged(); | ||
| 41 | void lockedHintChanged(); | ||
| 42 | |||
| 43 | private slots: | ||
| 44 | void onLogindSessionPropertiesChanged(const QString& interface_name, const QVariantMap& changed_properties, const QStringList& invalidated_properties); | ||
| 45 | |||
| 46 | private: | ||
| 47 | DBusSystemdManager* systemdManager; | ||
| 48 | DBusLogindManager* logindManager; | ||
| 49 | DBusLogindSession* logindSession; | ||
| 50 | DBusProperties* logindSessionProperties; | ||
| 51 | }; | ||
| 52 | |||
| 53 | class SystemdInhibitorParams : public QObject { | ||
| 54 | Q_OBJECT; | ||
| 55 | QML_ELEMENT; | ||
| 56 | QML_SINGLETON; | ||
| 57 | |||
| 58 | public: | ||
| 59 | enum WhatItem : uint8_t { | ||
| 60 | Shutdown = 0b1, | ||
| 61 | Sleep = 0b10, | ||
| 62 | Idle = 0b100, | ||
| 63 | HandlePowerKey = 0b1000, | ||
| 64 | HandleSuspendKey = 0b10000, | ||
| 65 | HandleHibernateKey = 0b100000, | ||
| 66 | HandleLidSwitch = 0b1000000, | ||
| 67 | }; | ||
| 68 | Q_ENUM(WhatItem); | ||
| 69 | Q_DECLARE_FLAGS(What, WhatItem); | ||
| 70 | |||
| 71 | enum Mode : uint8_t { | ||
| 72 | Block = 1, | ||
| 73 | BlockWeak = 2, | ||
| 74 | Delay = 3, | ||
| 75 | }; | ||
| 76 | Q_ENUM(Mode); | ||
| 77 | |||
| 78 | Q_INVOKABLE static std::string toString(WhatItem what); | ||
| 79 | Q_INVOKABLE static std::string toString(What what); | ||
| 80 | Q_INVOKABLE static std::string toString(Mode mode); | ||
| 81 | |||
| 82 | static constexpr WhatItem allWhatItems[] = { Shutdown, Sleep, Idle, HandlePowerKey, HandleSuspendKey, HandleHibernateKey, HandleLidSwitch }; | ||
| 14 | }; | 83 | }; |
| 84 | Q_DECLARE_OPERATORS_FOR_FLAGS(SystemdInhibitorParams::What) | ||
| 85 | |||
| 86 | class SystemdInhibitor : public QObject { | ||
| 87 | Q_OBJECT; | ||
| 88 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged); | ||
| 89 | Q_PROPERTY(SystemdInhibitorParams::What what READ what WRITE setWhat NOTIFY whatChanged); | ||
| 90 | Q_PROPERTY(QString who READ who WRITE setWho NOTIFY whoChanged); | ||
| 91 | Q_PROPERTY(QString why READ why WRITE setWhy NOTIFY whyChanged); | ||
| 92 | Q_PROPERTY(SystemdInhibitorParams::Mode mode READ mode WRITE setMode NOTIFY modeChanged); | ||
| 93 | QML_ELEMENT; | ||
| 94 | |||
| 95 | public: | ||
| 96 | explicit SystemdInhibitor(QObject* parent = nullptr): QObject(parent) {} | ||
| 97 | |||
| 98 | bool enabled() const; | ||
| 99 | void setEnabled(bool enabled); | ||
| 100 | |||
| 101 | SystemdInhibitorParams::What what() const; | ||
| 102 | void setWhat(SystemdInhibitorParams::What what); | ||
| 103 | |||
| 104 | QString who() const; | ||
| 105 | void setWho(QString who); | ||
| 106 | |||
| 107 | QString why() const; | ||
| 108 | void setWhy(QString why); | ||
| 109 | |||
| 110 | SystemdInhibitorParams::Mode mode() const; | ||
| 111 | void setMode(SystemdInhibitorParams::Mode mode); | ||
| 112 | |||
| 113 | Q_INVOKABLE void release(); | ||
| 114 | |||
| 115 | signals: | ||
| 116 | void enabledChanged(); | ||
| 117 | void whatChanged(); | ||
| 118 | void whoChanged(); | ||
| 119 | void whyChanged(); | ||
| 120 | void modeChanged(); | ||
| 121 | |||
| 122 | private: | ||
| 123 | class ActiveSystemdInhibitor { | ||
| 124 | public: | ||
| 125 | uint32_t fd = -1; | ||
| 126 | SystemdInhibitorParams::What what; | ||
| 127 | QString who; | ||
| 128 | QString why; | ||
| 129 | SystemdInhibitorParams::Mode mode; | ||
| 130 | |||
| 131 | ActiveSystemdInhibitor(SystemdInhibitorParams::What what_, QString who_, QString why_, SystemdInhibitorParams::Mode mode_); | ||
| 132 | ~ActiveSystemdInhibitor(); | ||
| 133 | }; | ||
| 134 | |||
| 135 | void update(); | ||
| 136 | |||
| 137 | std::unique_ptr<ActiveSystemdInhibitor> activeInhibitor; | ||
| 138 | SystemdInhibitorParams::What mWhat = static_cast<SystemdInhibitorParams::What>(0); | ||
| 139 | QString mWho; | ||
| 140 | QString mWhy; | ||
| 141 | SystemdInhibitorParams::Mode mMode = static_cast<SystemdInhibitorParams::Mode>(0); | ||
| 142 | }; | ||
| 143 | |||
