11 std::vector<std::unique_ptr<wl::output>> outputs;
12 std::unique_ptr<genivi::controller> c;
17 // ___| |__ ___ ___| | __ _____ _____ _ __ | |_ ___ / /\ \
18 // / __| '_ \ / _ \/ __| |/ / / _ \ \ / / _ \ '_ \| __/ __| | | |
19 // | (__| | | | __/ (__| < | __/\ V / __/ | | | |_\__ \ | | |
20 // \___|_| |_|\___|\___|_|\_\___\___| \_/ \___|_| |_|\__|___/ | | |
22 int check_events(struct wl::display &d, struct conn &c, int fd) {
23 struct pollfd pfd[2] = {{.fd = d.get_fd(), .events = POLLIN, .revents = 0},
24 {.fd = fd, .events = POLLIN, .revents = 0}};
28 if (poll(pfd, fd != -1 ? 2 : 1, -1) != -1 && errno != EINTR) {
31 if ((pfd[0].revents & POLLIN) != 0) {
39 if (fd != -1 && ((pfd[1].revents & POLLIN) != 0)) {
42 // read all there is ...
43 while (read(pfd[1].fd, buf, sizeof(buf)) == sizeof(buf)) {
47 // Display current status
48 if (!c.c->surfaces.empty()) {
50 for (auto const &i : c.c->surfaces) {
51 auto const &r = i.second->dst_rect;
52 auto const &s = i.second->size;
53 printf("%d [%ux%u] (%ux%u@%dx%d), ", i.first, s.w, s.h, r.w, r.h,
59 if (!c.c->layers.empty()) {
61 for (auto const &i : c.c->layers) {
62 auto const &r = i.second->dst_rect;
63 auto const &s = i.second->size;
64 printf("%d [%ux%u] (%ux%u@%dx%d), ", i.first, s.w, s.h, r.w, r.h,
76 // (_)_ __ (_) |_ | | __ _ _ _ ___ _ _| |_ / /\ \
77 // | | '_ \| | __| | |/ _` | | | |/ _ \| | | | __| | | |
78 // | | | | | | |_ | | (_| | |_| | (_) | |_| | |_| | | |
79 // |_|_| |_|_|\__|___|_|\__,_|\__, |\___/ \__,_|\__| | | |
80 // |_____| |___/ \_\/_/
81 void init_layout(struct conn &c) {
82 auto &o = c.outputs.front();
83 auto &s = c.c->screens.begin()->second;
84 auto &layers = c.c->layers;
86 // XXX: Write output dimensions to ivi controller...
87 c.c->output_size = genivi::size{uint32_t(o->width), uint32_t(o->height)};
95 // Setup our dummy scene...
96 c.c->layer_create(100, 0, 0); // bottom layer, anything else
97 c.c->layer_create(1000, 0, 0); // top layer, mandelbrot
99 auto &l100 = c.c->layers[100];
100 auto &l1k = c.c->layers[1000];
102 // Set layers fullscreen
103 l100->set_destination_rectangle(0, 0, o->width, o->height);
104 l1k->set_destination_rectangle(0, 0, o->width, o->height);
105 l100->set_visibility(1);
106 l1k->set_visibility(1);
108 // Add layers to screen
109 s->set_render_order({100, 1000});
111 c.c->commit_changes();
112 // Note: this does not flush the display!
117 // _ __ ___ __ _(_)_ __ / /\ \
118 // | '_ ` _ \ / _` | | '_ \| | | |
119 // | | | | | | (_| | | | | | | | |
120 // |_| |_| |_|\__,_|_|_| |_| | | |
122 int main(int /*argc*/, char ** /*argv*/) {
123 lognotice("WinMan ver. %s", WINMAN_VERSION_STRING);
125 if (getenv("XDG_RUNTIME_DIR") == nullptr) {
126 fatal("Environment variable XDG_RUNTIME_DIR not set");
129 struct wl::display d {};
131 fatal("Could not connect to compositor");
136 d.r.add_global_handler(
137 "ivi_controller", [&c](wl_registry *r, uint32_t name, uint32_t v) {
138 c.c = std::make_unique<genivi::controller>(r, name, v);
141 d.r.add_global_handler(
142 "wl_output", [&c](wl_registry *r, uint32_t name, uint32_t v) {
143 c.outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
146 // First level objects
148 // Second level objects
150 // Third level objects
154 fatal("ivi_controller global not available");
157 if (c.outputs.empty()) {
158 fatal("no output was set up!");
163 while (check_events(d, c, STDIN_FILENO) != -1) {
164 c.c->execute_pending();