1d9233841ca0d4d412c8eeab380c7359514ee312
[staging/windowmanager.git] / src / main.cpp
1 #include "util.h"
2 #include "wayland.hpp"
3
4 #include <stdlib.h>
5 #include <string.h>
6
7 #include <map>
8 #include <memory>
9 #include <string>
10 #include <vector>
11
12 struct conn {
13    std::vector<std::unique_ptr<wl::output>> outputs;
14    std::unique_ptr<genivi::controller> c;
15 };
16
17 int main(int argc, char **argv) {
18    lognotice("WinMan ver. %s", WINMAN_VERSION_STRING);
19
20    if (!getenv("XDG_RUNTIME_DIR"))
21       fatal("Environment variable XDG_RUNTIME_DIR not set");
22
23    auto d = std::make_unique<wl::display>();
24    if (!d->ok())
25       fatal("Could not connect to compositor");
26
27    struct conn c = {};
28
29    d->r->add_global_handler(
30       "ivi_controller", [&](wl_registry *r, uint32_t name, uint32_t v) {
31          c.c = std::make_unique<genivi::controller>(r, name, v);
32       });
33
34    d->r->add_global_handler(
35       "wl_output", [&](wl_registry *r, uint32_t name, uint32_t v) {
36          c.outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
37       });
38
39    // First level objects
40    d->roundtrip();
41    // Second level objects
42    d->roundtrip();
43    // Third level objects
44    d->roundtrip();
45
46    if (!c.c)
47       fatal("ivi_controller global not available");
48    // main loop
49
50    return 0;
51 }