Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
IdleService.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 <PhosphorServiceIdle/phosphorserviceidle_export.h>
7
8#include <QObject>
9#include <QString>
10#include <QLatin1String>
11#include <QVariantList>
12
13#include <memory>
14
16
24namespace StageKey {
25inline constexpr QLatin1String Name("name");
26inline constexpr QLatin1String TimeoutMs("timeoutMs");
27} // namespace StageKey
28
50class PHOSPHORSERVICEIDLE_EXPORT IdleService : public QObject
51{
52 Q_OBJECT
53 Q_PROPERTY(bool supported READ isSupported CONSTANT)
54 Q_PROPERTY(QVariantList stages READ stages WRITE setStages NOTIFY stagesChanged)
55 Q_PROPERTY(int currentStage READ currentStage NOTIFY currentStageChanged)
56 Q_PROPERTY(QString currentStageName READ currentStageName NOTIFY currentStageChanged)
57 Q_PROPERTY(bool idle READ isIdle NOTIFY currentStageChanged)
58 Q_PROPERTY(bool inhibited READ isInhibited NOTIFY inhibitedChanged)
59
60public:
61 explicit IdleService(QObject* parent = nullptr);
62 ~IdleService() override;
63
66 [[nodiscard]] bool isSupported() const;
67
75 [[nodiscard]] QVariantList stages() const;
88 void setStages(const QVariantList& stages);
89
100 [[nodiscard]] bool isArmed() const;
101
104 [[nodiscard]] int currentStage() const;
106 [[nodiscard]] QString currentStageName() const;
107 [[nodiscard]] bool isIdle() const;
108
109 [[nodiscard]] bool isInhibited() const;
110
115 [[nodiscard]] Q_INVOKABLE int inhibit();
118 Q_INVOKABLE bool release(int cookie);
119
120Q_SIGNALS:
124 void idled(int stage);
126 void resumed();
128
129private:
130 Q_DISABLE_COPY_MOVE(IdleService)
131
132 class Private;
133 std::unique_ptr<Private> d;
134};
135
136} // namespace PhosphorServiceIdle
QVariantList stages() const
The idle ladder, as a list of { name: string, timeoutMs: int } maps, sorted by ascending timeout.
bool isSupported() const
Whether the compositor advertises the idle-notification protocol this service builds on.
int inhibit()
Acquire an idle inhibition.
bool release(int cookie)
Release a previously acquired inhibition.
bool isArmed() const
Did the current ladder actually ARM?
void setStages(const QVariantList &stages)
Reconfiguring the ladder to a DIFFERENT one resets the session to active.
QString currentStageName() const
Name of the current stage, or an empty string when active.
void resumed()
Returned to active from any idle stage.
int currentStage() const
0 when active; otherwise the 1-based index of the deepest stage currently reached.
void idled(int stage)
Entered idle stage stage (1-based).
IdleService(QObject *parent=nullptr)
Field names of one entry in the idle ladder passed to IdleService::setStages.
Definition IdleService.h:24
constexpr QLatin1String Name("name")
constexpr QLatin1String TimeoutMs("timeoutMs")
Definition IdleService.h:15