cpp, simple wrappers for most of what we need, ivi_* still incomplete
[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    ~conn();
17 };
18
19 conn::~conn() {
20    this->outputs.clear();
21 }
22
23 int main(int argc, char **argv) {
24    lognotice("WinMan ver. %s", WINMAN_VERSION_STRING);
25
26    if (!getenv("XDG_RUNTIME_DIR"))
27       fatal("Environment variable XDG_RUNTIME_DIR not set");
28
29    auto d = std::make_unique<wl::display>();
30    if (!d->d)
31       fatal("Could not connect to compositor");
32
33    struct conn c = {};
34
35    d->r->add_global_handler("ivi_controller", [&](wl_registry *r, uint32_t name, uint32_t v) {
36       c.c = std::make_unique<genivi::controller>(r, name, v);
37    });
38
39    d->r->add_global_handler("wl_output", [&](wl_registry *r, uint32_t name, uint32_t v) {
40       c.outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
41    });
42
43    // First level objects
44    d->roundtrip();
45    // Second level objects
46    d->roundtrip();
47    // Third level objects
48    /* wl_display_roundtrip(c.d); */
49
50    if (!c.c)
51       fatal("ivi_controller global not available");
52    // main loop
53
54    return 0;
55 }