2 * Copyright (C) 2017 Mentor Graphics Development (Deutschland) GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "wayland.hpp"
23 using namespace std::chrono_literals;
25 // pretend we are a WM ...
29 controller_hooks chooks;
30 std::unique_ptr<wl::display> display;
31 std::unique_ptr<genivi::controller> controller;
32 std::vector<std::unique_ptr<wl::output>> outputs;
36 void surface_visibility(uint32_t surface_id, uint32_t v);
37 void surface_destination_rectangle(uint32_t surface_id, uint32_t x,
38 uint32_t y, uint32_t w, uint32_t h);
39 void try_fix(uint32_t surface_id);
42 void controller_hooks::surface_created(uint32_t /*surface_id*/) {}
44 void controller_hooks::surface_removed(uint32_t /*surface_id*/) {}
46 void controller_hooks::surface_visibility(uint32_t surface_id, uint32_t v) {
47 this->app->surface_visibility(surface_id, v);
50 void controller_hooks::surface_destination_rectangle(uint32_t surface_id,
51 uint32_t x, uint32_t y,
52 uint32_t w, uint32_t h) {
53 this->app->surface_destination_rectangle(surface_id, x, y, w, h);
56 App::App() : chooks{this}, display{new wl::display}, controller{}, outputs{} {
57 // The same init, the WM does, at least we can reuse the wayland stuff
58 if (!this->display->ok()) {
62 this->display->add_global_handler(
63 "wl_output", [this](wl_registry *r, uint32_t name, uint32_t v) {
64 this->outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
67 this->display->add_global_handler(
68 "ivi_controller", [this](wl_registry *r, uint32_t name, uint32_t v) {
70 std::make_unique<struct genivi::controller>(r, name, v);
72 // Init controller hooks
73 this->controller->chooks = &this->chooks;
75 this->controller->add_proxy_to_id_mapping(
76 this->outputs.back()->proxy.get(),
77 wl_proxy_get_id(reinterpret_cast<struct wl_proxy *>(
78 this->outputs.back()->proxy.get())));
81 for (int i : {1, 2, 3}) {
82 this->display->roundtrip();
87 this->controller->commit_changes();
88 this->display->roundtrip(); // read: flush()++
91 void App::surface_visibility(uint32_t surface_id, uint32_t v) {
92 fprintf(stderr, "surface %u visibility %u\n", surface_id, v);
95 this->try_fix(surface_id);
99 void App::surface_destination_rectangle(uint32_t surface_id, uint32_t x,
100 uint32_t y, uint32_t w, uint32_t h) {
101 fprintf(stderr, "surface %u dst %u %u %u %u\n", surface_id, x, y, w, h);
103 if (w != 1 && h != 1 && this->controller->sprops[surface_id].visibility != 0) {
104 this->try_fix(surface_id);
108 void App::try_fix(uint32_t surface_id) {
109 this->controller->surfaces[surface_id]->set_opacity(255);
111 std::this_thread::sleep_for(200ms);
112 this->controller->surfaces[surface_id]->set_opacity(256);
118 int main(int /*argc*/, char ** /*argv*/) {
120 if (!app.display->ok()) {
121 fputs("Could not init wayland display\n", stderr);
124 while (app.display->dispatch() != -1) {