4 #include "ivi-controller-client-protocol.h"
14 // __ ____ _ _ _| | __ _ _ __ __| | _ __ _ __ _____ ___ _
15 // \ \ /\ / / _` | | | | |/ _` | '_ \ / _` | | '_ \| '__/ _ \ \/ / | | |
16 // \ V V / (_| | |_| | | (_| | | | | (_| | | |_) | | | (_) > <| |_| |
17 // \_/\_/ \__,_|\__, |_|\__,_|_| |_|\__,_|____| .__/|_| \___/_/\_\\__, |
18 // |___/ |_____|_| |___/
19 template <typename ProxyT>
20 struct wayland_proxy {
23 wayland_proxy(void *p) : proxy(static_cast<ProxyT *>(p)) {}
25 virtual ~wayland_proxy() {
26 // If this is the nullptr, then it means it already was destroyed by a
27 // custom wayland dtor
29 logdebug("%s %p @ %p", __func__, this, this->proxy);
30 wl_proxy_destroy(reinterpret_cast<struct wl_proxy *>(this->proxy));
36 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ __ _| |
37 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / |
38 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ \ V V /| |
39 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| \_/\_/ |_|
45 // __| (_)___ _ __ | | __ _ _ _
46 // / _` | / __| '_ \| |/ _` | | | |
47 // | (_| | \__ \ |_) | | (_| | |_| |
48 // \__,_|_|___/ .__/|_|\__,_|\__, |
51 std::unique_ptr<struct wl_display, std::function<void(struct wl_display *)>>
53 std::unique_ptr<struct registry> r;
65 // _ __ ___ __ _(_)___| |_ _ __ _ _
66 // | '__/ _ \/ _` | / __| __| '__| | | |
67 // | | | __/ (_| | \__ \ |_| | | |_| |
68 // |_| \___|\__, |_|___/\__|_| \__, |
70 struct registry : public wayland_proxy<struct wl_registry> {
71 typedef std::function<void(struct wl_registry *, uint32_t, uint32_t)> binder;
72 std::map<std::string, binder> bindings;
74 registry(struct wl_display *d);
77 void add_global_handler(char const *iface, binder bind);
80 void global(uint32_t name, char const *iface, uint32_t v);
81 void global_remove(uint32_t name);
85 // ___ _ _| |_ _ __ _ _| |_
86 // / _ \| | | | __| '_ \| | | | __|
87 // | (_) | |_| | |_| |_) | |_| | |_
88 // \___/ \__,_|\__| .__/ \__,_|\__|
90 struct output : wayland_proxy<struct wl_output> {
95 output(struct wl_registry *registry, uint32_t name, uint32_t version);
98 void geometry(int32_t x, int32_t y, int32_t pw, int32_t ph, int32_t subpel,
99 char const *make, char const *model, int32_t tx);
100 void mode(uint32_t flags, int32_t w, int32_t h, int32_t r);
102 void scale(int32_t factor);
106 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___
107 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
108 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/
109 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
112 // __ _ ___ _ __ (_)_ _(_)
113 // / _` |/ _ \ '_ \| \ \ / / |
114 // | (_| | __/ | | | |\ V /| |
115 // \__, |\___|_| |_|_| \_/ |_|
130 struct controlled_entity {
131 struct controller *parent;
134 controlled_entity(struct controller *c, uint32_t i) : parent(c), id(i) {}
135 virtual ~controlled_entity() {}
139 // ___ _ _ _ __ / _| __ _ ___ ___
140 // / __| | | | '__| |_ / _` |/ __/ _ \
141 // \__ \ |_| | | | _| (_| | (_| __/
142 // |___/\__,_|_| |_| \__,_|\___\___|
144 struct surface : public wayland_proxy<struct ivi_controller_surface>,
146 struct rect dst_rect;
147 struct rect src_rect;
153 surface(uint32_t i, struct controller *c);
157 inline void set_visibility(uint32_t visibility) {
158 ivi_controller_surface_set_visibility(this->proxy, visibility);
161 inline void set_opacity(wl_fixed_t opacity) {
162 ivi_controller_surface_set_opacity(this->proxy, opacity);
165 inline void set_source_rectangle(int32_t x, int32_t y, int32_t width,
167 ivi_controller_surface_set_source_rectangle(this->proxy, x, y, width,
171 inline void set_destination_rectangle(int32_t x, int32_t y, int32_t width,
173 ivi_controller_surface_set_destination_rectangle(this->proxy, x, y, width,
177 inline void set_configuration(int32_t width, int32_t height) {
178 ivi_controller_surface_set_configuration(this->proxy, width, height);
181 inline void set_orientation(int32_t orientation) {
182 ivi_controller_surface_set_orientation(this->proxy, orientation);
185 inline void screenshot(const char *filename) {
186 ivi_controller_surface_screenshot(this->proxy, filename);
189 inline void send_stats() { ivi_controller_surface_send_stats(this->proxy); }
191 inline void destroy(int32_t destroy_scene_object) {
192 ivi_controller_surface_destroy(this->proxy, destroy_scene_object);
197 // | | __ _ _ _ ___ _ __
198 // | |/ _` | | | |/ _ \ '__|
199 // | | (_| | |_| | __/ |
200 // |_|\__,_|\__, |\___|_|
202 struct layer : public wayland_proxy<struct ivi_controller_layer>,
204 struct rect dst_rect;
205 struct rect src_rect;
211 layer(uint32_t i, struct controller *c);
212 layer(uint32_t i, int32_t w, int32_t h, struct controller *c);
216 inline void set_visibility(uint32_t visibility) {
217 ivi_controller_layer_set_visibility(this->proxy, visibility);
220 inline void set_opacity(wl_fixed_t opacity) {
221 ivi_controller_layer_set_opacity(this->proxy, opacity);
224 inline void set_source_rectangle(int32_t x, int32_t y, int32_t width,
226 ivi_controller_layer_set_source_rectangle(this->proxy, x, y, width,
230 inline void set_destination_rectangle(int32_t x, int32_t y, int32_t width,
232 ivi_controller_layer_set_destination_rectangle(this->proxy, x, y, width,
236 inline void set_configuration(int32_t width, int32_t height) {
237 ivi_controller_layer_set_configuration(this->proxy, width, height);
240 inline void set_orientation(int32_t orientation) {
241 ivi_controller_layer_set_orientation(this->proxy, orientation);
244 inline void screenshot(const char *filename) {
245 ivi_controller_layer_screenshot(this->proxy, filename);
248 inline void clear_surfaces() {
249 ivi_controller_layer_clear_surfaces(this->proxy);
252 inline void add_surface(struct surface *surface) {
253 ivi_controller_layer_add_surface(this->proxy, surface->proxy);
256 inline void remove_surface(struct surface *surface) {
257 ivi_controller_layer_remove_surface(this->proxy, surface->proxy);
260 inline void set_render_order(struct wl_array *surfaces) {
261 ivi_controller_layer_set_render_order(this->proxy, surfaces);
266 // ___ ___ _ __ ___ ___ _ __
267 // / __|/ __| '__/ _ \/ _ \ '_ \
268 // \__ \ (__| | | __/ __/ | | |
269 // |___/\___|_| \___|\___|_| |_|
271 struct screen : public wayland_proxy<struct ivi_controller_screen>,
273 screen(uint32_t i, struct controller *c, struct ivi_controller_screen *p);
275 void clear() { ivi_controller_screen_clear(this->proxy); }
276 void add_layer(layer *l) { ivi_controller_screen_add_layer(this->proxy, l->proxy); }
280 // ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __
281 // / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
282 // | (_| (_) | | | | |_| | | (_) | | | __/ |
283 // \___\___/|_| |_|\__|_| \___/|_|_|\___|_|
285 struct controller : public wayland_proxy<struct ivi_controller> {
286 std::map<uint32_t, std::unique_ptr<struct surface>> surfaces;
287 std::map<uint32_t, std::unique_ptr<struct layer>> layers;
288 std::map<uint32_t, std::unique_ptr<struct screen>> screens;
290 typedef std::pair<char const *, std::function<void(struct controller *)>>
292 std::vector<name_task_pair> pending;
296 void add_task(char const *name,
297 std::function<void(struct controller *)> &&f) {
298 this->pending.emplace_back(std::make_pair(name, f));
301 void execute_pending() {
302 if (!this->pending.empty()) {
303 for (auto &t : this->pending) {
304 logdebug("executing task '%s'", t.first);
307 this->pending.clear();
308 ivi_controller_commit_changes(this->proxy);
309 // XXX: No flush here...
313 controller(struct wl_registry *r, uint32_t name, uint32_t version);
314 ~controller() override;
317 void commit_changes() const { ivi_controller_commit_changes(this->proxy); }
318 void layer_create(uint32_t id, int32_t w, int32_t h);
319 void surface_create(uint32_t id);
323 void controller_screen(uint32_t id, struct ivi_controller_screen *screen);
324 void controller_layer(uint32_t id);
325 void controller_surface(uint32_t id);
326 void controller_error(int32_t oid, int32_t otype, int32_t code,
330 void surface_visibility(uint32_t id, int32_t visibility);
331 void surface_opacity(uint32_t id, float opacity);
332 void surface_source_rectangle(uint32_t id, int32_t x, int32_t y,
333 int32_t width, int32_t height);
334 void surface_destination_rectangle(uint32_t id, int32_t x, int32_t y,
335 int32_t width, int32_t height);
336 void surface_configuration(uint32_t id, int32_t width, int32_t height);
337 void surface_orientation(uint32_t id, int32_t orientation);
338 void surface_pixelformat(uint32_t id, int32_t pixelformat);
339 void surface_layer(uint32_t id, struct ivi_controller_layer *layer);
340 void surface_stats(uint32_t id, uint32_t redraw_count, uint32_t frame_count,
341 uint32_t update_count, uint32_t pid,
342 const char *process_name);
343 void surface_destroyed(uint32_t id);
344 void surface_content(uint32_t id, int32_t content_state);
347 void layer_visibility(uint32_t id, int32_t visibility);
348 void layer_opacity(uint32_t id, float opacity);
349 void layer_source_rectangle(uint32_t id, int32_t x, int32_t y, int32_t width,
351 void layer_destination_rectangle(uint32_t id, int32_t x, int32_t y,
352 int32_t width, int32_t height);
353 void layer_configuration(uint32_t id, int32_t width, int32_t height);
354 void layer_orientation(uint32_t id, int32_t orientation);
355 void layer_screen(uint32_t id, struct wl_output *screen);
356 void layer_destroyed(uint32_t id);
360 #endif // !WM_WAYLAND_HPP