File indexing completed on 2024-11-10 04:57:27

0001 /*
0002     SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "idlenotify_v1.h"
0008 #include "display.h"
0009 
0010 #include "idledetector.h"
0011 
0012 #include "qwayland-server-ext-idle-notify-v1.h"
0013 
0014 namespace KWin
0015 {
0016 
0017 static const quint32 s_version = 1;
0018 
0019 class IdleNotifyV1InterfacePrivate : public QtWaylandServer::ext_idle_notifier_v1
0020 {
0021 public:
0022     IdleNotifyV1InterfacePrivate(Display *display);
0023 
0024 protected:
0025     void ext_idle_notifier_v1_destroy(Resource *resource) override;
0026     void ext_idle_notifier_v1_get_idle_notification(Resource *resource, uint32_t id, uint32_t timeout, struct ::wl_resource *seat) override;
0027 };
0028 
0029 class IdleNotificationV1Interface : public QObject, public QtWaylandServer::ext_idle_notification_v1
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     IdleNotificationV1Interface(wl_client *client, int version, uint32_t id, std::chrono::milliseconds timeout);
0035 
0036 protected:
0037     void ext_idle_notification_v1_destroy_resource(Resource *resource) override;
0038     void ext_idle_notification_v1_destroy(Resource *resource) override;
0039 };
0040 
0041 IdleNotifyV1InterfacePrivate::IdleNotifyV1InterfacePrivate(Display *display)
0042     : QtWaylandServer::ext_idle_notifier_v1(*display, s_version)
0043 {
0044 }
0045 
0046 void IdleNotifyV1InterfacePrivate::ext_idle_notifier_v1_destroy(Resource *resource)
0047 {
0048     wl_resource_destroy(resource->handle);
0049 }
0050 
0051 void IdleNotifyV1InterfacePrivate::ext_idle_notifier_v1_get_idle_notification(Resource *resource, uint32_t id, uint32_t timeout, struct ::wl_resource *seat)
0052 {
0053     new IdleNotificationV1Interface(resource->client(), resource->version(), id, std::chrono::milliseconds(timeout));
0054 }
0055 
0056 IdleNotificationV1Interface::IdleNotificationV1Interface(wl_client *client, int version, uint32_t id, std::chrono::milliseconds timeout)
0057     : QtWaylandServer::ext_idle_notification_v1(client, id, version)
0058 {
0059     auto detector = new IdleDetector(timeout, this);
0060     connect(detector, &IdleDetector::idle, this, [this]() {
0061         send_idled();
0062     });
0063     connect(detector, &IdleDetector::resumed, this, [this]() {
0064         send_resumed();
0065     });
0066 }
0067 
0068 void IdleNotificationV1Interface::ext_idle_notification_v1_destroy_resource(Resource *resource)
0069 {
0070     delete this;
0071 }
0072 
0073 void IdleNotificationV1Interface::ext_idle_notification_v1_destroy(Resource *resource)
0074 {
0075     wl_resource_destroy(resource->handle);
0076 }
0077 
0078 IdleNotifyV1Interface::IdleNotifyV1Interface(Display *display, QObject *parent)
0079     : QObject(parent)
0080     , d(new IdleNotifyV1InterfacePrivate(display))
0081 {
0082 }
0083 
0084 IdleNotifyV1Interface::~IdleNotifyV1Interface()
0085 {
0086 }
0087 
0088 }
0089 
0090 #include "idlenotify_v1.moc"
0091 
0092 #include "moc_idlenotify_v1.cpp"