-conn::~conn() {
- this->layers.clear();
- this->surfaces.clear();
- ivi_controller_destroy(this->c);
- this->outputs.clear();
- wl_registry_destroy(this->r);
- wl_display_disconnect(this->d);
-}
-
-static ivi_controller_surface_listener cs_listener = {};
-
-static ivi_controller_layer_listener cl_listener = {};
-
-static void c_screen(void *data, struct ivi_controller *ivi_controller,
- uint32_t id_screen, struct ivi_controller_screen *screen) {
- lognotice("ivi_controller @ %p screen %u (%x) @ %p", ivi_controller,
- id_screen, id_screen, screen);
-}
-
-static void c_layer(void *data, struct ivi_controller *ivi_controller,
- uint32_t id_layer) {
- lognotice("ivi_controller @ %p layer %u (%x)", ivi_controller, id_layer,
- id_layer);
- auto c = static_cast<conn *>(data);
- auto i = std::make_unique<ivi_layer>(
- ivi_controller_layer_create(c->c, id_layer, 0, 0), id_layer, c);
- ivi_controller_layer_add_listener(i->controller, &cl_listener, i.get());
- c->layers[id_layer] = std::move(i);
-}
-
-static void c_surface(void *data, struct ivi_controller *ivi_controller,
- uint32_t id_surface) {
- lognotice("ivi_controller @ %p surface %u (%x)", ivi_controller, id_surface,
- id_surface);
- auto c = static_cast<conn *>(data);
- auto i = std::make_unique<ivi_surface>(
- ivi_controller_surface_create(c->c, id_surface), id_surface, c);
- ivi_controller_surface_add_listener(i->controller, &cs_listener, i.get());
- c->surfaces[id_surface] = std::move(i);
-}
-
-static void c_error(void *data, struct ivi_controller *ivi_controller,
- int32_t object_id, int32_t object_type, int32_t error_code,
- const char *error_text) {
- lognotice("ivi_controller @ %p error o %i t %i c %i text %s", ivi_controller,
- object_id, object_type, error_code, error_text);
-}
-
-static struct ivi_controller_listener c_listener = {c_screen, c_layer,
- c_surface, c_error};
-
-static void o_geometry(void *data, struct wl_output *wl_output, int32_t x,
- int32_t y, int32_t physical_width,
- int32_t physical_height, int32_t subpixel,
- const char *make, const char *model, int32_t transform) {
- lognotice("output @ %p x %i y %i w %i h %i spel %x make %s model %s tx %i",
- wl_output, x, y, physical_width, physical_height, subpixel, make,
- model, transform);
-}
-
-static void o_mode(void *data, struct wl_output *wl_output, uint32_t flags,
- int32_t width, int32_t height, int32_t refresh) {
- lognotice("output @ %p mode f %x w %i h %i r %i", wl_output, flags, width,
- height, refresh);
-}
-
-static void o_done(void *data, struct wl_output *wl_output) {
- lognotice("output @ %p done");
-}
+namespace {
+int check_events(struct wl::display *d, struct conn *c, int fd) {
+ struct pollfd pfd[2] = {{.fd = d->get_fd(), .events = POLLIN, .revents = 0},
+ {.fd = fd, .events = POLLIN, .revents = 0}};
+
+ d->flush();
+
+ if (poll(pfd, fd != -1 ? 2 : 1, -1) != -1 && errno != EINTR) {
+ int ret = 0;
+
+ if (pfd[0].revents & POLLIN) {
+ ret = d->dispatch();
+ }
+
+ if (ret == -1)
+ return ret;
+
+ if (fd != -1 && (pfd[1].revents & POLLIN)) {
+ char buf[256];
+
+ // read all there is ...
+ while (read(pfd[1].fd, buf, sizeof(buf)) == sizeof(buf))
+ ;
+
+ // Display current status
+ if (!c->c->surfaces.empty()) {
+ puts("Surfaces:");
+ for (auto const &i : c->c->surfaces) {
+ struct genivi::rect const &r = i.second->dst_rect;
+ struct genivi::size const &s = i.second->size;
+ printf("%d [%ux%u] (%ux%u@%dx%d), ", i.first, s.w, s.h, r.w, r.h,
+ r.x, r.y);
+ }
+ puts("\b\b ");
+ }
+ }
+ }