b350f48e439ed89568f3b9ce97ba91d331527a61
[platform/core/uifw/libds.git] / src / DSWaylandServer / DSWaylandCompositor.h
1 /*
2 * Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #ifndef __DS_WAYLAND_COMPOSITOR_H__
25 #define __DS_WAYLAND_COMPOSITOR_H__
26
27 #include "DSCore.h"
28 #include "DSObject.h"
29 #include "DSSignal.h"
30 #include <mutex>
31
32 struct wl_display;
33
34 namespace display_server
35 {
36
37 class DSWaylandClient;
38 class DSWaylandSeat;
39 class DSWaylandSurface;
40 class IDSWaylandShell;
41 class DSWaylandRegion;
42
43 class DSWaylandCompositorPrivate;
44
45 class DS_DECL_EXPORT DSWaylandCompositor : public DSObject
46 {
47         DS_PIMPL_USE_PRIVATE(DSWaylandCompositor);
48 public:
49         static DSWaylandCompositor *getInstance();
50         static void releaseInstance();
51
52         bool create();
53         bool isCreated();
54
55         void addClient(DSWaylandClient *client);
56         void removeClient(DSWaylandClient *client);
57         DSWaylandSeat *addSeat(uint32_t cap);
58         void removeSeat(DSWaylandSeat *seat);
59
60         std::string socketName();
61         struct ::wl_display *display();
62         uint32_t nextSerial();
63         uint32_t currentTime();
64         std::list<DSWaylandClient *> clients();
65         DSWaylandSeat *defaultSeat();
66
67         bool setShell(IDSWaylandShell *shell);
68         IDSWaylandShell *getShell(void);
69
70         DSWaylandSurface *getSurface(uint32_t id);
71
72         void sendSurfaceDestroy(DSWaylandSurface *dswSurface);
73         void regionDestroy(DSWaylandRegion *dswRegion);
74
75         // Callback methods
76         void registerCallbackSurfaceCreated(DSObject *slot, std::function<void(std::shared_ptr<DSWaylandSurface>)> func);
77         void registerCallbackSurfaceDestroy(DSObject *slot, std::function<void(std::shared_ptr<DSWaylandSurface>)> func);
78
79 protected:
80         //TODO
81
82 private:
83         static std::mutex __mutex;
84         static DSWaylandCompositor *__comp;
85         static int __refCount;
86
87         DSWaylandCompositor() = delete;
88         ~DSWaylandCompositor();
89         DSWaylandCompositor(DSObject *parent);
90         DSWaylandCompositor& operator=(const DSWaylandCompositor&) = delete;
91
92         std::list<std::shared_ptr<DSWaylandSurface>> __surfaceList;
93         std::list<std::shared_ptr<DSWaylandRegion>> __regionList;
94
95         // signals
96         DSSignal<std::shared_ptr<DSWaylandSurface>> __surfaceCreatedSignal;
97         DSSignal<std::shared_ptr<DSWaylandSurface>> __surfaceDestroySignal;
98 };
99
100 }
101
102 #endif //__DS_WAYLAND_COMPOSITOR_H__