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 <QObject>
23 
24 #include <QDebug>
25 
26 #include <Wrapland/Server/wraplandserver_export.h>
27 
28 #include <cstdint>
29 #include <memory>
30 #include <string>
31 
32 struct wl_client;
33 struct wl_display;
34 
35 namespace Wrapland::Server
36 {
37 
38 class Client;
39 class Private;
40 
41 class DataDeviceManager;
42 class DpmsManager;
43 class drm_lease_device_v1;
44 class WlOutput;
45 class OutputConfigurationV1;
46 class OutputDeviceV1;
47 class OutputManagementV1;
48 class PlasmaVirtualDesktopManager;
49 class PlasmaWindowManager;
50 class PresentationManager;
51 class Seat;
52 class XdgShell;
53 
54 class Compositor;
55 class KdeIdle;
56 class IdleInhibitManagerV1;
57 class input_method_manager_v2;
58 class FakeInput;
59 class LayerShellV1;
60 class PlasmaShell;
61 class ShadowManager;
62 class BlurManager;
63 class ContrastManager;
64 class SlideManager;
65 class Subcompositor;
66 class TextInputManagerV2;
67 class text_input_manager_v3;
68 class RelativePointerManagerV1;
69 class PointerGesturesV1;
70 class PointerConstraintsV1;
71 class PrimarySelectionDeviceManager;
72 class XdgForeign;
73 class AppmenuManager;
74 class ServerSideDecorationPaletteManager;
75 class Viewporter;
76 class XdgOutputManager;
77 class XdgDecorationManager;
78 class EglStreamController;
79 class KeyState;
80 class LinuxDmabufV1;
81 class KeyboardShortcutsInhibitManagerV1;
82 class XdgActivationV1;
83 
84 class WRAPLANDSERVER_EXPORT Display : public QObject
85 {
86     Q_OBJECT
87 public:
88     explicit Display(QObject* parent = nullptr);
89 
90     ~Display() override;
91 
92     void setSocketName(const std::string& name);
93     std::string socketName() const;
94 
95     uint32_t serial();
96     uint32_t nextSerial();
97 
98     enum class StartMode {
99         ConnectToSocket,
100         ConnectClientsOnly,
101     };
102 
103     void start(StartMode mode = StartMode::ConnectToSocket);
104     void terminate();
105 
106     void startLoop();
107 
108     void dispatchEvents(int msecTimeout = -1);
109 
110     wl_display* native() const;
111     bool running() const;
112 
113     void add_wl_output(WlOutput* output);
114     void removeOutput(WlOutput* output);
115     std::vector<WlOutput*>& outputs() const;
116 
117     Seat* createSeat(QObject* parent = nullptr);
118     std::vector<Seat*>& seats() const;
119 
120     void setSocketName(const QString& name);
121     void add_socket_fd(int fd);
122 
123     void add_output_device_v1(OutputDeviceV1* output);
124     void removeOutputDevice(OutputDeviceV1* outputDevice);
125     std::vector<OutputDeviceV1*> outputDevices() const;
126 
127     Compositor* createCompositor(QObject* parent = nullptr);
128     void createShm();
129 
130     Subcompositor* createSubCompositor(QObject* parent = nullptr);
131     DataDeviceManager* createDataDeviceManager(QObject* parent = nullptr);
132     OutputManagementV1* createOutputManagementV1(QObject* parent = nullptr);
133     PlasmaShell* createPlasmaShell(QObject* parent = nullptr);
134     PlasmaWindowManager* createPlasmaWindowManager(QObject* parent = nullptr);
135     PrimarySelectionDeviceManager* createPrimarySelectionDeviceManager(QObject* parent = nullptr);
136     KdeIdle* createIdle(QObject* parent = nullptr);
137     FakeInput* createFakeInput(QObject* parent = nullptr);
138     LayerShellV1* createLayerShellV1(QObject* parent = nullptr);
139     ShadowManager* createShadowManager(QObject* parent = nullptr);
140     BlurManager* createBlurManager(QObject* parent = nullptr);
141     SlideManager* createSlideManager(QObject* parent = nullptr);
142     ContrastManager* createContrastManager(QObject* parent = nullptr);
143     DpmsManager* createDpmsManager(QObject* parent = nullptr);
144     drm_lease_device_v1* createDrmLeaseDeviceV1(QObject* parent = nullptr);
145 
146     KeyState* createKeyState(QObject* parent = nullptr);
147     PresentationManager* createPresentationManager(QObject* parent = nullptr);
148 
149     TextInputManagerV2* createTextInputManagerV2(QObject* parent = nullptr);
150     text_input_manager_v3* createTextInputManagerV3(QObject* parent = nullptr);
151     input_method_manager_v2* createInputMethodManagerV2(QObject* parent = nullptr);
152 
153     XdgShell* createXdgShell(QObject* parent = nullptr);
154 
155     RelativePointerManagerV1* createRelativePointerManager(QObject* parent = nullptr);
156     PointerGesturesV1* createPointerGestures(QObject* parent = nullptr);
157     PointerConstraintsV1* createPointerConstraints(QObject* parent = nullptr);
158 
159     XdgForeign* createXdgForeign(QObject* parent = nullptr);
160 
161     IdleInhibitManagerV1* createIdleInhibitManager(QObject* parent = nullptr);
162     KeyboardShortcutsInhibitManagerV1* createKeyboardShortcutsInhibitManager(QObject* parent
163                                                                              = nullptr);
164     AppmenuManager* createAppmenuManager(QObject* parent = nullptr);
165 
166     ServerSideDecorationPaletteManager* createServerSideDecorationPaletteManager(QObject* parent
167                                                                                  = nullptr);
168     LinuxDmabufV1* createLinuxDmabuf(QObject* parent = nullptr);
169     Viewporter* createViewporter(QObject* parent = nullptr);
170     XdgOutputManager* xdgOutputManager() const;
171 
172     PlasmaVirtualDesktopManager* createPlasmaVirtualDesktopManager(QObject* parent = nullptr);
173     XdgActivationV1* createXdgActivationV1(QObject* parent = nullptr);
174     XdgDecorationManager* createXdgDecorationManager(XdgShell* shell, QObject* parent = nullptr);
175     EglStreamController* createEglStreamController(QObject* parent = nullptr);
176 
177     void dispatch();
178     void flush();
179 
180     Client* createClient(int fd);
181     Client* getClient(wl_client* client);
182     std::vector<Client*> clients() const;
183 
184     void setEglDisplay(void* display);
185 
186     void* eglDisplay() const;
187 
188 Q_SIGNALS:
189     void started();
190     void clientConnected(Wrapland::Server::Client*);
191     void clientDisconnected(Wrapland::Server::Client*);
192 
193 private:
194     friend class Private;
195     std::unique_ptr<Private> d_ptr;
196 };
197 
198 }
199 
200 Q_DECLARE_METATYPE(std::string)
201 Q_DECLARE_METATYPE(uint32_t)
202