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
27 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;
58 // _ __ ___ __ _(_)___| |_ _ __ _ _
59 // | '__/ _ \/ _` | / __| __| '__| | | |
60 // | | | __/ (_| | \__ \ |_| | | |_| |
61 // |_| \___|\__, |_|___/\__|_| \__, |
63 struct registry : public wayland_proxy<wl_registry> {
64 typedef std::function<void(wl_registry *, uint32_t, uint32_t)> binder;
65 std::map<std::string, binder> bindings;
67 registry(wl_display *d);
70 void add_global_handler(char const *iface, binder bind);
72 void event_global(uint32_t name, char const *iface, uint32_t v);
73 void event_global_remove(uint32_t name);
75 static void s_global(void *data, struct wl_registry *r, uint32_t name,
76 char const *iface, uint32_t v);
78 static void s_global_remove(void *data, struct wl_registry *r,
81 static constexpr wl_registry_listener listener = {s_global, s_global_remove};
85 // ___ _ _| |_ _ __ _ _| |_
86 // / _ \| | | | __| '_ \| | | | __|
87 // | (_) | |_| | |_| |_) | |_| | |_
88 // \___/ \__,_|\__| .__/ \__,_|\__|
90 struct output : wayland_proxy<wl_output> {
91 output(wl_registry *registry, uint32_t name, uint32_t version);
93 void event_geometry(int32_t x, int32_t y, int32_t pw, int32_t ph,
94 int32_t subpel, char const *make, char const *model,
96 void event_mode(uint32_t flags, int32_t w, int32_t h, int32_t r);
98 void event_scale(int32_t factor);
100 static void s_geometry(void *data, struct wl_output *wl_output, int32_t x,
101 int32_t y, int32_t physical_width,
102 int32_t physical_height, int32_t subpixel,
103 const char *make, const char *model,
106 static void s_mode(void *data, struct wl_output *wl_output, uint32_t flags,
107 int32_t width, int32_t height, int32_t refresh);
109 static void s_done(void *data, struct wl_output *wl_output);
111 static void s_scale(void *data, struct wl_output *wl_output, int32_t factor);
113 static constexpr wl_output_listener listener = {s_geometry, s_mode, s_done,
118 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___
119 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
120 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/
121 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
124 // __ _ ___ _ __ (_)_ _(_)
125 // / _` |/ _ \ '_ \| \ \ / / |
126 // | (_| | __/ | | | |\ V /| |
127 // \__, |\___|_| |_|_| \_/ |_|
132 // ___ _ _ _ __ / _| __ _ ___ ___
133 // / __| | | | '__| |_ / _` |/ __/ _ \
134 // \__ \ |_| | | | _| (_| | (_| __/
135 // |___/\__,_|_| |_| \__,_|\___\___|
137 struct surface : public wayland_proxy<ivi_controller_surface> {
140 surface(uint32_t i, ivi_controller *c);
143 static constexpr ivi_controller_surface_listener listener = {};
147 // | | __ _ _ _ ___ _ __
148 // | |/ _` | | | |/ _ \ '__|
149 // | | (_| | |_| | __/ |
150 // |_|\__,_|\__, |\___|_|
152 struct layer : public wayland_proxy<ivi_controller_layer> {
155 layer(uint32_t i, ivi_controller *c);
158 static constexpr ivi_controller_layer_listener listener = {};
162 // ___ ___ _ __ ___ ___ _ __
163 /// __|/ __| '__/ _ \/ _ \ '_ \
164 //\__ \ (__| | | __/ __/ | | |
165 //|___/\___|_| \___|\___|_| |_|
167 struct screen : public wayland_proxy<ivi_controller_screen> {
170 screen(uint32_t i, ivi_controller_screen *p);
174 // ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __
175 // / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
176 // | (_| (_) | | | | |_| | | (_) | | | __/ |
177 // \___\___/|_| |_|\__|_| \___/|_|_|\___|_|
179 struct controller : public wayland_proxy<ivi_controller> {
180 std::map<uint32_t, std::unique_ptr<surface>> surfaces;
181 std::map<uint32_t, std::unique_ptr<layer>> layers;
182 std::map<uint32_t, std::unique_ptr<screen>> screens;
184 controller(wl_registry *r, uint32_t name, uint32_t version);
185 ~controller() override;
187 void event_screen(uint32_t id, ivi_controller_screen *screen);
188 void event_layer(uint32_t id);
189 void event_surface(uint32_t id);
190 void event_error(int32_t oid, int32_t otype, int32_t code, char const *text);
193 static void s_screen(void *data, struct ivi_controller *ivi_controller,
195 struct ivi_controller_screen *screen);
197 static void s_layer(void *data, struct ivi_controller *ivi_controller,
200 static void s_surface(void *data, struct ivi_controller *ivi_controller,
201 uint32_t id_surface);
203 static void s_error(void *data, struct ivi_controller *ivi_controller,
204 int32_t object_id, int32_t object_type,
205 int32_t error_code, const char *error_text);
207 static constexpr ivi_controller_listener listener = {s_screen, s_layer,
212 #endif // !WM_WAYLAND_HPP