1 /********************************************************************
2 Copyright © 2020 Roman Gilg <subdiff@gmail.com>
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 "dpms.h"
23 #include "wayland/global.h"
24 #include "wayland/resource.h"
25 
26 #include <wayland-dpms-server-protocol.h>
27 
28 namespace Wrapland
29 {
30 namespace Server
31 {
32 
33 class WlOutput;
34 
35 constexpr uint32_t DpmsManagerVersion = 1;
36 using DpmsManagerGlobal = Wayland::Global<DpmsManager, DpmsManagerVersion>;
37 using DpmsManagerBind = Wayland::Bind<DpmsManagerGlobal>;
38 
39 class DpmsManager::Private : public Wayland::Global<DpmsManager>
40 {
41 public:
42     Private(Display* display, DpmsManager* q);
43 
44 private:
45     static void getDpmsCallback(DpmsManagerBind* bind, uint32_t id, wl_resource* output);
46 
47     static const struct org_kde_kwin_dpms_manager_interface s_interface;
48 };
49 
50 using Sender = std::function<void(wl_resource*)>;
51 
52 class Dpms : public QObject
53 {
54     Q_OBJECT
55 public:
56     Dpms(Client* client, uint32_t version, uint32_t id, WlOutput* output);
57 
58     void sendSupported();
59     void sendMode();
60     void sendDone();
61 
62 Q_SIGNALS:
63     void resourceDestroyed();
64 
65 private:
66     class Private;
67     Private* d_ptr;
68 };
69 
70 class Dpms::Private : public Wayland::Resource<Dpms>
71 {
72 public:
73     Private(Client* client, uint32_t version, uint32_t id, WlOutput* output, Dpms* q);
74 
75     WlOutput* output;
76 
77 private:
78     static void setCallback(wl_client* client, wl_resource* wlResource, uint32_t mode);
79     static const struct org_kde_kwin_dpms_interface s_interface;
80 };
81 
82 }
83 }
84