aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.cpp
blob: 5e74ed8e8da9043e0ae7174bc3e80906f80e8c0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "util.h"
#include "wayland.hpp"

#include <stdlib.h>
#include <string.h>

#include <map>
#include <memory>
#include <string>
#include <vector>

struct conn {
   std::vector<std::unique_ptr<wl::output>> outputs;
   std::unique_ptr<genivi::controller> c;
};

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<wl::display>();
   if (!d->ok())
      fatal("Could not connect to compositor");

   struct conn c = {};

   d->r->add_global_handler(
      "ivi_controller", [&](wl_registry *r, uint32_t name, uint32_t v) {
         c.c = std::make_unique<genivi::controller>(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<wl::output>(r, name, v));
      });

   // First level objects
   d->roundtrip();
   // Second level objects
   d->roundtrip();
   // Third level objects
   d->roundtrip();

   if (!c.c)
      fatal("ivi_controller global not available");

   /* while (1) { */
   /*    int ret = d->dispatch(); */
   /*    if (ret != 0) */
   /*       break; */
   /* } */

   return 0;
}