9 std::vector<std::unique_ptr<wl::output>> outputs;
10 std::unique_ptr<genivi::controller> c;
14 // ___| |_ _ __ _ _ ___| |_ | _ \ ___ | | | ___ _ __
15 // / __| __| '__| | | |/ __| __| | |_) / _ \| | |/ _ \ '__|
16 // \__ \ |_| | | |_| | (__| |_ | __/ (_) | | | __/ |
17 // |___/\__|_| \__,_|\___|\__| |_| \___/|_|_|\___|_|
20 std::vector<std::function<int(int)>> handlers;
21 std::vector<struct pollfd> pfds;
24 void add_fd(int fd, std::function<int(int)> handler);
34 void Poller::add_fd(int fd, std::function<int(int)> handler) {
35 pfds.emplace_back(pollfd{ .fd = fd, .events = POLLIN, .revents = 0 });
36 handlers.emplace_back(std::move(handler));
39 int Poller::check_events() {
41 if ((ret = poll(this->pfds.data(), this->pfds.size(), -1)) != -1 && errno != EINTR) {
42 for (unsigned i = 0; i < pfds.size(); i++) {
43 if (pfds[i].revents & POLLIN) {
44 if (handlers[i](pfds[i].fd) == -1) {
48 pfds[i].events = POLLIN;
57 // (_)_ __ (_) |_ | | __ _ _ _ ___ _ _| |_ / /\ \
58 // | | '_ \| | __| | |/ _` | | | |/ _ \| | | | __| | | |
59 // | | | | | | |_ | | (_| | |_| | (_) | |_| | |_| | | |
60 // |_|_| |_|_|\__|___|_|\__,_|\__, |\___/ \__,_|\__| | | |
61 // |_____| |___/ \_\/_/
62 char const *init_layout(struct connection &c) {
64 return "ivi_controller global not available";
67 if (c.outputs.empty()) {
68 return "no output was set up!";
71 auto &o = c.outputs.front();
72 auto &s = c.c->screens.begin()->second;
73 auto &layers = c.c->layers;
75 // XXX: Write output dimensions to ivi controller...
76 c.c->output_size = genivi::size{uint32_t(o->width), uint32_t(o->height)};
84 // Setup our dummy scene...
85 c.c->layer_create(100, 0, 0); // bottom layer, anything else
86 c.c->layer_create(1000, 0, 0); // top layer, mandelbrot
88 auto &l100 = c.c->layers[100];
89 auto &l1k = c.c->layers[1000];
91 // Set layers fullscreen
92 l100->set_destination_rectangle(0, 0, o->width, o->height);
93 l1k->set_destination_rectangle(0, 0, o->width, o->height);
94 l100->set_visibility(1);
95 l1k->set_visibility(1);
97 // Add layers to screen
98 s->set_render_order({100, 1000});
100 c.c->commit_changes();
101 // Note: this does not flush the display!
108 // _ __ ___ __ _(_)_ __ / /\ \
109 // | '_ ` _ \ / _` | | '_ \| | | |
110 // | | | | | | (_| | | | | | | | |
111 // |_| |_| |_|\__,_|_|_| |_| | | |
113 int main(int /*argc*/, char ** /*argv*/) {
114 lognotice("WinMan ver. %s", WINMAN_VERSION_STRING);
116 if (getenv("XDG_RUNTIME_DIR") == nullptr) {
117 fatal("Environment variable XDG_RUNTIME_DIR not set");
120 struct wl::display d {};
122 fatal("Could not connect to compositor");
125 struct connection c {};
127 d.r.add_global_handler(
128 "wl_output", [&c](wl_registry *r, uint32_t name, uint32_t v) {
129 c.outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
132 d.r.add_global_handler(
133 "ivi_controller", [&c](wl_registry *r, uint32_t name, uint32_t v) {
134 c.c = std::make_unique<genivi::controller>(r, name, v);
136 // XXX: This protocol needs the output, so lets just add our mapping here...
137 c.c->add_proxy_to_id_mapping(c.outputs.back()->proxy.get(),
139 reinterpret_cast<struct wl_proxy *>(
140 c.outputs.back()->proxy.get())));
143 // First level objects
145 // Second level objects
147 // Third level objects
150 if (char const *e = init_layout(c)) {
151 fatal("Could not init layout: %s", e);
155 p.add_fd(STDIN_FILENO, [&c](int fd) {
157 while ((ret = read(fd, &buf, sizeof(buf))) == sizeof(buf)) {
160 c.c->debug_dump_current_status();
161 return ret == 0 ? -1 : 0;
164 p.add_fd(d.get_fd(), [&d](int fd) {
168 while ((d.flush(), p.check_events()) != -1) {
169 c.c->execute_pending();