-struct controller : public wayland_proxy<ivi_controller> {
- std::map<uint32_t, std::unique_ptr<surface>> surfaces;
- std::map<uint32_t, std::unique_ptr<layer>> layers;
- std::map<uint32_t, std::unique_ptr<screen>> screens;
-
- controller(wl_registry *r, uint32_t name, uint32_t version);
- ~controller() override;
-
- void event_screen(uint32_t id, ivi_controller_screen *screen);
- void event_layer(uint32_t id);
- void event_surface(uint32_t id);
- void event_error(int32_t oid, int32_t otype, int32_t code, char const *text);
-
- // thunks...
- static void s_screen(void *data, struct ivi_controller *ivi_controller,
- uint32_t id_screen,
- struct ivi_controller_screen *screen);
-
- static void s_layer(void *data, struct ivi_controller *ivi_controller,
- uint32_t id_layer);
-
- static void s_surface(void *data, struct ivi_controller *ivi_controller,
- uint32_t id_surface);
-
- static void s_error(void *data, struct ivi_controller *ivi_controller,
- int32_t object_id, int32_t object_type,
- int32_t error_code, const char *error_text);
-
- static constexpr ivi_controller_listener listener = {s_screen, s_layer,
- s_surface, s_error};
+struct controller : public wayland_proxy<struct ivi_controller> {
+ // HACK:
+ // The order of these member is mandatory, as when objects are destroyed
+ // they will call their parent (that's us right here!) and remove their
+ // proxy-to-id mapping. I.e. the *_proxy_to_id members need to be valid
+ // when the surfaces/layers/screens maps are destroyed. This sucks, but
+ // I cannot see a better solution w/o globals or some other horrible
+ // call-our-parent construct.
+ std::unordered_map<uintptr_t, uint32_t> surface_proxy_to_id;
+ std::unordered_map<uintptr_t, uint32_t> layer_proxy_to_id;
+ std::unordered_map<uintptr_t, uint32_t> screen_proxy_to_id;
+
+ std::unordered_map<uint32_t, std::unique_ptr<struct surface>> surfaces;
+ std::unordered_map<uint32_t, std::unique_ptr<struct layer>> layers;
+ std::unordered_map<uint32_t, std::unique_ptr<struct screen>> screens;
+
+ typedef std::pair<char const *, std::function<void(struct controller *)>>
+ name_task_pair;
+ std::vector<name_task_pair> pending;
+
+ size output_size;
+
+ void add_proxy_to_id_mapping(struct ivi_controller_surface *p, uint32_t id);
+ void remove_proxy_to_id_mapping(struct ivi_controller_surface *p);
+ void add_proxy_to_id_mapping(struct ivi_controller_layer *p, uint32_t id);
+ void remove_proxy_to_id_mapping(struct ivi_controller_layer *p);
+ void add_proxy_to_id_mapping(struct wl_output *p, uint32_t id);
+ void remove_proxy_to_id_mapping(struct wl_output *p);
+
+ void add_task(char const *name,
+ std::function<void(struct controller *)> &&f);
+ void execute_pending();
+
+ controller(struct wl_registry *r, uint32_t name, uint32_t version);
+
+ // Requests
+ void commit_changes() const {
+ ivi_controller_commit_changes(this->proxy.get());
+ }
+ void layer_create(uint32_t id, int32_t w, int32_t h);
+ void surface_create(uint32_t id);
+
+ // Events
+ // controller
+ void controller_screen(uint32_t id, struct ivi_controller_screen *screen);
+ void controller_layer(uint32_t id);
+ void controller_surface(uint32_t id);
+ void controller_error(int32_t object_id, int32_t object_type,
+ int32_t error_code, char const *error_text);
+
+ // surface
+ void surface_visibility(struct surface *s, int32_t visibility);
+ void surface_opacity(struct surface *s, float opacity);
+ void surface_source_rectangle(struct surface *s, int32_t x, int32_t y,
+ int32_t width, int32_t height);
+ void surface_destination_rectangle(struct surface *s, int32_t x, int32_t y,
+ int32_t width, int32_t height);
+ void surface_configuration(struct surface *s, int32_t width, int32_t height);
+ void surface_orientation(struct surface *s, int32_t orientation);
+ void surface_pixelformat(struct surface *s, int32_t pixelformat);
+ void surface_layer(struct surface *s, struct ivi_controller_layer *layer);
+ void surface_stats(struct surface *s, uint32_t redraw_count, uint32_t frame_count,
+ uint32_t update_count, uint32_t pid,
+ const char *process_name);
+ void surface_destroyed(struct surface *s);
+ void surface_content(struct surface *s, int32_t content_state);
+
+ // layer
+ void layer_visibility(struct layer *l, int32_t visibility);
+ void layer_opacity(struct layer *l, float opacity);
+ void layer_source_rectangle(struct layer *l, int32_t x, int32_t y, int32_t width,
+ int32_t height);
+ void layer_destination_rectangle(struct layer *l, int32_t x, int32_t y,
+ int32_t width, int32_t height);
+ void layer_configuration(struct layer *l, int32_t width, int32_t height);
+ void layer_orientation(struct layer *l, int32_t orientation);
+ void layer_screen(struct layer *l, struct wl_output *screen);
+ void layer_destroyed(struct layer *l);