4 #include "ivi-controller-client-protocol.h"
9 #include <unordered_map>
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 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| \_/\_/ |_|
43 // _ __ ___ __ _(_)___| |_ _ __ _ _
44 // | '__/ _ \/ _` | / __| __| '__| | | |
45 // | | | __/ (_| | \__ \ |_| | | |_| |
46 // |_| \___|\__, |_|___/\__|_| \__, |
48 struct registry : public wayland_proxy<struct wl_registry> {
49 typedef std::function<void(struct wl_registry *, uint32_t, uint32_t)> binder;
50 std::unordered_map<std::string, binder> bindings;
52 registry(struct wl_display *d);
55 void add_global_handler(char const *iface, binder bind);
58 void global(uint32_t name, char const *iface, uint32_t v);
59 void global_remove(uint32_t name);
63 // __| (_)___ _ __ | | __ _ _ _
64 // / _` | / __| '_ \| |/ _` | | | |
65 // | (_| | \__ \ |_) | | (_| | |_| |
66 // \__,_|_|___/ .__/|_|\__,_|\__, |
69 std::unique_ptr<struct wl_display, void (*)(struct wl_display *)> d;
82 // ___ _ _| |_ _ __ _ _| |_
83 // / _ \| | | | __| '_ \| | | | __|
84 // | (_) | |_| | |_| |_) | |_| | |_
85 // \___/ \__,_|\__| .__/ \__,_|\__|
87 struct output : wayland_proxy<struct wl_output> {
92 output(struct wl_registry *r, uint32_t name, uint32_t v);
95 void geometry(int32_t x, int32_t y, int32_t pw, int32_t ph, int32_t subpel,
96 char const *make, char const *model, int32_t tx);
97 void mode(uint32_t flags, int32_t w, int32_t h, int32_t r);
99 void scale(int32_t factor);
103 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___
104 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
105 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/
106 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
109 // __ _ ___ _ __ (_)_ _(_)
110 // / _` |/ _ \ '_ \| \ \ / / |
111 // | (_| | __/ | | | |\ V /| |
112 // \__, |\___|_| |_|_| \_/ |_|
127 struct controller_child {
128 struct controller *parent;
131 controller_child(struct controller *c, uint32_t i) : parent(c), id(i) {}
132 virtual ~controller_child() {}
136 // ___ _ _ _ __ / _| __ _ ___ ___
137 // / __| | | | '__| |_ / _` |/ __/ _ \
138 // \__ \ |_| | | | _| (_| | (_| __/
139 // |___/\__,_|_| |_| \__,_|\___\___|
141 struct surface : public wayland_proxy<struct ivi_controller_surface>,
143 struct rect dst_rect;
144 struct rect src_rect;
150 surface(uint32_t i, struct controller *c);
154 void set_visibility(uint32_t visibility);
155 void set_opacity(wl_fixed_t opacity);
156 void set_source_rectangle(int32_t x, int32_t y, int32_t width,
158 void set_destination_rectangle(int32_t x, int32_t y, int32_t width,
160 void set_configuration(int32_t width, int32_t height);
161 void set_orientation(int32_t orientation);
162 void screenshot(const char *filename);
164 void destroy(int32_t destroy_scene_object);
168 // | | __ _ _ _ ___ _ __
169 // | |/ _` | | | |/ _ \ '__|
170 // | | (_| | |_| | __/ |
171 // |_|\__,_|\__, |\___|_|
173 struct layer : public wayland_proxy<struct ivi_controller_layer>,
175 struct rect dst_rect;
176 struct rect src_rect;
182 layer(uint32_t i, struct controller *c);
183 layer(uint32_t i, int32_t w, int32_t h, struct controller *c);
187 void set_visibility(uint32_t visibility);
188 void set_opacity(wl_fixed_t opacity);
189 void set_source_rectangle(int32_t x, int32_t y, int32_t width,
191 void set_destination_rectangle(int32_t x, int32_t y, int32_t width,
193 void set_configuration(int32_t width, int32_t height);
194 void set_orientation(int32_t orientation);
195 void screenshot(const char *filename);
196 void clear_surfaces();
197 void add_surface(struct surface *surface);
198 void remove_surface(struct surface *surface);
199 void set_render_order(std::vector<uint32_t> const &ro);
203 // ___ ___ _ __ ___ ___ _ __
204 // / __|/ __| '__/ _ \/ _ \ '_ \
205 // \__ \ (__| | | __/ __/ | | |
206 // |___/\___|_| \___|\___|_| |_|
208 struct screen : public wayland_proxy<struct ivi_controller_screen>,
210 screen(uint32_t i, struct controller *c, struct ivi_controller_screen *p);
212 void add_layer(layer *l);
213 void set_render_order(std::vector<uint32_t> const &ro);
217 // ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __
218 // / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
219 // | (_| (_) | | | | |_| | | (_) | | | __/ |
220 // \___\___/|_| |_|\__|_| \___/|_|_|\___|_|
222 struct controller : public wayland_proxy<struct ivi_controller> {
223 std::unordered_map<uintptr_t, uint32_t> surface_proxy_to_id;
224 std::unordered_map<uintptr_t, uint32_t> layer_proxy_to_id;
225 std::unordered_map<uintptr_t, uint32_t> screen_proxy_to_id;
227 std::unordered_map<uint32_t, std::unique_ptr<struct surface>> surfaces;
228 std::unordered_map<uint32_t, std::unique_ptr<struct layer>> layers;
229 std::unordered_map<uint32_t, std::unique_ptr<struct screen>> screens;
231 typedef std::pair<char const *, std::function<void(struct controller *)>>
233 std::vector<name_task_pair> pending;
237 void add_proxy_to_id_mapping(struct ivi_controller_surface *p, uint32_t id);
238 void remove_proxy_to_id_mapping(struct ivi_controller_surface *p);
239 void add_proxy_to_id_mapping(struct ivi_controller_layer *p, uint32_t id);
240 void remove_proxy_to_id_mapping(struct ivi_controller_layer *p);
241 void add_proxy_to_id_mapping(struct wl_output *p, uint32_t id);
242 void remove_proxy_to_id_mapping(struct wl_output *p);
244 void add_task(char const *name, std::function<void(struct controller *)> &&f);
245 void execute_pending();
247 controller(struct wl_registry *r, uint32_t name, uint32_t version);
248 ~controller() override;
251 void commit_changes() const { ivi_controller_commit_changes(this->proxy); }
252 void layer_create(uint32_t id, int32_t w, int32_t h);
253 void surface_create(uint32_t id);
257 void controller_screen(uint32_t id, struct ivi_controller_screen *screen);
258 void controller_layer(uint32_t id);
259 void controller_surface(uint32_t id);
260 void controller_error(int32_t object_id, int32_t object_type,
261 int32_t error_code, char const *error_text);
264 void surface_visibility(uint32_t id, int32_t visibility);
265 void surface_opacity(uint32_t id, float opacity);
266 void surface_source_rectangle(uint32_t id, int32_t x, int32_t y,
267 int32_t width, int32_t height);
268 void surface_destination_rectangle(uint32_t id, int32_t x, int32_t y,
269 int32_t width, int32_t height);
270 void surface_configuration(uint32_t id, int32_t width, int32_t height);
271 void surface_orientation(uint32_t id, int32_t orientation);
272 void surface_pixelformat(uint32_t id, int32_t pixelformat);
273 void surface_layer(uint32_t id, struct ivi_controller_layer *layer);
274 void surface_stats(uint32_t id, uint32_t redraw_count, uint32_t frame_count,
275 uint32_t update_count, uint32_t pid,
276 const char *process_name);
277 void surface_destroyed(uint32_t id);
278 void surface_content(uint32_t id, int32_t content_state);
281 void layer_visibility(uint32_t id, int32_t visibility);
282 void layer_opacity(uint32_t id, float opacity);
283 void layer_source_rectangle(uint32_t id, int32_t x, int32_t y, int32_t width,
285 void layer_destination_rectangle(uint32_t id, int32_t x, int32_t y,
286 int32_t width, int32_t height);
287 void layer_configuration(uint32_t id, int32_t width, int32_t height);
288 void layer_orientation(uint32_t id, int32_t orientation);
289 void layer_screen(uint32_t id, struct wl_output *screen);
290 void layer_destroyed(uint32_t id);
294 #endif // !WM_WAYLAND_HPP