9#include <QGuiApplication>
10#include <QLoggingCategory>
11#include <QWaylandClientExtensionTemplate>
12#include <QtWaylandClientVersion>
14#include "qwayland-ext-idle-notify-v1.h"
15#include "qwayland-idle.h"
17Q_DECLARE_LOGGING_CATEGORY(POLLER)
18Q_LOGGING_CATEGORY(POLLER,
"kf5idletime_wayland")
30class IdleTimeout : public
QObject
34 IdleTimeout() =
default;
37 void resumeFromIdle();
40class IdleTimeoutKwin :
public IdleTimeout,
public QtWayland::org_kde_kwin_idle_timeout
44 IdleTimeoutKwin(struct ::org_kde_kwin_idle_timeout *
object)
46 , QtWayland::org_kde_kwin_idle_timeout(object)
57 void org_kde_kwin_idle_timeout_idle()
override {
60 void org_kde_kwin_idle_timeout_resumed()
override {
65class IdleTimeoutExt :
public IdleTimeout,
public QtWayland::ext_idle_notification_v1
69 IdleTimeoutExt(struct ::ext_idle_notification_v1 *
object)
71 , QtWayland::ext_idle_notification_v1(object)
83 void ext_idle_notification_v1_idled()
override
87 void ext_idle_notification_v1_resumed()
override
93class IdleManagerKwin :
public QWaylandClientExtensionTemplate<IdleManagerKwin>,
public QtWayland::org_kde_kwin_idle
97 : QWaylandClientExtensionTemplate<IdleManagerKwin>(1)
103class IdleManagerExt :
public QWaylandClientExtensionTemplate<IdleManagerExt>,
public QtWayland::ext_idle_notifier_v1
107 : QWaylandClientExtensionTemplate<IdleManagerExt>(1)
113 if (qGuiApp && isActive()) {
120 : KAbstractIdleTimePoller(parent)
121 , m_idleManagerKwin(new IdleManagerKwin)
122 , m_idleManagerExt(new IdleManagerExt)
126Poller::~Poller() =
default;
128bool Poller::isAvailable()
130 return m_idleManagerKwin->isActive() || m_idleManagerExt->isActive();
133void Poller::addTimeout(
int nextTimeout)
135 if (m_timeouts.
contains(nextTimeout)) {
139 auto timeout = createTimeout(nextTimeout);
144 connect(timeout, &IdleTimeout::idle,
this, [
this, nextTimeout] {
145 Q_EMIT timeoutReached(nextTimeout);
147 connect(timeout, &IdleTimeout::resumeFromIdle,
this, &Poller::resumingFromIdle);
151void Poller::removeTimeout(
int nextTimeout)
153 m_timeouts.
remove(nextTimeout);
161void Poller::catchIdleEvent()
163 if (m_catchResumeTimeout) {
167 if (!isAvailable()) {
171 m_catchResumeTimeout.
reset(createTimeout(0));
172 if (!m_catchResumeTimeout) {
175 connect(m_catchResumeTimeout.
get(), &IdleTimeout::resumeFromIdle,
this, [
this] {
176 stopCatchingIdleEvents();
177 Q_EMIT resumingFromIdle();
181void Poller::stopCatchingIdleEvents()
183 m_catchResumeTimeout.
reset();
186int Poller::forcePollRequest()
188 qCWarning(POLLER) <<
"This plugin does not support polling idle time";
192void Poller::simulateUserActivity()
196IdleTimeout* Poller::createTimeout(
int timeout)
202 auto seat = waylandApp->
seat();
208 if (m_idleManagerExt->isActive()) {
209 return new IdleTimeoutExt(m_idleManagerExt->get_idle_notification(timeout, seat));
211 if (m_idleManagerKwin->isActive()) {
212 return new IdleTimeoutKwin(m_idleManagerKwin->get_idle_timeout(seat, timeout));
217#include "moc_poller.cpp"
KCRASH_EXPORT void initialize()
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
bool remove(const Key &key)
virtual wl_seat * seat() const const=0
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)