4 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ __ _| |
5 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / |
6 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ \ V V /| |
7 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| \_/\_/ |_|
12 // __| (_)___ _ __ | | __ _ _ _
13 // / _` | / __| '_ \| |/ _` | | | |
14 // | (_| | \__ \ |_) | | (_| | |_| |
15 // \__,_|_|___/ .__/|_|\__,_|\__, |
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())) {}
22 bool display::ok() const {
23 return d.get() != nullptr && wl_display_get_error(d.get()) == 0;
26 void display::roundtrip() { wl_display_roundtrip(this->d.get()); }
29 // _ __ ___ __ _(_)___| |_ _ __ _ _
30 // | '__/ _ \/ _` | / __| __| '__| | | |
31 // | | | __/ (_| | \__ \ |_| | | |_| |
32 // |_| \___|\__, |_|___/\__|_| \__, |
34 registry::registry(wl_display *d) : wayland_proxy(wl_display_get_registry(d)) {
35 wl_registry_add_listener(this->proxy, &listener, this);
38 registry::~registry() {
39 wl_registry_destroy(this->proxy);
40 this->proxy = nullptr;
43 void registry::add_global_handler(char const *iface, binder bind) {
44 this->bindings[iface] = bind;
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);
52 logdebug("wl::registry @ %p global n %u i %s v %u", this->proxy, name,
56 void registry::event_global_remove(uint32_t name) {}
58 constexpr wl_registry_listener registry::listener;
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);
65 void registry::s_global_remove(void *data, struct wl_registry *r,
67 static_cast<registry *>(data)->event_global_remove(name);
71 // ___ _ _| |_ _ __ _ _| |_
72 // / _ \| | | | __| '_ \| | | | __|
73 // | (_) | |_| | |_| |_) | |_| | |_
74 // \___/ \__,_|\__| .__/ \__,_|\__|
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);
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,
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);
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,
94 void output::event_done() { logdebug("wl::output @ %p done", this->proxy); }
96 void output::event_scale(int32_t factor) {
97 logdebug("wl::output @ %p scale %i", this->proxy, factor);
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,
105 static_cast<output *>(data)->event_geometry(
106 x, y, physical_width, physical_height, subpixel, make, model, transform);
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);
114 void output::s_done(void *data, struct wl_output *wl_output) {
115 static_cast<output *>(data)->event_done();
118 void output::s_scale(void *data, struct wl_output *wl_output, int32_t factor) {
119 static_cast<output *>(data)->event_scale(factor);
122 constexpr wl_output_listener output::listener;
125 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___
126 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
127 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/
128 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
131 // __ _ ___ _ __ (_)_ _(_)
132 // / _` |/ _ \ '_ \| \ \ / / |
133 // | (_| | __/ | | | |\ V /| |
134 // \__, |\___|_| |_|_| \_/ |_|
139 // ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __
140 // / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
141 // | (_| (_) | | | | |_| | | (_) | | | __/ |
142 // \___\___/|_| |_|\__|_| \___/|_|_|\___|_|
144 controller::controller(wl_registry *r, uint32_t name, uint32_t version)
146 wl_registry_bind(r, name, &ivi_controller_interface, version)) {
147 ivi_controller_add_listener(this->proxy, &listener, this);
150 controller::~controller() {}
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,
156 this->screens[id] = std::make_unique<struct screen>(id, screen);
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);
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);
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);
175 void controller::s_screen(void *data, struct ivi_controller *ivi_controller,
177 struct ivi_controller_screen *screen) {
178 static_cast<controller *>(data)->event_screen(id_screen, screen);
181 void controller::s_layer(void *data, struct ivi_controller *ivi_controller,
183 static_cast<controller *>(data)->event_layer(id_layer);
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);
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);
198 constexpr ivi_controller_listener controller::listener;
201 // | | __ _ _ _ ___ _ __
202 // | |/ _` | | | |/ _ \ '__|
203 // | | (_| | |_| | __/ |
204 // |_|\__,_|\__, |\___|_|
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);
212 logdebug("%s layer %i @ %p", __func__, this->id, this->proxy);
213 ivi_controller_layer_destroy(this->proxy, 1);
214 this->proxy = nullptr;
217 void layer::event_visibility(int32_t visibility) {
218 logdebug("genivi::layer %s @ %p v %i", __func__, this->proxy, visibility);
221 void layer::event_opacity(wl_fixed_t opacity) {
222 logdebug("genivi::layer %s @ %p o %i", __func__, this->proxy, opacity);
225 void layer::event_source_rectangle(int32_t x, int32_t y, int32_t width,
227 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
228 x, y, width, height);
231 void layer::event_destination_rectangle(int32_t x, int32_t y, int32_t width,
233 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
234 x, y, width, height);
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,
242 void layer::event_orientation(int32_t orientation) {
243 logdebug("genivi::layer %s @ %p o %i", __func__, this->proxy, orientation);
246 void layer::event_screen(struct wl_output *screen) {
247 logdebug("genivi::layer %s @ %p s %p", __func__, this->proxy, screen);
250 void layer::event_destroyed() {
251 logdebug("genivi::layer %s @ %p", __func__, this->proxy);
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);
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);
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);
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);
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);
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);
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);
296 void layer::s_destroyed(void *data,
297 struct ivi_controller_layer *ivi_controller_layer) {
298 static_cast<layer *>(data)->event_destroyed();
301 constexpr ivi_controller_layer_listener layer::listener;
304 // ___ _ _ _ __ / _| __ _ ___ ___
305 // / __| | | | '__| |_ / _` |/ __/ _ \
306 // \__ \ |_| | | | _| (_| | (_| __/
307 // |___/\__,_|_| |_| \__,_|\___\___|
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);
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;
320 void surface::event_visibility(int32_t visibility) {
321 logdebug("genivi::surface %s @ %p v %i", __func__, this->proxy, visibility);
324 void surface::event_opacity(wl_fixed_t opacity) {
325 logdebug("genivi::surface %s @ %p o %i", __func__, this->proxy, opacity);
328 void surface::event_source_rectangle(int32_t x, int32_t y, int32_t width,
330 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
331 this->proxy, x, y, width, height);
334 void surface::event_destination_rectangle(int32_t x, int32_t y, int32_t width,
336 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
337 this->proxy, x, y, width, height);
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,
345 void surface::event_orientation(int32_t orientation) {
346 logdebug("genivi::surface %s @ %p o %i", __func__, this->proxy, orientation);
349 void surface::event_pixelformat(int32_t pixelformat) {
350 logdebug("genivi::surface %s @ %p f %i", __func__, this->proxy, pixelformat);
353 void surface::event_layer(struct ivi_controller_layer *layer) {
354 logdebug("genivi::surface %s @ %p l @ %p", __func__, this->proxy, layer);
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,
365 void surface::event_destroyed() {
366 logdebug("genivi::surface %s @ %p", __func__, this->proxy);
369 void surface::event_content(int32_t content_state) {
370 logdebug("genivi::surface %s @ %p s %i", __func__, this->proxy,
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);
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);
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);
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,
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);
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);
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);
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);
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);
432 void surface::s_destroyed(
433 void *data, struct ivi_controller_surface *ivi_controller_surface) {
434 static_cast<surface *>(data)->event_destroyed();
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);
443 constexpr ivi_controller_surface_listener surface::listener;
446 // ___ ___ _ __ ___ ___ _ __
447 /// __|/ __| '__/ _ \/ _ \ '_ \
448 //\__ \ (__| | | __/ __/ | | |
449 //|___/\___|_| \___|\___|_| |_|
451 screen::screen(uint32_t i, ivi_controller_screen *p)
452 : wayland_proxy(p), id(i) {}