removed all notifier remnants
[staging/windowmanager.git] / src / wayland.hpp
1 #ifndef WM_WAYLAND_HPP
2 #define WM_WAYLAND_HPP
3
4 #include "ivi-controller-client-protocol.h"
5
6 #include "util.h"
7
8 #include <functional>
9 #include <map>
10 #include <memory>
11 #include <vector>
12
13 //                      _                 _
14 // __      ____ _ _   _| | __ _ _ __   __| |     _ __  _ __ _____  ___   _
15 // \ \ /\ / / _` | | | | |/ _` | '_ \ / _` |    | '_ \| '__/ _ \ \/ / | | |
16 //  \ V  V / (_| | |_| | | (_| | | | | (_| |    | |_) | | | (_) >  <| |_| |
17 //   \_/\_/ \__,_|\__, |_|\__,_|_| |_|\__,_|____| .__/|_|  \___/_/\_\\__, |
18 //                |___/                   |_____|_|                  |___/
19 template <typename ProxyT>
20 struct wayland_proxy {
21    ProxyT *proxy;
22
23    wayland_proxy(void *p) : proxy(static_cast<ProxyT *>(p)) {}
24
25    virtual ~wayland_proxy() {
26       // If this is the nullptr, then it means it already was destroyed by a
27       // custom wayland dtor
28       if (this->proxy) {
29          logdebug("%s %p @ %p", __func__, this, this->proxy);
30          wl_proxy_destroy(reinterpret_cast<struct wl_proxy *>(proxy));
31       }
32    }
33 };
34
35 //                                                                  _
36 //  _ __   __ _ _ __ ___   ___  ___ _ __   __ _  ___ ___  __      _| |
37 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / |
38 // | | | | (_| | | | | | |  __/\__ \ |_) | (_| | (_|  __/  \ V  V /| |
39 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|   \_/\_/ |_|
40 //                                 |_|
41 namespace wl {
42 struct registry;
43
44 //      _ _           _
45 //   __| (_)___ _ __ | | __ _ _   _
46 //  / _` | / __| '_ \| |/ _` | | | |
47 // | (_| | \__ \ |_) | | (_| | |_| |
48 //  \__,_|_|___/ .__/|_|\__,_|\__, |
49 //             |_|            |___/
50 struct display {
51    std::unique_ptr<struct wl_display, std::function<void(struct wl_display *)>>
52       d;
53    std::unique_ptr<struct registry> r;
54
55    display();
56    ~display();
57    bool ok() const;
58    void roundtrip();
59    int dispatch();
60 };
61
62 //                 _     _
63 //  _ __ ___  __ _(_)___| |_ _ __ _   _
64 // | '__/ _ \/ _` | / __| __| '__| | | |
65 // | | |  __/ (_| | \__ \ |_| |  | |_| |
66 // |_|  \___|\__, |_|___/\__|_|   \__, |
67 //           |___/                |___/
68 struct registry : public wayland_proxy<struct wl_registry> {
69    typedef std::function<void(struct wl_registry *, uint32_t, uint32_t)> binder;
70    std::map<std::string, binder> bindings;
71
72    registry(struct wl_display *d);
73    ~registry();
74
75    void add_global_handler(char const *iface, binder bind);
76
77    // Events
78    void global(uint32_t name, char const *iface, uint32_t v);
79    void global_remove(uint32_t name);
80 };
81
82 //              _               _
83 //   ___  _   _| |_ _ __  _   _| |_
84 //  / _ \| | | | __| '_ \| | | | __|
85 // | (_) | |_| | |_| |_) | |_| | |_
86 //  \___/ \__,_|\__| .__/ \__,_|\__|
87 //                 |_|
88 struct output : wayland_proxy<struct wl_output> {
89    output(struct wl_registry *registry, uint32_t name, uint32_t version);
90
91    // Events
92    void geometry(int32_t x, int32_t y, int32_t pw, int32_t ph, int32_t subpel,
93                  char const *make, char const *model, int32_t tx);
94    void mode(uint32_t flags, int32_t w, int32_t h, int32_t r);
95    void done();
96    void scale(int32_t factor);
97 };
98 }
99
100 //  _ __   __ _ _ __ ___   ___  ___ _ __   __ _  ___ ___
101 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
102 // | | | | (_| | | | | | |  __/\__ \ |_) | (_| | (_|  __/
103 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
104 //                                 |_|
105 //                   _       _
106 //   __ _  ___ _ __ (_)_   _(_)
107 //  / _` |/ _ \ '_ \| \ \ / / |
108 // | (_| |  __/ | | | |\ V /| |
109 //  \__, |\___|_| |_|_| \_/ |_|
110 //  |___/
111 namespace genivi {
112
113 struct controller;
114
115 struct controlled_entity {
116    struct controller *parent;
117    uint32_t id;
118
119    controlled_entity(struct controller *c, uint32_t i) : parent(c), id(i) {}
120    virtual ~controlled_entity() {}
121 };
122
123 //                  __
124 //  ___ _   _ _ __ / _| __ _  ___ ___
125 // / __| | | | '__| |_ / _` |/ __/ _ \
126 // \__ \ |_| | |  |  _| (_| | (_|  __/
127 // |___/\__,_|_|  |_|  \__,_|\___\___|
128 //
129 struct surface : public wayland_proxy<struct ivi_controller_surface>,
130                  controlled_entity {
131    surface(uint32_t i, struct controller *c);
132    ~surface() override;
133
134    // Requests
135    inline void set_visibility(uint32_t visibility) {
136       ivi_controller_surface_set_visibility(this->proxy, visibility);
137    }
138
139    inline void set_opacity(wl_fixed_t opacity) {
140       ivi_controller_surface_set_opacity(this->proxy, opacity);
141    }
142
143    inline void set_source_rectangle(int32_t x, int32_t y, int32_t width,
144                                     int32_t height) {
145       ivi_controller_surface_set_source_rectangle(this->proxy, x, y, width,
146                                                   height);
147    }
148
149    inline void set_destination_rectangle(int32_t x, int32_t y, int32_t width,
150                                          int32_t height) {
151       ivi_controller_surface_set_destination_rectangle(this->proxy, x, y, width,
152                                                        height);
153    }
154
155    inline void set_configuration(int32_t width, int32_t height) {
156       ivi_controller_surface_set_configuration(this->proxy, width, height);
157    }
158
159    inline void set_orientation(int32_t orientation) {
160       ivi_controller_surface_set_orientation(this->proxy, orientation);
161    }
162
163    inline void screenshot(const char *filename) {
164       ivi_controller_surface_screenshot(this->proxy, filename);
165    }
166
167    inline void send_stats() { ivi_controller_surface_send_stats(this->proxy); }
168
169    inline void destroy(int32_t destroy_scene_object) {
170       ivi_controller_surface_destroy(this->proxy, destroy_scene_object);
171    }
172 };
173
174 //  _
175 // | | __ _ _   _  ___ _ __
176 // | |/ _` | | | |/ _ \ '__|
177 // | | (_| | |_| |  __/ |
178 // |_|\__,_|\__, |\___|_|
179 //          |___/
180 struct layer : public wayland_proxy<struct ivi_controller_layer>,
181                controlled_entity {
182    layer(uint32_t i, struct controller *c);
183    ~layer() override;
184
185    // Requests
186    inline void set_visibility(uint32_t visibility) {
187       ivi_controller_layer_set_visibility(this->proxy, visibility);
188    }
189
190    inline void set_opacity(wl_fixed_t opacity) {
191       ivi_controller_layer_set_opacity(this->proxy, opacity);
192    }
193
194    inline void set_source_rectangle(int32_t x, int32_t y, int32_t width,
195                                     int32_t height) {
196       ivi_controller_layer_set_source_rectangle(this->proxy, x, y, width,
197                                                 height);
198    }
199
200    inline void set_destination_rectangle(int32_t x, int32_t y, int32_t width,
201                                          int32_t height) {
202       ivi_controller_layer_set_destination_rectangle(this->proxy, x, y, width,
203                                                      height);
204    }
205
206    inline void set_configuration(int32_t width, int32_t height) {
207       ivi_controller_layer_set_configuration(this->proxy, width, height);
208    }
209
210    inline void set_orientation(int32_t orientation) {
211       ivi_controller_layer_set_orientation(this->proxy, orientation);
212    }
213
214    inline void screenshot(const char *filename) {
215       ivi_controller_layer_screenshot(this->proxy, filename);
216    }
217
218    inline void clear_surfaces() {
219       ivi_controller_layer_clear_surfaces(this->proxy);
220    }
221
222    inline void add_surface(struct surface *surface) {
223       ivi_controller_layer_add_surface(this->proxy, surface->proxy);
224    }
225
226    inline void remove_surface(struct surface *surface) {
227       ivi_controller_layer_remove_surface(this->proxy, surface->proxy);
228    }
229
230    inline void set_render_order(struct wl_array *surfaces) {
231       ivi_controller_layer_set_render_order(this->proxy, surfaces);
232    }
233 };
234
235 //
236 //  ___  ___ _ __ ___  ___ _ __
237 // / __|/ __| '__/ _ \/ _ \ '_ \
238 // \__ \ (__| | |  __/  __/ | | |
239 // |___/\___|_|  \___|\___|_| |_|
240 //
241 struct screen : public wayland_proxy<struct ivi_controller_screen>,
242                 controlled_entity {
243    screen(uint32_t i, struct controller *c, struct ivi_controller_screen *p);
244 };
245
246 //                  _             _ _
247 //   ___ ___  _ __ | |_ _ __ ___ | | | ___ _ __
248 //  / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
249 // | (_| (_) | | | | |_| | | (_) | | |  __/ |
250 //  \___\___/|_| |_|\__|_|  \___/|_|_|\___|_|
251 //
252 struct controller : public wayland_proxy<struct ivi_controller> {
253    std::map<uint32_t, std::unique_ptr<struct surface>> surfaces;
254    std::map<uint32_t, std::unique_ptr<struct layer>> layers;
255    std::map<uint32_t, std::unique_ptr<struct screen>> screens;
256
257    controller(struct wl_registry *r, uint32_t name, uint32_t version);
258    ~controller() override;
259
260    // Events
261    // controller
262    void screen(uint32_t id, struct ivi_controller_screen *screen);
263    void layer(uint32_t id);
264    void surface(uint32_t id);
265    void error(int32_t oid, int32_t otype, int32_t code, char const *text);
266
267    // surface
268    void surface_visibility(uint32_t id, int32_t visibility);
269    void surface_opacity(uint32_t id, float opacity);
270    void surface_source_rectangle(uint32_t id, int32_t x, int32_t y,
271                                  int32_t width, int32_t height);
272    void surface_destination_rectangle(uint32_t id, int32_t x, int32_t y,
273                                       int32_t width, int32_t height);
274    void surface_configuration(uint32_t id, int32_t width, int32_t height);
275    void surface_orientation(uint32_t id, int32_t orientation);
276    void surface_pixelformat(uint32_t id, int32_t pixelformat);
277    void surface_layer(uint32_t id, struct ivi_controller_layer *layer);
278    void surface_stats(uint32_t id, uint32_t redraw_count, uint32_t frame_count,
279                       uint32_t update_count, uint32_t pid,
280                       const char *process_name);
281    void surface_destroyed(uint32_t id);
282    void surface_content(uint32_t id, int32_t content_state);
283
284    // layer
285    void layer_visibility(uint32_t id, int32_t visibility);
286    void layer_opacity(uint32_t id, float opacity);
287    void layer_source_rectangle(uint32_t id, int32_t x, int32_t y, int32_t width,
288                                int32_t height);
289    void layer_destination_rectangle(uint32_t id, int32_t x, int32_t y,
290                                     int32_t width, int32_t height);
291    void layer_configuration(uint32_t id, int32_t width, int32_t height);
292    void layer_orientation(uint32_t id, int32_t orientation);
293    void layer_screen(uint32_t id, struct wl_output *screen);
294    void layer_destroyed(uint32_t id);
295 };
296 }
297
298 #endif  // !WM_WAYLAND_HPP