From: Marcus Fritzsch Date: Thu, 8 Jun 2017 11:33:47 +0000 (+0200) Subject: cpp, simple wrappers for most of what we need, ivi_* still incomplete X-Git-Tag: 4.99.1~361 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=db95653246560c24ad3c8cb224b3d9321b50af0a;p=staging%2Fwindowmanager.git cpp, simple wrappers for most of what we need, ivi_* still incomplete Signed-off-by: Marcus Fritzsch --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 791e645..cc6c88a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,9 +40,16 @@ macro(wlproto var_basename proto_xml_basename) include_directories(${CMAKE_CURRENT_BINARY_DIR}) endmacro() -add_definitions(-D_GNU_SOURCE) +add_definitions(-D_GNU_SOURCE -DDEBUG_OUTPUT) set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-parameter -std=c99 ${CMAKE_C_FLAGS}") set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-parameter -std=c++14 ${CMAKE_CXX_FLAGS}") +set(SANITIZER_MODE "none" CACHE STRING "Build using a specific sanitizer (e.g. 'address', 'thread', 'leak', 'undefined'), depends on compiler; default none") +if (NOT ${SANITIZER_MODE} STREQUAL "none" AND NOT ${SANITIZER_MODE} STREQUAL "") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=${SANITIZER_MODE} -g -fno-omit-frame-pointer") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${SANITIZER_MODE} -g") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=${SANITIZER_MODE} -g") +endif() + add_subdirectory(src) diff --git a/session.vim b/session.vim index 63ede7e..d02e460 100644 --- a/session.vim +++ b/session.vim @@ -7,18 +7,17 @@ if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == '' let s:wipebuf = bufnr('%') endif set shortmess=aoO -badd +77 src/main.c badd +10 src/CMakeLists.txt badd +46 CMakeLists.txt badd +19 src/util.c badd +14 src/util.h -badd +1 term://.//9732:/usr/bin/fish -badd +1 main.cpp -badd +26 src/main.cpp +badd +36 term://.//9732:/usr/bin/fish +badd +80 src/main.cpp +badd +11 src/genivi.hpp argglobal silent! argdel * argadd src/main.c -edit src/main.cpp +edit src/genivi.hpp set splitbelow splitright wincmd _ | wincmd | vsplit @@ -39,12 +38,12 @@ setlocal fdl=0 setlocal fml=1 setlocal fdn=20 setlocal fen -let s:l = 125 - ((60 * winheight(0) + 33) / 66) +let s:l = 11 - ((10 * winheight(0) + 33) / 66) if s:l < 1 | let s:l = 1 | endif exe s:l normal! zt -125 -normal! 022| +11 +normal! 0 wincmd w argglobal edit term://.//9732:/usr/bin/fish @@ -56,11 +55,11 @@ setlocal fdl=0 setlocal fml=1 setlocal fdn=20 setlocal fen -let s:l = 41 - ((13 * winheight(0) + 33) / 66) +let s:l = 91 - ((63 * winheight(0) + 33) / 66) if s:l < 1 | let s:l = 1 | endif exe s:l normal! zt -41 +91 normal! 0 wincmd w exe 'vert 1resize ' . ((&columns * 137 + 137) / 274) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 86e7ecd..b11d397 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,8 @@ wlproto(IVI_CON ivi-controller) add_executable(winman main.cpp + wayland.cpp + wayland.hpp util.c util.h ${IVI_APP_PROTO} diff --git a/src/main.cpp b/src/main.cpp index 794d9af..0c010ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,171 +1,54 @@ #include "util.h" - -#include "ivi-controller-client-protocol.h" +#include "wayland.hpp" #include #include -#include - #include #include #include #include -struct ivi_surface; -struct ivi_layer; - struct conn { - wl_display *d; - wl_registry *r; - ivi_controller *c; - std::vector> outputs; - std::map> layers; - std::map> surfaces; + std::vector> outputs; + std::unique_ptr c; ~conn(); }; -struct ivi_surface { - ivi_controller_surface *controller; - uint32_t id; - conn *con; - ivi_surface(ivi_controller_surface *c, uint32_t i, conn *co) - : controller(c), id(i), con(co) {} - ~ivi_surface() { ivi_controller_surface_destroy(this->controller, 1); } -}; - -struct ivi_layer { - ivi_controller_layer *controller; - uint32_t id; - conn *con; - ivi_layer(ivi_controller_layer *c, uint32_t i, conn *co) - : controller(c), id(i), con(co) {} - ~ivi_layer() { ivi_controller_layer_destroy(this->controller, 1); } -}; - conn::~conn() { - this->layers.clear(); - this->surfaces.clear(); - ivi_controller_destroy(this->c); this->outputs.clear(); - wl_registry_destroy(this->r); - wl_display_disconnect(this->d); } -static ivi_controller_surface_listener cs_listener = {}; - -static ivi_controller_layer_listener cl_listener = {}; - -static void c_screen(void *data, struct ivi_controller *ivi_controller, - uint32_t id_screen, struct ivi_controller_screen *screen) { - lognotice("ivi_controller @ %p screen %u (%x) @ %p", ivi_controller, - id_screen, id_screen, screen); -} - -static void c_layer(void *data, struct ivi_controller *ivi_controller, - uint32_t id_layer) { - lognotice("ivi_controller @ %p layer %u (%x)", ivi_controller, id_layer, - id_layer); - auto c = static_cast(data); - auto i = std::make_unique( - ivi_controller_layer_create(c->c, id_layer, 0, 0), id_layer, c); - ivi_controller_layer_add_listener(i->controller, &cl_listener, i.get()); - c->layers[id_layer] = std::move(i); -} - -static void c_surface(void *data, struct ivi_controller *ivi_controller, - uint32_t id_surface) { - lognotice("ivi_controller @ %p surface %u (%x)", ivi_controller, id_surface, - id_surface); - auto c = static_cast(data); - auto i = std::make_unique( - ivi_controller_surface_create(c->c, id_surface), id_surface, c); - ivi_controller_surface_add_listener(i->controller, &cs_listener, i.get()); - c->surfaces[id_surface] = std::move(i); -} - -static void c_error(void *data, struct ivi_controller *ivi_controller, - int32_t object_id, int32_t object_type, int32_t error_code, - const char *error_text) { - lognotice("ivi_controller @ %p error o %i t %i c %i text %s", ivi_controller, - object_id, object_type, error_code, error_text); -} - -static struct ivi_controller_listener c_listener = {c_screen, c_layer, - c_surface, c_error}; - -static void o_geometry(void *data, struct wl_output *wl_output, int32_t x, - int32_t y, int32_t physical_width, - int32_t physical_height, int32_t subpixel, - const char *make, const char *model, int32_t transform) { - lognotice("output @ %p x %i y %i w %i h %i spel %x make %s model %s tx %i", - wl_output, x, y, physical_width, physical_height, subpixel, make, - model, transform); -} - -static void o_mode(void *data, struct wl_output *wl_output, uint32_t flags, - int32_t width, int32_t height, int32_t refresh) { - lognotice("output @ %p mode f %x w %i h %i r %i", wl_output, flags, width, - height, refresh); -} - -static void o_done(void *data, struct wl_output *wl_output) { - lognotice("output @ %p done"); -} - -static void o_scale(void *data, struct wl_output *wl_output, int32_t factor) { - lognotice("output @ %p scale %i", wl_output, factor); -} - -static struct wl_output_listener o_listener = {o_geometry, o_mode, o_done, - o_scale}; - -static void r_global(void *data, struct wl_registry *r, uint32_t name, - char const *iface, uint32_t v) { - struct conn *c = static_cast(data); - - if (strcmp(iface, "ivi_controller") == 0) { - c->c = static_cast( - wl_registry_bind(r, name, &ivi_controller_interface, v)); - ivi_controller_add_listener(c->c, &c_listener, c); - } else if (strcmp(iface, "wl_output") == 0) { - auto o = static_cast( - wl_registry_bind(r, name, &wl_output_interface, v)); - c->outputs.emplace_back(std::unique_ptr( - o, wl_output_destroy)); - wl_output_add_listener(o, &o_listener, c); - } else { - lognotice("registry @ %p global n %u i %s v %u", r, name, iface, v); - } -} - -static void r_global_remove(void *data, struct wl_registry *r, uint32_t name) {} - -static struct wl_registry_listener r_listener = {r_global, r_global_remove}; - int main(int argc, char **argv) { lognotice("WinMan ver. %s", WINMAN_VERSION_STRING); if (!getenv("XDG_RUNTIME_DIR")) fatal("Environment variable XDG_RUNTIME_DIR not set"); + auto d = std::make_unique(); + if (!d->d) + fatal("Could not connect to compositor"); + struct conn c = {}; - c.d = wl_display_connect(NULL); - if (!c.d) - fatal("Could not connect to compositor"); - c.r = wl_display_get_registry(c.d); - wl_registry_add_listener(c.r, &r_listener, &c); + d->r->add_global_handler("ivi_controller", [&](wl_registry *r, uint32_t name, uint32_t v) { + c.c = std::make_unique(r, name, v); + }); + + d->r->add_global_handler("wl_output", [&](wl_registry *r, uint32_t name, uint32_t v) { + c.outputs.emplace_back(std::make_unique(r, name, v)); + }); // First level objects - wl_display_roundtrip(c.d); + d->roundtrip(); // Second level objects - wl_display_roundtrip(c.d); + d->roundtrip(); + // Third level objects + /* wl_display_roundtrip(c.d); */ if (!c.c) fatal("ivi_controller global not available"); - // main loop return 0; diff --git a/src/util.c b/src/util.c index ee4b7b6..0ce7c27 100644 --- a/src/util.c +++ b/src/util.c @@ -53,3 +53,12 @@ void fatal(char const *fmt, ...) { va_end(a); abort(); } + +#ifdef DEBUG_OUTPUT +void logdebug(char const *fmt, ...) { + va_list a; + va_start(a, fmt); + log_("debug", stdout, fmt, a); + va_end(a); +} +#endif diff --git a/src/util.h b/src/util.h index 27d1015..600c638 100644 --- a/src/util.h +++ b/src/util.h @@ -9,6 +9,12 @@ void lognotice(char const *fmt, ...); void logerror(char const *fmt, ...); void fatal(char const *fmt, ...); +#ifdef DEBUG_OUTPUT +void logdebug(char const *fmt, ...); +#else +inline void logdebug(char const *fmt, ...) {} +#endif + #ifdef __cplusplus } #endif diff --git a/src/wayland.cpp b/src/wayland.cpp new file mode 100644 index 0000000..c88b5c6 --- /dev/null +++ b/src/wayland.cpp @@ -0,0 +1,242 @@ +#include "wayland.hpp" + +// _ +// _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ __ _| | +// | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / | +// | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ \ V V /| | +// |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| \_/\_/ |_| +// |_| +namespace wl { + +// _ _ _ +// __| (_)___ _ __ | | __ _ _ _ +// / _` | / __| '_ \| |/ _` | | | | +// | (_| | \__ \ |_) | | (_| | |_| | +// \__,_|_|___/ .__/|_|\__,_|\__, | +// |_| |___/ +display::display() + : d(std::unique_ptr( + wl_display_connect(NULL), wl_display_disconnect)), + r(std::make_unique(d.get())) {} + +void display::roundtrip() { wl_display_roundtrip(this->d.get()); } + +// _ _ +// _ __ ___ __ _(_)___| |_ _ __ _ _ +// | '__/ _ \/ _` | / __| __| '__| | | | +// | | | __/ (_| | \__ \ |_| | | |_| | +// |_| \___|\__, |_|___/\__|_| \__, | +// |___/ |___/ +registry::registry(wl_display *d) : wayland_proxy(wl_display_get_registry(d)) { + wl_registry_add_listener(this->proxy, &listener, this); +} + +registry::~registry() { + wl_registry_destroy(this->proxy); + this->proxy = nullptr; +} + +void registry::add_global_handler(char const *iface, binder bind) { + this->bindings[iface] = bind; +} + +void registry::event_global(uint32_t name, char const *iface, uint32_t v) { + auto b = this->bindings.find(iface); + if (b != this->bindings.end()) + b->second(this->proxy, name, v); + else + logdebug("registry @ %p global n %u i %s v %u", this->proxy, name, iface, + v); +} + +void registry::event_global_remove(uint32_t name) {} + +constexpr wl_registry_listener registry::listener; + +void registry::s_global(void *data, struct wl_registry *r, uint32_t name, + char const *iface, uint32_t v) { + static_cast(data)->event_global(name, iface, v); +} + +void registry::s_global_remove(void *data, struct wl_registry *r, + uint32_t name) { + static_cast(data)->event_global_remove(name); +} + +// _ _ +// ___ _ _| |_ _ __ _ _| |_ +// / _ \| | | | __| '_ \| | | | __| +// | (_) | |_| | |_| |_) | |_| | |_ +// \___/ \__,_|\__| .__/ \__,_|\__| +// |_| +output::output(wl_registry *r, uint32_t name, uint32_t v) + : wayland_proxy(wl_registry_bind(r, name, &wl_output_interface, v)) { + wl_output_add_listener(this->proxy, &listener, this); +} + +void output::event_geometry(int32_t x, int32_t y, int32_t pw, int32_t ph, + int32_t subpel, char const *make, char const *model, + int32_t tx) { + logdebug( + "wl::output @ %p x %i y %i w %i h %i spel %x make %s model %s tx %i", + this->proxy, x, y, pw, ph, subpel, make, model, tx); +} + +void output::event_mode(uint32_t flags, int32_t w, int32_t h, int32_t r) { + logdebug("wl::output @ %p mode f %x w %i h %i r %i", this->proxy, flags, w, + h, r); +} + +void output::event_done() { logdebug("wl::output @ %p done", this->proxy); } + +void output::event_scale(int32_t factor) { + logdebug("wl::output @ %p scale %i", this->proxy, factor); +} + +void output::s_geometry(void *data, struct wl_output *wl_output, int32_t x, + int32_t y, int32_t physical_width, + int32_t physical_height, int32_t subpixel, + const char *make, const char *model, + int32_t transform) { + static_cast(data)->event_geometry( + x, y, physical_width, physical_height, subpixel, make, model, transform); +} + +void output::s_mode(void *data, struct wl_output *wl_output, uint32_t flags, + int32_t width, int32_t height, int32_t refresh) { + static_cast(data)->event_mode(flags, width, height, refresh); +} + +void output::s_done(void *data, struct wl_output *wl_output) { + static_cast(data)->event_done(); +} + +void output::s_scale(void *data, struct wl_output *wl_output, int32_t factor) { + static_cast(data)->event_scale(factor); +} + +constexpr wl_output_listener output::listener; +} + +// _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ +// | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ +// | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ +// |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| +// |_| +// _ _ +// __ _ ___ _ __ (_)_ _(_) +// / _` |/ _ \ '_ \| \ \ / / | +// | (_| | __/ | | | |\ V /| | +// \__, |\___|_| |_|_| \_/ |_| +// |___/ +namespace genivi { + +// _ _ _ +// ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __ +// / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__| +// | (_| (_) | | | | |_| | | (_) | | | __/ | +// \___\___/|_| |_|\__|_| \___/|_|_|\___|_| +// +controller::controller(wl_registry *r, uint32_t name, uint32_t version) + : wayland_proxy( + wl_registry_bind(r, name, &ivi_controller_interface, version)) { + ivi_controller_add_listener(this->proxy, &listener, this); +} + +controller::~controller() {} + +void controller::event_screen(uint32_t id, + struct ivi_controller_screen *screen) { + logdebug("genivi::controller @ %p screen %u (%x) @ %p", this->proxy, id, id, + screen); + this->screens[id] = std::make_unique(id, screen); +} + +void controller::event_layer(uint32_t id) { + logdebug("genivi::controller @ %p layer %u (%x)", this->proxy, id, id); + this->layers[id] = std::make_unique(id, this->proxy); +} + +void controller::event_surface(uint32_t id) { + logdebug("genivi::controller @ %p surface %u (%x)", this->proxy, id, id); + this->surfaces[id] = std::make_unique(id, this->proxy); +} + +void controller::event_error(int32_t object_id, int32_t object_type, + int32_t error_code, const char *error_text) { + logdebug("genivi::controller @ %p error o %i t %i c %i text %s", this->proxy, + object_id, object_type, error_code, error_text); +} + +void controller::s_screen(void *data, struct ivi_controller *ivi_controller, + uint32_t id_screen, + struct ivi_controller_screen *screen) { + static_cast(data)->event_screen(id_screen, screen); +} + +void controller::s_layer(void *data, struct ivi_controller *ivi_controller, + uint32_t id_layer) { + static_cast(data)->event_layer(id_layer); +} + +void controller::s_surface(void *data, struct ivi_controller *ivi_controller, + uint32_t id_surface) { + static_cast(data)->event_surface(id_surface); +} + +void controller::s_error(void *data, struct ivi_controller *ivi_controller, + int32_t object_id, int32_t object_type, + int32_t error_code, const char *error_text) { + static_cast(data)->event_error(object_id, object_type, + error_code, error_text); +} + +constexpr ivi_controller_listener controller::listener; + +// _ +// | | __ _ _ _ ___ _ __ +// | |/ _` | | | |/ _ \ '__| +// | | (_| | |_| | __/ | +// |_|\__,_|\__, |\___|_| +// |___/ +layer::layer(uint32_t i, ivi_controller *c) + : wayland_proxy(ivi_controller_layer_create(c, i, 0, 0)), id(i) { + ivi_controller_layer_add_listener(this->proxy, &listener, this); +} + +layer::~layer() { + logdebug("%s layer %i @ %p", __func__, this->id, this->proxy); + ivi_controller_layer_destroy(this->proxy, 1); + this->proxy = nullptr; +} + +constexpr ivi_controller_layer_listener layer::listener; + +// __ +// ___ _ _ _ __ / _| __ _ ___ ___ +// / __| | | | '__| |_ / _` |/ __/ _ \ +// \__ \ |_| | | | _| (_| | (_| __/ +// |___/\__,_|_| |_| \__,_|\___\___| +// +surface::surface(uint32_t i, ivi_controller *c) + : wayland_proxy(ivi_controller_surface_create(c, i)), id(i) { + ivi_controller_surface_add_listener(this->proxy, &listener, this); +} + +surface::~surface() { + logdebug("%s surface %i @ %p", __func__, this->id, this->proxy); + ivi_controller_surface_destroy(this->proxy, 1); + this->proxy = nullptr; +} + +constexpr ivi_controller_surface_listener surface::listener; + +// +// ___ ___ _ __ ___ ___ _ __ +/// __|/ __| '__/ _ \/ _ \ '_ \ +//\__ \ (__| | | __/ __/ | | | +//|___/\___|_| \___|\___|_| |_| +// +screen::screen(uint32_t i, ivi_controller_screen *p) + : wayland_proxy(p), id(i) {} +} diff --git a/src/wayland.hpp b/src/wayland.hpp new file mode 100644 index 0000000..5cafd1a --- /dev/null +++ b/src/wayland.hpp @@ -0,0 +1,212 @@ +#ifndef WM_WAYLAND_HPP +#define WM_WAYLAND_HPP + +#include "ivi-controller-client-protocol.h" + +#include "util.h" + +#include +#include +#include + +// _ _ +// __ ____ _ _ _| | __ _ _ __ __| | _ __ _ __ _____ ___ _ +// \ \ /\ / / _` | | | | |/ _` | '_ \ / _` | | '_ \| '__/ _ \ \/ / | | | +// \ V V / (_| | |_| | | (_| | | | | (_| | | |_) | | | (_) > <| |_| | +// \_/\_/ \__,_|\__, |_|\__,_|_| |_|\__,_|____| .__/|_| \___/_/\_\\__, | +// |___/ |_____|_| |___/ +template +struct wayland_proxy { + ProxyT *proxy; + + wayland_proxy(void *p) : proxy(static_cast(p)) {} + + virtual ~wayland_proxy() { + // If this is the nullptr, then it means it already was destroyed by a + // custom wayland dtor + logdebug("%s %p @ %p", __func__, this, this->proxy); + if (proxy) { + wl_proxy_destroy(reinterpret_cast(proxy)); + } + } +}; + +// _ +// _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ __ _| | +// | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / | +// | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ \ V V /| | +// |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| \_/\_/ |_| +// |_| +namespace wl { +struct registry; + +// _ _ _ +// __| (_)___ _ __ | | __ _ _ _ +// / _` | / __| '_ \| |/ _` | | | | +// | (_| | \__ \ |_) | | (_| | |_| | +// \__,_|_|___/ .__/|_|\__,_|\__, | +// |_| |___/ +struct display { + std::unique_ptr d; + std::unique_ptr r; + + display(); + void roundtrip(); +}; + +// _ _ +// _ __ ___ __ _(_)___| |_ _ __ _ _ +// | '__/ _ \/ _` | / __| __| '__| | | | +// | | | __/ (_| | \__ \ |_| | | |_| | +// |_| \___|\__, |_|___/\__|_| \__, | +// |___/ |___/ +struct registry : public wayland_proxy { + typedef std::function binder; + std::map bindings; + + registry(wl_display *d); + ~registry(); + + void add_global_handler(char const *iface, binder bind); + + void event_global(uint32_t name, char const *iface, uint32_t v); + void event_global_remove(uint32_t name); + + static void s_global(void *data, struct wl_registry *r, uint32_t name, + char const *iface, uint32_t v); + + static void s_global_remove(void *data, struct wl_registry *r, + uint32_t name); + + static constexpr wl_registry_listener listener = {s_global, s_global_remove}; +}; + +// _ _ +// ___ _ _| |_ _ __ _ _| |_ +// / _ \| | | | __| '_ \| | | | __| +// | (_) | |_| | |_| |_) | |_| | |_ +// \___/ \__,_|\__| .__/ \__,_|\__| +// |_| +struct output : wayland_proxy { + output(wl_registry *registry, uint32_t name, uint32_t version); + + void event_geometry(int32_t x, int32_t y, int32_t pw, int32_t ph, + int32_t subpel, char const *make, char const *model, + int32_t tx); + void event_mode(uint32_t flags, int32_t w, int32_t h, int32_t r); + void event_done(); + void event_scale(int32_t factor); + + static void s_geometry(void *data, struct wl_output *wl_output, int32_t x, + int32_t y, int32_t physical_width, + int32_t physical_height, int32_t subpixel, + const char *make, const char *model, + int32_t transform); + + static void s_mode(void *data, struct wl_output *wl_output, uint32_t flags, + int32_t width, int32_t height, int32_t refresh); + + static void s_done(void *data, struct wl_output *wl_output); + + static void s_scale(void *data, struct wl_output *wl_output, int32_t factor); + + static constexpr wl_output_listener listener = {s_geometry, s_mode, s_done, + s_scale}; +}; +}; + +// _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ +// | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ +// | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ +// |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| +// |_| +// _ _ +// __ _ ___ _ __ (_)_ _(_) +// / _` |/ _ \ '_ \| \ \ / / | +// | (_| | __/ | | | |\ V /| | +// \__, |\___|_| |_|_| \_/ |_| +// |___/ +namespace genivi { + +// __ +// ___ _ _ _ __ / _| __ _ ___ ___ +// / __| | | | '__| |_ / _` |/ __/ _ \ +// \__ \ |_| | | | _| (_| | (_| __/ +// |___/\__,_|_| |_| \__,_|\___\___| +// +struct surface : public wayland_proxy { + uint32_t id; + + surface(uint32_t i, ivi_controller *c); + ~surface() override; + + static constexpr ivi_controller_surface_listener listener = {}; +}; + +// _ +// | | __ _ _ _ ___ _ __ +// | |/ _` | | | |/ _ \ '__| +// | | (_| | |_| | __/ | +// |_|\__,_|\__, |\___|_| +// |___/ +struct layer : public wayland_proxy { + uint32_t id; + + layer(uint32_t i, ivi_controller *c); + ~layer() override; + + static constexpr ivi_controller_layer_listener listener = {}; +}; + +// +// ___ ___ _ __ ___ ___ _ __ +/// __|/ __| '__/ _ \/ _ \ '_ \ +//\__ \ (__| | | __/ __/ | | | +//|___/\___|_| \___|\___|_| |_| +// +struct screen : public wayland_proxy { + uint32_t id; + + screen(uint32_t i, ivi_controller_screen *p); +}; + +// _ _ _ +// ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __ +// / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__| +// | (_| (_) | | | | |_| | | (_) | | | __/ | +// \___\___/|_| |_|\__|_| \___/|_|_|\___|_| +// +struct controller : public wayland_proxy { + std::map> surfaces; + std::map> layers; + std::map> screens; + + controller(wl_registry *r, uint32_t name, uint32_t version); + ~controller() override; + + void event_screen(uint32_t id, ivi_controller_screen *screen); + void event_layer(uint32_t id); + void event_surface(uint32_t id); + void event_error(int32_t oid, int32_t otype, int32_t code, char const *text); + + // thunks... + static void s_screen(void *data, struct ivi_controller *ivi_controller, + uint32_t id_screen, + struct ivi_controller_screen *screen); + + static void s_layer(void *data, struct ivi_controller *ivi_controller, + uint32_t id_layer); + + static void s_surface(void *data, struct ivi_controller *ivi_controller, + uint32_t id_surface); + + static void s_error(void *data, struct ivi_controller *ivi_controller, + int32_t object_id, int32_t object_type, + int32_t error_code, const char *error_text); + + static constexpr ivi_controller_listener listener = {s_screen, s_layer, + s_surface, s_error}; +}; +} + +#endif // !WM_WAYLAND_HPP