7 #include <sys/signalfd.h>
12 std::vector<std::unique_ptr<wl::output>> outputs;
13 std::unique_ptr<genivi::controller> c;
18 // (_)_ __ (_) |_ | | __ _ _ _ ___ _ _| |_ / /\ \
19 // | | '_ \| | __| | |/ _` | | | |/ _ \| | | | __| | | |
20 // | | | | | | |_ | | (_| | |_| | (_) | |_| | |_| | | |
21 // |_|_| |_|_|\__|___|_|\__,_|\__, |\___/ \__,_|\__| | | |
22 // |_____| |___/ \_\/_/
23 char const *init_layout(struct connection &c) {
25 return "ivi_controller global not available";
28 if (c.outputs.empty()) {
29 return "no output was set up!";
32 auto &o = c.outputs.front();
33 auto &s = c.c->screens.begin()->second;
34 auto &layers = c.c->layers;
36 // XXX: Write output dimensions to ivi controller...
37 c.c->output_size = genivi::size{uint32_t(o->width), uint32_t(o->height)};
45 // Setup our dummy scene...
46 c.c->layer_create(100, 0, 0); // bottom layer, anything else
47 c.c->layer_create(1000, 0, 0); // top layer, mandelbrot
49 auto &l100 = c.c->layers[100];
50 auto &l1k = c.c->layers[1000];
52 // Set layers fullscreen
53 l100->set_destination_rectangle(0, 0, o->width, o->height);
54 l1k->set_destination_rectangle(0, 0, o->width, o->height);
55 l100->set_visibility(1);
56 l1k->set_visibility(1);
58 // Add layers to screen
59 s->set_render_order({100, 1000});
61 c.c->commit_changes();
62 // Note: this does not flush the display!
69 // _ __ ___ __ _(_)_ __ / /\ \
70 // | '_ ` _ \ / _` | | '_ \| | | |
71 // | | | | | | (_| | | | | | | | |
72 // |_| |_| |_|\__,_|_|_| |_| | | |
74 int main(int /*argc*/, char ** /*argv*/) {
75 lognotice("WinMan ver. %s", WINMAN_VERSION_STRING);
77 if (getenv("XDG_RUNTIME_DIR") == nullptr) {
78 fatal("Environment variable XDG_RUNTIME_DIR not set");
81 struct wl::display d {};
83 fatal("Could not connect to compositor");
86 struct connection c {};
88 d.r.add_global_handler(
89 "wl_output", [&c](wl_registry *r, uint32_t name, uint32_t v) {
90 c.outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
93 d.r.add_global_handler(
94 "ivi_controller", [&c](wl_registry *r, uint32_t name, uint32_t v) {
95 c.c = std::make_unique<genivi::controller>(r, name, v);
97 // XXX: This protocol needs the output, so lets just add our mapping here...
98 c.c->add_proxy_to_id_mapping(c.outputs.back()->proxy.get(),
100 reinterpret_cast<struct wl_proxy *>(
101 c.outputs.back()->proxy.get())));
104 // First level objects
106 // Second level objects
108 // Third level objects
111 if (char const *e = init_layout(c)) {
112 fatal("Could not init layout: %s", e);
116 p.add_fd(STDIN_FILENO, [&c](int fd) {
119 ret = read(fd, &buf, sizeof(buf));
120 c.c->debug_dump_current_status();
121 return ret == 0 ? -1 : 0;
124 p.add_fd(d.get_fd(), [&d](int fd) {
130 sigaddset(&sset, SIGINT);
131 sigaddset(&sset, SIGTERM);
133 auto sfd = unique_fd(signalfd(-1, &sset, SFD_NONBLOCK | SFD_CLOEXEC));
134 sigprocmask(SIG_BLOCK, &sset, NULL);
135 p.add_fd(sfd.fd, [](int fd) {
136 struct signalfd_siginfo si;
137 while (read(fd, &si, sizeof(si)) == sizeof(si)) {
138 lognotice("Received signal %u", si.ssi_signo);
143 while ((d.flush(), p.check_events()) != -1) {
144 c.c->execute_pending();
147 c.c->commit_changes();