2 // Created by mfritzsc on 9/11/17.
11 using namespace std::chrono_literals;
13 // pretend we are a WM ...
17 controller_hooks chooks;
18 std::unique_ptr<wl::display> display;
19 std::unique_ptr<genivi::controller> controller;
20 std::vector<std::unique_ptr<wl::output>> outputs;
24 void surface_created(uint32_t surface_id);
25 void surface_removed(uint32_t surface_id);
26 void surface_visibility(uint32_t surface_id, uint32_t v);
27 void surface_destination_rectangle(uint32_t surface_id, uint32_t x,
28 uint32_t y, uint32_t w, uint32_t h);
29 void try_fix(uint32_t surface_id);
32 void controller_hooks::surface_created(uint32_t surface_id) {
33 this->app->surface_created(surface_id);
36 void controller_hooks::surface_removed(uint32_t surface_id) {
37 this->app->surface_removed(surface_id);
40 void controller_hooks::surface_visibility(uint32_t surface_id, uint32_t v) {
41 this->app->surface_visibility(surface_id, v);
44 void controller_hooks::surface_destination_rectangle(uint32_t surface_id,
45 uint32_t x, uint32_t y,
46 uint32_t w, uint32_t h) {
47 this->app->surface_destination_rectangle(surface_id, x, y, w, h);
50 App::App() : chooks{this}, display{new wl::display}, controller{} {
51 // The same init, the WM does, at least we can reuse the wayland stuff
52 if (this->display->ok()) {
53 this->display->add_global_handler("wl_output", [this](wl_registry *r,
56 this->outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
59 this->display->add_global_handler(
60 "ivi_controller", [this](wl_registry *r, uint32_t name, uint32_t v) {
62 std::make_unique<struct genivi::controller>(r, name, v);
64 // Init controller hooks
65 this->controller->chooks = &this->chooks;
67 // XXX: This protocol needs the output, so lets just add our
70 this->controller->add_proxy_to_id_mapping(
71 this->outputs.back()->proxy.get(),
72 wl_proxy_get_id(reinterpret_cast<struct wl_proxy *>(
73 this->outputs.back()->proxy.get())));
76 for (int i : {1, 2, 3})
77 this->display->roundtrip();
82 this->controller->commit_changes();
83 this->display->dispatch(); // read: flush()++
86 void App::surface_created(uint32_t surface_id) { }
88 void App::surface_removed(uint32_t surface_id) { }
90 void App::surface_visibility(uint32_t surface_id, uint32_t v) {
91 fprintf(stderr, "surface %u visibility %u\n", surface_id, v);
94 this->try_fix(surface_id);
98 void App::surface_destination_rectangle(uint32_t surface_id, uint32_t x,
99 uint32_t y, uint32_t w, uint32_t h) {
100 fprintf(stderr, "surface %u dst %u %u %u %u\n", surface_id, x, y, w, h);
102 if (w != 1 && h != 1) {
103 this->try_fix(surface_id);
107 void App::try_fix(uint32_t surface_id) {
108 this->controller->surfaces[surface_id]->set_opacity(255);
110 std::this_thread::sleep_for(200ms);
111 this->controller->surfaces[surface_id]->set_opacity(256);
117 int main(int argc, char **argv) {
119 if (!app.display->ok()) {
120 fputs("Could not init wayland display\n", stderr);
123 while (app.display->dispatch() != -1)