1 /******************************************************************** 2 Copyright 2020 Faveraux Adrien <ad1rie3@hotmail.fr> 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) version 3, or any 8 later version accepted by the membership of KDE e.V. (or its 9 successor approved by the membership of KDE e.V.), which shall 10 act as a proxy defined in Section 6 of version 3 of the license. 11 12 This library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General Public 18 License along with this library. If not, see <http://www.gnu.org/licenses/>. 19 *********************************************************************/ 20 #pragma once 21 22 #include "kde_idle.h" 23 24 #include "wayland/global.h" 25 #include "wayland/resource.h" 26 27 #include <QTimer> 28 #include <vector> 29 30 #include <wayland-idle-server-protocol.h> 31 32 namespace Wrapland::Server 33 { 34 35 class Display; 36 class Seat; 37 class IdleTimeout; 38 39 constexpr uint32_t KdeIdleVersion = 1; 40 using KdeIdleGlobal = Wayland::Global<KdeIdle, KdeIdleVersion>; 41 using KdeIdleBind = Wayland::Bind<KdeIdleGlobal>; 42 43 class KdeIdle::Private : public KdeIdleGlobal 44 { 45 public: 46 Private(Display* display, KdeIdle* q); 47 ~Private() override; 48 int inhibitCount = 0; 49 std::vector<IdleTimeout*> idleTimeouts; 50 51 private: 52 static void 53 getIdleTimeoutCallback(KdeIdleBind* bind, uint32_t id, wl_resource* wlSeat, uint32_t timeout); 54 55 static const struct org_kde_kwin_idle_interface s_interface; 56 }; 57 58 class WRAPLANDSERVER_EXPORT IdleTimeout : public QObject 59 { 60 Q_OBJECT 61 public: 62 ~IdleTimeout() override; 63 64 Q_SIGNALS: 65 void resourceDestroyed(); 66 67 private: 68 explicit IdleTimeout(Client* client, 69 uint32_t version, 70 uint32_t id, 71 Seat* seat, 72 KdeIdle* parent); 73 friend class KdeIdle; 74 class Private; 75 Private* d_ptr; 76 }; 77 78 class IdleTimeout::Private : public Wayland::Resource<IdleTimeout> 79 { 80 public: 81 Private(Client* client, 82 uint32_t version, 83 uint32_t id, 84 Seat* seat, 85 KdeIdle* manager, 86 IdleTimeout* q); 87 88 ~Private() override; 89 void setup(uint32_t timeout); 90 91 void simulateUserActivity(); 92 93 Seat* seat; 94 KdeIdle* manager; 95 QTimer* timer = nullptr; 96 97 private: 98 static void simulateUserActivityCallback(wl_client* wlClient, wl_resource* wlResource); 99 static const struct org_kde_kwin_idle_timeout_interface s_interface; 100 }; 101 102 } 103