summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp')
-rw-r--r--accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp131
1 files changed, 131 insertions, 0 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp b/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp
index 883a96f3..84752d76 100644
--- a/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp
+++ b/accounts/gkleen@sif/shell/quickshell-plugins/Systemd.hpp
@@ -1,13 +1,144 @@
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
6class Systemd : public QObject { 16class Systemd : public QObject {
7 Q_OBJECT; 17 Q_OBJECT;
8 QML_SINGLETON; 18 QML_SINGLETON;
9 QML_ELEMENT; 19 QML_ELEMENT;
10 20
11public: 21public:
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);
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
35signals:
36 void shutdown(bool before);
37 void sleep(bool before);
38 void lock();
39 void unlock();
40 void idleHintChanged();
41 void lockedHintChanged();
42
43private slots:
44 void onLogindSessionPropertiesChanged(const QString& interface_name, const QVariantMap& changed_properties, const QStringList& invalidated_properties);
45
46private:
47 DBusSystemdManager* systemdManager;
48 DBusLogindManager* logindManager;
49 DBusLogindSession* logindSession;
50 DBusProperties* logindSessionProperties;
51};
52
53class SystemdInhibitorParams : public QObject {
54 Q_OBJECT;
55 QML_ELEMENT;
56 QML_SINGLETON;
57
58public:
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 };
13}; 83};
84Q_DECLARE_OPERATORS_FOR_FLAGS(SystemdInhibitorParams::What)
85
86class 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
95public:
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
115signals:
116 void enabledChanged();
117 void whatChanged();
118 void whoChanged();
119 void whyChanged();
120 void modeChanged();
121
122private:
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 bool mEnabled = true;
138 std::unique_ptr<ActiveSystemdInhibitor> activeInhibitor;
139 SystemdInhibitorParams::What mWhat = static_cast<SystemdInhibitorParams::What>(0);
140 QString mWho;
141 QString mWhy;
142 SystemdInhibitorParams::Mode mMode = static_cast<SystemdInhibitorParams::Mode>(0);
143};
144