File indexing completed on 2024-05-19 16:35:19

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