hooked up genivi::surface and layer
[staging/windowmanager.git] / src / wayland.cpp
1 #include "wayland.hpp"
2
3 //                                                                  _
4 //  _ __   __ _ _ __ ___   ___  ___ _ __   __ _  ___ ___  __      _| |
5 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / |
6 // | | | | (_| | | | | | |  __/\__ \ |_) | (_| | (_|  __/  \ V  V /| |
7 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|   \_/\_/ |_|
8 //                                 |_|
9 namespace wl {
10
11 //      _ _           _
12 //   __| (_)___ _ __ | | __ _ _   _
13 //  / _` | / __| '_ \| |/ _` | | | |
14 // | (_| | \__ \ |_) | | (_| | |_| |
15 //  \__,_|_|___/ .__/|_|\__,_|\__, |
16 //             |_|            |___/
17 display::display()
18    : d(std::unique_ptr<wl_display, void (*)(wl_display *)>(
19         wl_display_connect(NULL), wl_display_disconnect)),
20      r(std::make_unique<registry>(d.get())) {}
21
22 bool display::ok() const {
23    return d.get() != nullptr && wl_display_get_error(d.get()) == 0;
24 }
25
26 void display::roundtrip() { wl_display_roundtrip(this->d.get()); }
27
28 //                 _     _
29 //  _ __ ___  __ _(_)___| |_ _ __ _   _
30 // | '__/ _ \/ _` | / __| __| '__| | | |
31 // | | |  __/ (_| | \__ \ |_| |  | |_| |
32 // |_|  \___|\__, |_|___/\__|_|   \__, |
33 //           |___/                |___/
34 registry::registry(wl_display *d) : wayland_proxy(wl_display_get_registry(d)) {
35    wl_registry_add_listener(this->proxy, &listener, this);
36 }
37
38 registry::~registry() {
39    wl_registry_destroy(this->proxy);
40    this->proxy = nullptr;
41 }
42
43 void registry::add_global_handler(char const *iface, binder bind) {
44    this->bindings[iface] = bind;
45 }
46
47 void registry::event_global(uint32_t name, char const *iface, uint32_t v) {
48    auto b = this->bindings.find(iface);
49    if (b != this->bindings.end())
50       b->second(this->proxy, name, v);
51    else
52       logdebug("wl::registry @ %p global n %u i %s v %u", this->proxy, name,
53                iface, v);
54 }
55
56 void registry::event_global_remove(uint32_t name) {}
57
58 constexpr wl_registry_listener registry::listener;
59
60 void registry::s_global(void *data, struct wl_registry *r, uint32_t name,
61                         char const *iface, uint32_t v) {
62    static_cast<registry *>(data)->event_global(name, iface, v);
63 }
64
65 void registry::s_global_remove(void *data, struct wl_registry *r,
66                                uint32_t name) {
67    static_cast<registry *>(data)->event_global_remove(name);
68 }
69
70 //              _               _
71 //   ___  _   _| |_ _ __  _   _| |_
72 //  / _ \| | | | __| '_ \| | | | __|
73 // | (_) | |_| | |_| |_) | |_| | |_
74 //  \___/ \__,_|\__| .__/ \__,_|\__|
75 //                 |_|
76 output::output(wl_registry *r, uint32_t name, uint32_t v)
77    : wayland_proxy(wl_registry_bind(r, name, &wl_output_interface, v)) {
78    wl_output_add_listener(this->proxy, &listener, this);
79 }
80
81 void output::event_geometry(int32_t x, int32_t y, int32_t pw, int32_t ph,
82                             int32_t subpel, char const *make, char const *model,
83                             int32_t tx) {
84    logdebug(
85       "wl::output @ %p x %i y %i w %i h %i spel %x make %s model %s tx %i",
86       this->proxy, x, y, pw, ph, subpel, make, model, tx);
87 }
88
89 void output::event_mode(uint32_t flags, int32_t w, int32_t h, int32_t r) {
90    logdebug("wl::output @ %p mode f %x w %i h %i r %i", this->proxy, flags, w,
91             h, r);
92 }
93
94 void output::event_done() { logdebug("wl::output @ %p done", this->proxy); }
95
96 void output::event_scale(int32_t factor) {
97    logdebug("wl::output @ %p scale %i", this->proxy, factor);
98 }
99
100 void output::s_geometry(void *data, struct wl_output *wl_output, int32_t x,
101                         int32_t y, int32_t physical_width,
102                         int32_t physical_height, int32_t subpixel,
103                         const char *make, const char *model,
104                         int32_t transform) {
105    static_cast<output *>(data)->event_geometry(
106       x, y, physical_width, physical_height, subpixel, make, model, transform);
107 }
108
109 void output::s_mode(void *data, struct wl_output *wl_output, uint32_t flags,
110                     int32_t width, int32_t height, int32_t refresh) {
111    static_cast<output *>(data)->event_mode(flags, width, height, refresh);
112 }
113
114 void output::s_done(void *data, struct wl_output *wl_output) {
115    static_cast<output *>(data)->event_done();
116 }
117
118 void output::s_scale(void *data, struct wl_output *wl_output, int32_t factor) {
119    static_cast<output *>(data)->event_scale(factor);
120 }
121
122 constexpr wl_output_listener output::listener;
123 }
124
125 //  _ __   __ _ _ __ ___   ___  ___ _ __   __ _  ___ ___
126 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
127 // | | | | (_| | | | | | |  __/\__ \ |_) | (_| | (_|  __/
128 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
129 //                                 |_|
130 //                   _       _
131 //   __ _  ___ _ __ (_)_   _(_)
132 //  / _` |/ _ \ '_ \| \ \ / / |
133 // | (_| |  __/ | | | |\ V /| |
134 //  \__, |\___|_| |_|_| \_/ |_|
135 //  |___/
136 namespace genivi {
137
138 //                  _             _ _
139 //   ___ ___  _ __ | |_ _ __ ___ | | | ___ _ __
140 //  / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
141 // | (_| (_) | | | | |_| | | (_) | | |  __/ |
142 //  \___\___/|_| |_|\__|_|  \___/|_|_|\___|_|
143 //
144 controller::controller(wl_registry *r, uint32_t name, uint32_t version)
145    : wayland_proxy(
146         wl_registry_bind(r, name, &ivi_controller_interface, version)) {
147    ivi_controller_add_listener(this->proxy, &listener, this);
148 }
149
150 controller::~controller() {}
151
152 void controller::event_screen(uint32_t id,
153                               struct ivi_controller_screen *screen) {
154    logdebug("genivi::controller @ %p screen %u (%x) @ %p", this->proxy, id, id,
155             screen);
156    this->screens[id] = std::make_unique<struct screen>(id, screen);
157 }
158
159 void controller::event_layer(uint32_t id) {
160    logdebug("genivi::controller @ %p layer %u (%x)", this->proxy, id, id);
161    this->layers[id] = std::make_unique<layer>(id, this->proxy);
162 }
163
164 void controller::event_surface(uint32_t id) {
165    logdebug("genivi::controller @ %p surface %u (%x)", this->proxy, id, id);
166    this->surfaces[id] = std::make_unique<surface>(id, this->proxy);
167 }
168
169 void controller::event_error(int32_t object_id, int32_t object_type,
170                              int32_t error_code, const char *error_text) {
171    logdebug("genivi::controller @ %p error o %i t %i c %i text %s", this->proxy,
172             object_id, object_type, error_code, error_text);
173 }
174
175 void controller::s_screen(void *data, struct ivi_controller *ivi_controller,
176                           uint32_t id_screen,
177                           struct ivi_controller_screen *screen) {
178    static_cast<controller *>(data)->event_screen(id_screen, screen);
179 }
180
181 void controller::s_layer(void *data, struct ivi_controller *ivi_controller,
182                          uint32_t id_layer) {
183    static_cast<controller *>(data)->event_layer(id_layer);
184 }
185
186 void controller::s_surface(void *data, struct ivi_controller *ivi_controller,
187                            uint32_t id_surface) {
188    static_cast<controller *>(data)->event_surface(id_surface);
189 }
190
191 void controller::s_error(void *data, struct ivi_controller *ivi_controller,
192                          int32_t object_id, int32_t object_type,
193                          int32_t error_code, const char *error_text) {
194    static_cast<controller *>(data)->event_error(object_id, object_type,
195                                                 error_code, error_text);
196 }
197
198 constexpr ivi_controller_listener controller::listener;
199
200 //  _
201 // | | __ _ _   _  ___ _ __
202 // | |/ _` | | | |/ _ \ '__|
203 // | | (_| | |_| |  __/ |
204 // |_|\__,_|\__, |\___|_|
205 //          |___/
206 layer::layer(uint32_t i, ivi_controller *c)
207    : wayland_proxy(ivi_controller_layer_create(c, i, 0, 0)), id(i) {
208    ivi_controller_layer_add_listener(this->proxy, &listener, this);
209 }
210
211 layer::~layer() {
212    logdebug("%s layer %i @ %p", __func__, this->id, this->proxy);
213    ivi_controller_layer_destroy(this->proxy, 1);
214    this->proxy = nullptr;
215 }
216
217 void layer::event_visibility(int32_t visibility) {
218    logdebug("genivi::layer %s @ %p v %i", __func__, this->proxy, visibility);
219 }
220
221 void layer::event_opacity(wl_fixed_t opacity) {
222    logdebug("genivi::layer %s @ %p o %i", __func__, this->proxy, opacity);
223 }
224
225 void layer::event_source_rectangle(int32_t x, int32_t y, int32_t width,
226                                    int32_t height) {
227    logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
228             x, y, width, height);
229 }
230
231 void layer::event_destination_rectangle(int32_t x, int32_t y, int32_t width,
232                                         int32_t height) {
233    logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
234             x, y, width, height);
235 }
236
237 void layer::event_configuration(int32_t width, int32_t height) {
238    logdebug("genivi::layer %s @ %p w %i h %i", __func__, this->proxy, width,
239             height);
240 }
241
242 void layer::event_orientation(int32_t orientation) {
243    logdebug("genivi::layer %s @ %p o %i", __func__, this->proxy, orientation);
244 }
245
246 void layer::event_screen(struct wl_output *screen) {
247    logdebug("genivi::layer %s @ %p s %p", __func__, this->proxy, screen);
248 }
249
250 void layer::event_destroyed() {
251    logdebug("genivi::layer %s @ %p", __func__, this->proxy);
252 }
253
254 void layer::s_visibility(void *data,
255                          struct ivi_controller_layer *ivi_controller_layer,
256                          int32_t visibility) {
257    static_cast<layer *>(data)->event_visibility(visibility);
258 }
259
260 void layer::s_opacity(void *data,
261                       struct ivi_controller_layer *ivi_controller_layer,
262                       wl_fixed_t opacity) {
263    static_cast<layer *>(data)->event_opacity(opacity);
264 }
265
266 void layer::s_source_rectangle(
267    void *data, struct ivi_controller_layer *ivi_controller_layer, int32_t x,
268    int32_t y, int32_t width, int32_t height) {
269    static_cast<layer *>(data)->event_source_rectangle(x, y, width, height);
270 }
271
272 void layer::s_destination_rectangle(
273    void *data, struct ivi_controller_layer *ivi_controller_layer, int32_t x,
274    int32_t y, int32_t width, int32_t height) {
275    static_cast<layer *>(data)->event_destination_rectangle(x, y, width, height);
276 }
277
278 void layer::s_configuration(void *data,
279                             struct ivi_controller_layer *ivi_controller_layer,
280                             int32_t width, int32_t height) {
281    static_cast<layer *>(data)->event_configuration(width, height);
282 }
283
284 void layer::s_orientation(void *data,
285                           struct ivi_controller_layer *ivi_controller_layer,
286                           int32_t orientation) {
287    static_cast<layer *>(data)->event_orientation(orientation);
288 }
289
290 void layer::s_screen(void *data,
291                      struct ivi_controller_layer *ivi_controller_layer,
292                      struct wl_output *screen) {
293    static_cast<layer *>(data)->event_screen(screen);
294 }
295
296 void layer::s_destroyed(void *data,
297                         struct ivi_controller_layer *ivi_controller_layer) {
298    static_cast<layer *>(data)->event_destroyed();
299 }
300
301 constexpr ivi_controller_layer_listener layer::listener;
302
303 //                  __
304 //  ___ _   _ _ __ / _| __ _  ___ ___
305 // / __| | | | '__| |_ / _` |/ __/ _ \
306 // \__ \ |_| | |  |  _| (_| | (_|  __/
307 // |___/\__,_|_|  |_|  \__,_|\___\___|
308 //
309 surface::surface(uint32_t i, ivi_controller *c)
310    : wayland_proxy(ivi_controller_surface_create(c, i)), id(i) {
311    ivi_controller_surface_add_listener(this->proxy, &listener, this);
312 }
313
314 surface::~surface() {
315    logdebug("%s surface %i @ %p", __func__, this->id, this->proxy);
316    ivi_controller_surface_destroy(this->proxy, 1);
317    this->proxy = nullptr;
318 }
319
320 void surface::event_visibility(int32_t visibility) {
321    logdebug("genivi::surface %s @ %p v %i", __func__, this->proxy, visibility);
322 }
323
324 void surface::event_opacity(wl_fixed_t opacity) {
325    logdebug("genivi::surface %s @ %p o %i", __func__, this->proxy, opacity);
326 }
327
328 void surface::event_source_rectangle(int32_t x, int32_t y, int32_t width,
329                                      int32_t height) {
330    logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
331             this->proxy, x, y, width, height);
332 }
333
334 void surface::event_destination_rectangle(int32_t x, int32_t y, int32_t width,
335                                           int32_t height) {
336    logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
337             this->proxy, x, y, width, height);
338 }
339
340 void surface::event_configuration(int32_t width, int32_t height) {
341    logdebug("genivi::surface %s @ %p w %i h %i", __func__, this->proxy, width,
342             height);
343 }
344
345 void surface::event_orientation(int32_t orientation) {
346    logdebug("genivi::surface %s @ %p o %i", __func__, this->proxy, orientation);
347 }
348
349 void surface::event_pixelformat(int32_t pixelformat) {
350    logdebug("genivi::surface %s @ %p f %i", __func__, this->proxy, pixelformat);
351 }
352
353 void surface::event_layer(struct ivi_controller_layer *layer) {
354    logdebug("genivi::surface %s @ %p l @ %p", __func__, this->proxy, layer);
355 }
356
357 void surface::event_stats(uint32_t redraw_count, uint32_t frame_count,
358                           uint32_t update_count, uint32_t pid,
359                           const char *process_name) {
360    logdebug("genivi::surface %s @ %p r %u f %u u %u pid %u p %s", __func__,
361             this->proxy, redraw_count, frame_count, update_count, pid,
362             process_name);
363 }
364
365 void surface::event_destroyed() {
366    logdebug("genivi::surface %s @ %p", __func__, this->proxy);
367 }
368
369 void surface::event_content(int32_t content_state) {
370    logdebug("genivi::surface %s @ %p s %i", __func__, this->proxy,
371             content_state);
372 }
373
374 void surface::s_visibility(
375    void *data, struct ivi_controller_surface *ivi_controller_surface,
376    int32_t visibility) {
377    static_cast<surface *>(data)->event_visibility(visibility);
378 }
379
380 void surface::s_opacity(void *data,
381                         struct ivi_controller_surface *ivi_controller_surface,
382                         wl_fixed_t opacity) {
383    static_cast<surface *>(data)->event_opacity(opacity);
384 }
385
386 void surface::s_source_rectangle(
387    void *data, struct ivi_controller_surface *ivi_controller_surface, int32_t x,
388    int32_t y, int32_t width, int32_t height) {
389    static_cast<surface *>(data)->event_source_rectangle(x, y, width, height);
390 }
391
392 void surface::s_destination_rectangle(
393    void *data, struct ivi_controller_surface *ivi_controller_surface, int32_t x,
394    int32_t y, int32_t width, int32_t height) {
395    static_cast<surface *>(data)->event_destination_rectangle(x, y, width,
396                                                              height);
397 }
398
399 void surface::s_configuration(
400    void *data, struct ivi_controller_surface *ivi_controller_surface,
401    int32_t width, int32_t height) {
402    static_cast<surface *>(data)->event_configuration(width, height);
403 }
404
405 void surface::s_orientation(
406    void *data, struct ivi_controller_surface *ivi_controller_surface,
407    int32_t orientation) {
408    static_cast<surface *>(data)->event_orientation(orientation);
409 }
410
411 void surface::s_pixelformat(
412    void *data, struct ivi_controller_surface *ivi_controller_surface,
413    int32_t pixelformat) {
414    static_cast<surface *>(data)->event_pixelformat(pixelformat);
415 }
416
417 void surface::s_layer(void *data,
418                       struct ivi_controller_surface *ivi_controller_surface,
419                       struct ivi_controller_layer *layer) {
420    static_cast<surface *>(data)->event_layer(layer);
421 }
422
423 void surface::s_stats(void *data,
424                       struct ivi_controller_surface *ivi_controller_surface,
425                       uint32_t redraw_count, uint32_t frame_count,
426                       uint32_t update_count, uint32_t pid,
427                       const char *process_name) {
428    static_cast<surface *>(data)->event_stats(redraw_count, frame_count,
429                                              update_count, pid, process_name);
430 }
431
432 void surface::s_destroyed(
433    void *data, struct ivi_controller_surface *ivi_controller_surface) {
434    static_cast<surface *>(data)->event_destroyed();
435 }
436
437 void surface::s_content(void *data,
438                         struct ivi_controller_surface *ivi_controller_surface,
439                         int32_t content_state) {
440    static_cast<surface *>(data)->event_content(content_state);
441 }
442
443 constexpr ivi_controller_surface_listener surface::listener;
444
445 //
446 // ___  ___ _ __ ___  ___ _ __
447 /// __|/ __| '__/ _ \/ _ \ '_ \
448 //\__ \ (__| | |  __/  __/ | | |
449 //|___/\___|_|  \___|\___|_| |_|
450 //
451 screen::screen(uint32_t i, ivi_controller_screen *p)
452    : wayland_proxy(p), id(i) {}
453 }