|  | 
|  | 1 | +#pragma once | 
|  | 2 | + | 
|  | 3 | +#include <qobject.h> | 
|  | 4 | +#include <qproperty.h> | 
|  | 5 | +#include <qqmlintegration.h> | 
|  | 6 | +#include <qtclasshelpermacros.h> | 
|  | 7 | +#include <qtmetamacros.h> | 
|  | 8 | +#include <qtypes.h> | 
|  | 9 | + | 
|  | 10 | +#include "../../core/reload.hpp" | 
|  | 11 | +#include "proto.hpp" | 
|  | 12 | + | 
|  | 13 | +namespace qs::wayland::idle_notify { | 
|  | 14 | + | 
|  | 15 | +///! Provides a notification when a wayland session is makred idle | 
|  | 16 | +/// An idle monitor detects when the user stops providing input for a period of time. | 
|  | 17 | +/// | 
|  | 18 | +/// > [!NOTE] Using an idle monitor requires the compositor support the [ext-idle-notify-v1] protocol. | 
|  | 19 | +/// | 
|  | 20 | +/// [ext-idle-notify-v1]: https://wayland.app/protocols/ext-idle-notify-v1 | 
|  | 21 | +class IdleMonitor: public PostReloadHook { | 
|  | 22 | +	Q_OBJECT; | 
|  | 23 | +	QML_ELEMENT; | 
|  | 24 | +	// clang-format off | 
|  | 25 | +	/// If the idle monitor should be enabled. Defaults to true. | 
|  | 26 | +	Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged); | 
|  | 27 | +	/// The amount of time in seconds the idle monitor should wait before reporting an idle state. | 
|  | 28 | +	/// | 
|  | 29 | +	/// Defaults to zero, which reports idle status immediately. | 
|  | 30 | +	Q_PROPERTY(qreal timeout READ default WRITE default NOTIFY timeoutChanged BINDABLE bindableTimeout); | 
|  | 31 | +	/// When set to true, @@isIdle will depend on both user interaction and active idle inhibitors. | 
|  | 32 | +	/// When false, the value will depend solely on user interaction. Defaults to true. | 
|  | 33 | +	Q_PROPERTY(bool respectInhibitors READ default WRITE default NOTIFY respectInhibitorsChanged BINDABLE bindableRespectInhibitors); | 
|  | 34 | +	/// This property is true if the user has been idle for at least @@timeout. | 
|  | 35 | +	/// What is considered to be idle is influenced by @@respectInhibitors. | 
|  | 36 | +	Q_PROPERTY(bool isIdle READ default NOTIFY isIdleChanged BINDABLE bindableIsIdle); | 
|  | 37 | +	// clang-format on | 
|  | 38 | + | 
|  | 39 | +public: | 
|  | 40 | +	IdleMonitor() = default; | 
|  | 41 | +	~IdleMonitor() override; | 
|  | 42 | +	Q_DISABLE_COPY_MOVE(IdleMonitor); | 
|  | 43 | + | 
|  | 44 | +	void onPostReload() override; | 
|  | 45 | + | 
|  | 46 | +	[[nodiscard]] bool isEnabled() const { return this->bNotification.value(); } | 
|  | 47 | +	void setEnabled(bool enabled) { this->bEnabled = enabled; } | 
|  | 48 | + | 
|  | 49 | +	[[nodiscard]] QBindable<qreal> bindableTimeout() { return &this->bTimeout; } | 
|  | 50 | +	[[nodiscard]] QBindable<bool> bindableRespectInhibitors() { return &this->bRespectInhibitors; } | 
|  | 51 | +	[[nodiscard]] QBindable<bool> bindableIsIdle() const { return &this->bIsIdle; } | 
|  | 52 | + | 
|  | 53 | +signals: | 
|  | 54 | +	void enabledChanged(); | 
|  | 55 | +	void timeoutChanged(); | 
|  | 56 | +	void respectInhibitorsChanged(); | 
|  | 57 | +	void isIdleChanged(); | 
|  | 58 | + | 
|  | 59 | +private: | 
|  | 60 | +	void updateNotification(); | 
|  | 61 | + | 
|  | 62 | +	struct Params { | 
|  | 63 | +		bool enabled; | 
|  | 64 | +		qreal timeout; | 
|  | 65 | +		bool respectInhibitors; | 
|  | 66 | +	}; | 
|  | 67 | + | 
|  | 68 | +	// clang-format off | 
|  | 69 | +	Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(IdleMonitor, bool, bEnabled, true, &IdleMonitor::enabledChanged); | 
|  | 70 | +	Q_OBJECT_BINDABLE_PROPERTY(IdleMonitor, qreal, bTimeout, &IdleMonitor::timeoutChanged); | 
|  | 71 | +	Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(IdleMonitor, bool, bRespectInhibitors, true, &IdleMonitor::respectInhibitorsChanged); | 
|  | 72 | +	Q_OBJECT_BINDABLE_PROPERTY(IdleMonitor, Params, bParams, &IdleMonitor::updateNotification); | 
|  | 73 | +	Q_OBJECT_BINDABLE_PROPERTY(IdleMonitor, impl::IdleNotification*, bNotification); | 
|  | 74 | +	Q_OBJECT_BINDABLE_PROPERTY(IdleMonitor, bool, bIsIdle, &IdleMonitor::isIdleChanged); | 
|  | 75 | +	// clang-format on | 
|  | 76 | +}; | 
|  | 77 | + | 
|  | 78 | +} // namespace qs::wayland::idle_notify | 
0 commit comments