4 #include "ivi-controller-client-protocol.h"
13 // __ ____ _ _ _| | __ _ _ __ __| | _ __ _ __ _____ ___ _
14 // \ \ /\ / / _` | | | | |/ _` | '_ \ / _` | | '_ \| '__/ _ \ \/ / | | |
15 // \ V V / (_| | |_| | | (_| | | | | (_| | | |_) | | | (_) > <| |_| |
16 // \_/\_/ \__,_|\__, |_|\__,_|_| |_|\__,_|____| .__/|_| \___/_/\_\\__, |
17 // |___/ |_____|_| |___/
18 template <typename ProxyT>
19 struct wayland_proxy {
22 wayland_proxy(void *p) : proxy(static_cast<ProxyT *>(p)) {}
24 virtual ~wayland_proxy() {
25 // If this is the nullptr, then it means it already was destroyed by a
26 // custom wayland dtor
28 logdebug("%s %p @ %p", __func__, this, this->proxy);
29 wl_proxy_destroy(reinterpret_cast<wl_proxy *>(proxy));
35 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ __ _| |
36 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / |
37 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ \ V V /| |
38 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| \_/\_/ |_|
44 // __| (_)___ _ __ | | __ _ _ _
45 // / _` | / __| '_ \| |/ _` | | | |
46 // | (_| | \__ \ |_) | | (_| | |_| |
47 // \__,_|_|___/ .__/|_|\__,_|\__, |
50 std::unique_ptr<wl_display, void (*)(wl_display *)> d;
51 std::unique_ptr<registry> r;
59 // _ __ ___ __ _(_)___| |_ _ __ _ _
60 // | '__/ _ \/ _` | / __| __| '__| | | |
61 // | | | __/ (_| | \__ \ |_| | | |_| |
62 // |_| \___|\__, |_|___/\__|_| \__, |
64 struct registry : public wayland_proxy<wl_registry> {
65 typedef std::function<void(wl_registry *, uint32_t, uint32_t)> binder;
66 std::map<std::string, binder> bindings;
68 registry(wl_display *d);
71 void add_global_handler(char const *iface, binder bind);
73 void event_global(uint32_t name, char const *iface, uint32_t v);
74 void event_global_remove(uint32_t name);
76 static void s_global(void *data, struct wl_registry *r, uint32_t name,
77 char const *iface, uint32_t v);
79 static void s_global_remove(void *data, struct wl_registry *r,
82 static constexpr wl_registry_listener listener = {s_global, s_global_remove};
86 // ___ _ _| |_ _ __ _ _| |_
87 // / _ \| | | | __| '_ \| | | | __|
88 // | (_) | |_| | |_| |_) | |_| | |_
89 // \___/ \__,_|\__| .__/ \__,_|\__|
91 struct output : wayland_proxy<wl_output> {
92 output(wl_registry *registry, uint32_t name, uint32_t version);
94 void event_geometry(int32_t x, int32_t y, int32_t pw, int32_t ph,
95 int32_t subpel, char const *make, char const *model,
97 void event_mode(uint32_t flags, int32_t w, int32_t h, int32_t r);
99 void event_scale(int32_t factor);
101 static void s_geometry(void *data, struct wl_output *wl_output, int32_t x,
102 int32_t y, int32_t physical_width,
103 int32_t physical_height, int32_t subpixel,
104 const char *make, const char *model,
107 static void s_mode(void *data, struct wl_output *wl_output, uint32_t flags,
108 int32_t width, int32_t height, int32_t refresh);
110 static void s_done(void *data, struct wl_output *wl_output);
112 static void s_scale(void *data, struct wl_output *wl_output, int32_t factor);
114 static constexpr wl_output_listener listener = {s_geometry, s_mode, s_done,
119 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___
120 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
121 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/
122 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
125 // __ _ ___ _ __ (_)_ _(_)
126 // / _` |/ _ \ '_ \| \ \ / / |
127 // | (_| | __/ | | | |\ V /| |
128 // \__, |\___|_| |_|_| \_/ |_|
133 // ___ _ _ _ __ / _| __ _ ___ ___
134 // / __| | | | '__| |_ / _` |/ __/ _ \
135 // \__ \ |_| | | | _| (_| | (_| __/
136 // |___/\__,_|_| |_| \__,_|\___\___|
138 struct surface : public wayland_proxy<ivi_controller_surface> {
141 surface(uint32_t i, ivi_controller *c);
144 void event_visibility(int32_t visibility);
145 void event_opacity(wl_fixed_t opacity);
146 void event_source_rectangle(int32_t x, int32_t y, int32_t width,
148 void event_destination_rectangle(int32_t x, int32_t y, int32_t width,
150 void event_configuration(int32_t width, int32_t height);
151 void event_orientation(int32_t orientation);
152 void event_pixelformat(int32_t pixelformat);
153 void event_layer(struct ivi_controller_layer *layer);
154 void event_stats(uint32_t redraw_count, uint32_t frame_count,
155 uint32_t update_count, uint32_t pid,
156 const char *process_name);
157 void event_destroyed();
158 void event_content(int32_t content_state);
160 static void s_visibility(
161 void *data, struct ivi_controller_surface *ivi_controller_surface,
163 static void s_opacity(void *data,
164 struct ivi_controller_surface *ivi_controller_surface,
166 static void s_source_rectangle(
167 void *data, struct ivi_controller_surface *ivi_controller_surface,
168 int32_t x, int32_t y, int32_t width, int32_t height);
169 static void s_destination_rectangle(
170 void *data, struct ivi_controller_surface *ivi_controller_surface,
171 int32_t x, int32_t y, int32_t width, int32_t height);
172 static void s_configuration(
173 void *data, struct ivi_controller_surface *ivi_controller_surface,
174 int32_t width, int32_t height);
175 static void s_orientation(
176 void *data, struct ivi_controller_surface *ivi_controller_surface,
177 int32_t orientation);
178 static void s_pixelformat(
179 void *data, struct ivi_controller_surface *ivi_controller_surface,
180 int32_t pixelformat);
181 static void s_layer(void *data,
182 struct ivi_controller_surface *ivi_controller_surface,
183 struct ivi_controller_layer *layer);
184 static void s_stats(void *data,
185 struct ivi_controller_surface *ivi_controller_surface,
186 uint32_t redraw_count, uint32_t frame_count,
187 uint32_t update_count, uint32_t pid,
188 const char *process_name);
189 static void s_destroyed(
190 void *data, struct ivi_controller_surface *ivi_controller_surface);
191 static void s_content(void *data,
192 struct ivi_controller_surface *ivi_controller_surface,
193 int32_t content_state);
195 static constexpr ivi_controller_surface_listener listener = {
199 s_destination_rectangle,
211 // | | __ _ _ _ ___ _ __
212 // | |/ _` | | | |/ _ \ '__|
213 // | | (_| | |_| | __/ |
214 // |_|\__,_|\__, |\___|_|
216 struct layer : public wayland_proxy<ivi_controller_layer> {
219 layer(uint32_t i, ivi_controller *c);
222 void event_visibility(int32_t visibility);
223 void event_opacity(wl_fixed_t opacity);
224 void event_source_rectangle(int32_t x, int32_t y, int32_t width,
226 void event_destination_rectangle(int32_t x, int32_t y, int32_t width,
228 void event_configuration(int32_t width, int32_t height);
229 void event_orientation(int32_t orientation);
230 void event_screen(struct wl_output *screen);
231 void event_destroyed();
233 static void s_visibility(void *data,
234 struct ivi_controller_layer *ivi_controller_layer,
236 static void s_opacity(void *data,
237 struct ivi_controller_layer *ivi_controller_layer,
239 static void s_source_rectangle(
240 void *data, struct ivi_controller_layer *ivi_controller_layer, int32_t x,
241 int32_t y, int32_t width, int32_t height);
242 static void s_destination_rectangle(
243 void *data, struct ivi_controller_layer *ivi_controller_layer, int32_t x,
244 int32_t y, int32_t width, int32_t height);
245 static void s_configuration(
246 void *data, struct ivi_controller_layer *ivi_controller_layer,
247 int32_t width, int32_t height);
248 static void s_orientation(void *data,
249 struct ivi_controller_layer *ivi_controller_layer,
250 int32_t orientation);
251 static void s_screen(void *data,
252 struct ivi_controller_layer *ivi_controller_layer,
253 struct wl_output *screen);
254 static void s_destroyed(void *data,
255 struct ivi_controller_layer *ivi_controller_layer);
257 static constexpr ivi_controller_layer_listener listener = {
258 s_visibility, s_opacity,
259 s_source_rectangle, s_destination_rectangle,
260 s_configuration, s_orientation,
261 s_screen, s_destroyed,
266 // ___ ___ _ __ ___ ___ _ __
267 /// __|/ __| '__/ _ \/ _ \ '_ \
268 //\__ \ (__| | | __/ __/ | | |
269 //|___/\___|_| \___|\___|_| |_|
271 struct screen : public wayland_proxy<ivi_controller_screen> {
274 screen(uint32_t i, ivi_controller_screen *p);
278 // ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __
279 // / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
280 // | (_| (_) | | | | |_| | | (_) | | | __/ |
281 // \___\___/|_| |_|\__|_| \___/|_|_|\___|_|
283 struct controller : public wayland_proxy<ivi_controller> {
284 std::map<uint32_t, std::unique_ptr<surface>> surfaces;
285 std::map<uint32_t, std::unique_ptr<layer>> layers;
286 std::map<uint32_t, std::unique_ptr<screen>> screens;
288 controller(wl_registry *r, uint32_t name, uint32_t version);
289 ~controller() override;
291 void event_screen(uint32_t id, ivi_controller_screen *screen);
292 void event_layer(uint32_t id);
293 void event_surface(uint32_t id);
294 void event_error(int32_t oid, int32_t otype, int32_t code, char const *text);
297 static void s_screen(void *data, struct ivi_controller *ivi_controller,
299 struct ivi_controller_screen *screen);
301 static void s_layer(void *data, struct ivi_controller *ivi_controller,
304 static void s_surface(void *data, struct ivi_controller *ivi_controller,
305 uint32_t id_surface);
307 static void s_error(void *data, struct ivi_controller *ivi_controller,
308 int32_t object_id, int32_t object_type,
309 int32_t error_code, const char *error_text);
311 static constexpr ivi_controller_listener listener = {s_screen, s_layer,
316 #endif // !WM_WAYLAND_HPP