4 #include "ivi-controller-client-protocol.h"
10 #include <unordered_map>
14 // __ ____ _ _ _| | __ _ _ __ __| | _ __ _ __ _____ ___ _
15 // \ \ /\ / / _` | | | | |/ _` | '_ \ / _` | | '_ \| '__/ _ \ \/ / | | |
16 // \ V V / (_| | |_| | | (_| | | | | (_| | | |_) | | | (_) > <| |_| |
17 // \_/\_/ \__,_|\__, |_|\__,_|_| |_|\__,_|____| .__/|_| \___/_/\_\\__, |
18 // |___/ |_____|_| |___/
19 template <typename ProxyT>
20 struct wayland_proxy {
21 std::unique_ptr<ProxyT, std::function<void(ProxyT *)>> proxy;
22 wayland_proxy(void *p)
23 : wayland_proxy(p, [](ProxyT *p) {
24 wl_proxy_destroy(reinterpret_cast<struct wl_proxy *>(p));
26 wayland_proxy(void *p, std::function<void(ProxyT *)> p_del)
27 : proxy(std::unique_ptr<ProxyT, std::function<void(ProxyT *)>>(
28 static_cast<ProxyT *>(p), p_del)) {}
32 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ __ _| |
33 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / |
34 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ \ V V /| |
35 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| \_/\_/ |_|
39 // _ __ ___ __ _(_)___| |_ _ __ _ _
40 // | '__/ _ \/ _` | / __| __| '__| | | |
41 // | | | __/ (_| | \__ \ |_| | | |_| |
42 // |_| \___|\__, |_|___/\__|_| \__, |
44 struct registry : public wayland_proxy<struct wl_registry> {
45 typedef std::function<void(struct wl_registry *, uint32_t, uint32_t)> binder;
46 std::unordered_map<std::string, binder> bindings;
48 registry(struct wl_display *d);
50 void add_global_handler(char const *iface, binder bind);
53 void global(uint32_t name, char const *iface, uint32_t v);
54 void global_remove(uint32_t name);
58 // __| (_)___ _ __ | | __ _ _ _
59 // / _` | / __| '_ \| |/ _` | | | |
60 // | (_| | \__ \ |_) | | (_| | |_| |
61 // \__,_|_|___/ .__/|_|\__,_|\__, |
64 std::unique_ptr<struct wl_display, void (*)(struct wl_display *)> d;
76 // ___ _ _| |_ _ __ _ _| |_
77 // / _ \| | | | __| '_ \| | | | __|
78 // | (_) | |_| | |_| |_) | |_| | |_
79 // \___/ \__,_|\__| .__/ \__,_|\__|
81 struct output : wayland_proxy<struct wl_output> {
86 output(struct wl_registry *r, uint32_t name, uint32_t v);
89 void geometry(int32_t x, int32_t y, int32_t pw, int32_t ph, int32_t subpel,
90 char const *make, char const *model, int32_t tx);
91 void mode(uint32_t flags, int32_t w, int32_t h, int32_t r);
93 void scale(int32_t factor);
97 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___
98 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
99 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/
100 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
103 // __ _ ___ _ __ (_)_ _(_)
104 // / _` |/ _ \ '_ \| \ \ / / |
105 // | (_| | __/ | | | |\ V /| |
106 // \__, |\___|_| |_|_| \_/ |_|
121 struct controller_child {
122 struct controller *parent;
125 controller_child(struct controller *c, uint32_t i) : parent(c), id(i) {}
126 virtual ~controller_child() {}
130 // ___ _ _ _ __ / _| __ _ ___ ___
131 // / __| | | | '__| |_ / _` |/ __/ _ \
132 // \__ \ |_| | | | _| (_| | (_| __/
133 // |___/\__,_|_| |_| \__,_|\___\___|
135 struct surface : public wayland_proxy<struct ivi_controller_surface>,
137 struct rect dst_rect;
138 struct rect src_rect;
144 surface(uint32_t i, struct controller *c);
147 void set_visibility(uint32_t visibility);
148 void set_opacity(wl_fixed_t opacity);
149 void set_source_rectangle(int32_t x, int32_t y, int32_t width,
151 void set_destination_rectangle(int32_t x, int32_t y, int32_t width,
153 void set_configuration(int32_t width, int32_t height);
154 void set_orientation(int32_t orientation);
155 void screenshot(const char *filename);
157 void destroy(int32_t destroy_scene_object);
161 // | | __ _ _ _ ___ _ __
162 // | |/ _` | | | |/ _ \ '__|
163 // | | (_| | |_| | __/ |
164 // |_|\__,_|\__, |\___|_|
166 struct layer : public wayland_proxy<struct ivi_controller_layer>,
168 struct rect dst_rect;
169 struct rect src_rect;
175 layer(uint32_t i, struct controller *c);
176 layer(uint32_t i, int32_t w, int32_t h, struct controller *c);
179 void set_visibility(uint32_t visibility);
180 void set_opacity(wl_fixed_t opacity);
181 void set_source_rectangle(int32_t x, int32_t y, int32_t width,
183 void set_destination_rectangle(int32_t x, int32_t y, int32_t width,
185 void set_configuration(int32_t width, int32_t height);
186 void set_orientation(int32_t orientation);
187 void screenshot(const char *filename);
188 void clear_surfaces();
189 void add_surface(struct surface *surface);
190 void remove_surface(struct surface *surface);
191 void set_render_order(std::vector<uint32_t> const &ro);
195 // ___ ___ _ __ ___ ___ _ __
196 // / __|/ __| '__/ _ \/ _ \ '_ \
197 // \__ \ (__| | | __/ __/ | | |
198 // |___/\___|_| \___|\___|_| |_|
200 struct screen : public wayland_proxy<struct ivi_controller_screen>,
202 screen(uint32_t i, struct controller *c, struct ivi_controller_screen *p);
204 void add_layer(layer *l);
205 void set_render_order(std::vector<uint32_t> const &ro);
209 // ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __
210 // / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
211 // | (_| (_) | | | | |_| | | (_) | | | __/ |
212 // \___\___/|_| |_|\__|_| \___/|_|_|\___|_|
214 struct controller : public wayland_proxy<struct ivi_controller> {
215 std::unordered_map<uintptr_t, uint32_t> surface_proxy_to_id;
216 std::unordered_map<uintptr_t, uint32_t> layer_proxy_to_id;
217 std::unordered_map<uintptr_t, uint32_t> screen_proxy_to_id;
219 std::unordered_map<uint32_t, std::unique_ptr<struct surface>> surfaces;
220 std::unordered_map<uint32_t, std::unique_ptr<struct layer>> layers;
221 std::unordered_map<uint32_t, std::unique_ptr<struct screen>> screens;
223 typedef std::pair<char const *, std::function<void(struct controller *)>>
225 std::vector<name_task_pair> pending;
229 void add_proxy_to_id_mapping(struct ivi_controller_surface *p, uint32_t id);
230 void remove_proxy_to_id_mapping(struct ivi_controller_surface *p);
231 void add_proxy_to_id_mapping(struct ivi_controller_layer *p, uint32_t id);
232 void remove_proxy_to_id_mapping(struct ivi_controller_layer *p);
233 void add_proxy_to_id_mapping(struct wl_output *p, uint32_t id);
234 void remove_proxy_to_id_mapping(struct wl_output *p);
236 void add_task(char const *name,
237 std::function<void(struct controller *)> &&f);
238 void execute_pending();
240 controller(struct wl_registry *r, uint32_t name, uint32_t version);
243 void commit_changes() const {
244 ivi_controller_commit_changes(this->proxy.get());
246 void layer_create(uint32_t id, int32_t w, int32_t h);
247 void surface_create(uint32_t id);
251 void controller_screen(uint32_t id, struct ivi_controller_screen *screen);
252 void controller_layer(uint32_t id);
253 void controller_surface(uint32_t id);
254 void controller_error(int32_t object_id, int32_t object_type,
255 int32_t error_code, char const *error_text);
258 void surface_visibility(uint32_t id, int32_t visibility);
259 void surface_opacity(uint32_t id, float opacity);
260 void surface_source_rectangle(uint32_t id, int32_t x, int32_t y,
261 int32_t width, int32_t height);
262 void surface_destination_rectangle(uint32_t id, int32_t x, int32_t y,
263 int32_t width, int32_t height);
264 void surface_configuration(uint32_t id, int32_t width, int32_t height);
265 void surface_orientation(uint32_t id, int32_t orientation);
266 void surface_pixelformat(uint32_t id, int32_t pixelformat);
267 void surface_layer(uint32_t id, struct ivi_controller_layer *layer);
268 void surface_stats(uint32_t id, uint32_t redraw_count, uint32_t frame_count,
269 uint32_t update_count, uint32_t pid,
270 const char *process_name);
271 void surface_destroyed(uint32_t id);
272 void surface_content(uint32_t id, int32_t content_state);
275 void layer_visibility(uint32_t id, int32_t visibility);
276 void layer_opacity(uint32_t id, float opacity);
277 void layer_source_rectangle(uint32_t id, int32_t x, int32_t y, int32_t width,
279 void layer_destination_rectangle(uint32_t id, int32_t x, int32_t y,
280 int32_t width, int32_t height);
281 void layer_configuration(uint32_t id, int32_t width, int32_t height);
282 void layer_orientation(uint32_t id, int32_t orientation);
283 void layer_screen(uint32_t id, struct wl_output *screen);
284 void layer_destroyed(uint32_t id);
288 #endif // !WM_WAYLAND_HPP