Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
SessionHost.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorServiceSession/phosphorservicesession_export.h>
7
8#include <QObject>
9#include <QString>
10
11#include <memory>
12
13class QDBusConnection;
14
15namespace PhosphorServiceSession {
16
35class PHOSPHORSERVICESESSION_EXPORT SessionHost : public QObject
36{
37 Q_OBJECT
38
39public:
41 enum class Availability {
42 Unknown,
43 Yes,
44 No,
45 NotApplicable,
46 Challenge,
47 };
48 Q_ENUM(Availability)
49
50 Q_PROPERTY(Availability canPowerOff READ canPowerOff NOTIFY capabilitiesChanged)
51 Q_PROPERTY(Availability canReboot READ canReboot NOTIFY capabilitiesChanged)
52 Q_PROPERTY(Availability canHalt READ canHalt NOTIFY capabilitiesChanged)
53 Q_PROPERTY(Availability canSuspend READ canSuspend NOTIFY capabilitiesChanged)
54 Q_PROPERTY(Availability canHibernate READ canHibernate NOTIFY capabilitiesChanged)
55 Q_PROPERTY(Availability canHybridSleep READ canHybridSleep NOTIFY capabilitiesChanged)
56 Q_PROPERTY(Availability canSuspendThenHibernate READ canSuspendThenHibernate NOTIFY capabilitiesChanged)
57
58
62 Q_PROPERTY(bool interactive READ interactive WRITE setInteractive NOTIFY interactiveChanged)
63
64
65 explicit SessionHost(QObject* parent = nullptr);
66
70 SessionHost(QDBusConnection connection, QString service, QObject* parent = nullptr);
71
72 ~SessionHost() override;
73
74 [[nodiscard]] Availability canPowerOff() const;
75 [[nodiscard]] Availability canReboot() const;
76 [[nodiscard]] Availability canHalt() const;
77 [[nodiscard]] Availability canSuspend() const;
78 [[nodiscard]] Availability canHibernate() const;
79 [[nodiscard]] Availability canHybridSleep() const;
81
85 Q_INVOKABLE void refreshCapabilities();
86
87 [[nodiscard]] bool interactive() const;
89
94 Q_INVOKABLE void lock();
95
99 Q_INVOKABLE void logout();
100 Q_INVOKABLE void terminateSession();
101
105 Q_INVOKABLE void suspend();
106 Q_INVOKABLE void hibernate();
107 Q_INVOKABLE void hybridSleep();
108 Q_INVOKABLE void suspendThenHibernate();
109 Q_INVOKABLE void reboot();
110 Q_INVOKABLE void powerOff();
111 Q_INVOKABLE void halt();
112
117 Q_INVOKABLE void allowSleep();
118
119Q_SIGNALS:
128
131 void prepareForSleep(bool beforeSleep);
132
136
142
143private Q_SLOTS:
144 // logind signal delivery points (QtDBus signal subscription needs
145 // string-named slots, so these are not lambdas).
146 void onPrepareForSleep(bool beforeSleep);
147 void onSessionLock();
148 void onSessionUnlock();
149
150private:
151 Q_DISABLE_COPY_MOVE(SessionHost)
152 class Private;
153 std::unique_ptr<Private> d;
154};
155
156} // namespace PhosphorServiceSession
void aboutToSleep()
Emitted on PrepareForSleep(true) while the delay inhibitor is held: the shell should lock now,...
void capabilitiesChanged()
Emitted whenever any capability value actually changes (each async Can* reply that differs from the c...
void lockRequested()
The logind session was asked to lock / unlock (e.g.
void prepareForSleep(bool beforeSleep)
Raw logind PrepareForSleep passthrough: beforeSleep is true just before the system sleeps and false j...
void logoutRequested()
Emitted by logout() so the shell / compositor can end the session gracefully (close clients,...
void setInteractive(bool interactive)
void lock()
Lock this session (resolved via XDG_SESSION_ID / GetSession, falling back to GetSessionByPID): logind...
Availability canHibernate() const
void allowSleep()
Drop the sleep delay-inhibitor so a pending suspend proceeds.
Availability canSuspendThenHibernate() const
void refreshCapabilities()
Re-read every capability from logind.
Availability canPowerOff() const
Availability canHybridSleep() const
void logout()
End this session.
Availability
logind capability state, parsed from the Can* query strings.
Definition SessionHost.h:41
void suspend()
Capability-gated power actions.
SessionHost(QObject *parent=nullptr)
Whether action calls pass logind interactive=true, routing an action that needs authorization to an i...
Definition QmlRegistration.h:8