aboutsummaryrefslogtreecommitdiffstats
path: root/src/redraw_fixer.cpp
blob: 94964af3939846bd8ab5ccabee74cfc2feb76e4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
/*
 * Copyright (C) 2017 Mentor Graphics Development (Deutschland) GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "wayland.hpp"

#include <algorithm>
#include <chrono>
#include <thread>

using namespace std::chrono_literals;

// pretend we are a WM ...
namespace wm {

struct App {
   controller_hooks chooks;
   std::unique_ptr<wl::display> display;
   std::unique_ptr<genivi::controller> controller;
   std::vector<std::unique_ptr<wl::output>> outputs;

   App();
   void commit();
   void surface_visibility(uint32_t surface_id, uint32_t v);
   void surface_destination_rectangle(uint32_t surface_id, uint32_t x,
                                      uint32_t y, uint32_t w, uint32_t h);
   void try_fix(uint32_t surface_id);
};

void controller_hooks::surface_created(uint32_t /*surface_id*/) {}

void controller_hooks::surface_removed(uint32_t /*surface_id*/) {}

void controller_hooks::surface_visibility(uint32_t surface_id, uint32_t v) {
   this->app->surface_visibility(surface_id, v);
}

void controller_hooks::surface_destination_rectangle(uint32_t surface_id,
                                                     uint32_t x, uint32_t y,
                                                     uint32_t w, uint32_t h) {
   this->app->surface_destination_rectangle(surface_id, x, y, w, h);
}

App::App() : chooks{this}, display{new wl::display}, controller{}, outputs{} {
   // The same init, the WM does, at least we can reuse the wayland stuff
   if (!this->display->ok()) {
      return;
   }

   this->display->add_global_handler(
      "wl_output", [this](wl_registry *r, uint32_t name, uint32_t v) {
         this->outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
      });

   this->display->add_global_handler(
      "ivi_controller", [this](wl_registry *r, uint32_t name, uint32_t v) {
         this->controller =
            std::make_unique<struct genivi::controller>(r, name, v);

         // Init controller hooks
         this->controller->chooks = &this->chooks;

         this->controller->add_proxy_to_id_mapping(
            this->outputs.back()->proxy.get(),
            wl_proxy_get_id(reinterpret_cast<struct wl_proxy *>(
               this->outputs.back()->proxy.get())));
      });

   for (int i : {1, 2, 3}) {
      this->display->roundtrip();
}
}

void App::commit() {
   this->controller->commit_changes();
   this->display->roundtrip();  // read: flush()++
}

void App::surface_visibility(uint32_t surface_id, uint32_t v) {
   fprintf(stderr, "surface %u visibility %u\n", surface_id, v);

   if (v == 1) {
      this->try_fix(surface_id);
   }
}

void App::surface_destination_rectangle(uint32_t surface_id, uint32_t x,
                                        uint32_t y, uint32_t w, uint32_t h) {
   fprintf(stderr, "surface %u dst %u %u %u %u\n", surface_id, x, y, w, h);

   if (w != 1 && h != 1 && this->controller->sprops[surface_id].visibility != 0) {
      this->try_fix(surface_id);
   }
}

void App::try_fix(uint32_t surface_id) {
   this->controller->surfaces[surface_id]->set_opacity(255);
   this->commit();
   std::this_thread::sleep_for(200ms);
   this->controller->surfaces[surface_id]->set_opacity(256);
   this->commit();
}

}  // namespace wm

int main(int /*argc*/, char ** /*argv*/) {
   wm::App app;
   if (!app.display->ok()) {
      fputs("Could not init wayland display\n", stderr);
      return 1;
   }
   while (app.display->dispatch() != -1) {
      ;
   }
   return 0;
}