From 1c2a6b6e01836423ca4168cc3f067a113efe654b Mon Sep 17 00:00:00 2001 From: Marcus Fritzsch Date: Thu, 29 Jun 2017 14:29:13 +0200 Subject: [PATCH] main: rename connection, streamline init_layout and error handling Signed-off-by: Marcus Fritzsch --- src/main.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7734d97..52d6b32 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,7 @@ #include -struct conn { +struct connection { std::vector> outputs; std::unique_ptr c; }; @@ -17,7 +17,7 @@ namespace { // | (__| | | | __/ (__| < | __/\ V / __/ | | | |_\__ \ | | | // \___|_| |_|\___|\___|_|\_\___\___| \_/ \___|_| |_|\__|___/ | | | // |_____| \_\/_/ -int check_events(struct wl::display &d, struct conn &c, int fd) { +int check_events(struct wl::display &d, struct connection &c, int fd) { struct pollfd pfd[2] = {{.fd = d.get_fd(), .events = POLLIN, .revents = 0}, {.fd = fd, .events = POLLIN, .revents = 0}}; @@ -76,7 +76,15 @@ int check_events(struct wl::display &d, struct conn &c, int fd) { // | | | | | | |_ | | (_| | |_| | (_) | |_| | |_| | | | // |_|_| |_|_|\__|___|_|\__,_|\__, |\___/ \__,_|\__| | | | // |_____| |___/ \_\/_/ -void init_layout(struct conn &c) { +char const *init_layout(struct connection &c) { + if (!c.c) { + return "ivi_controller global not available"; + } + + if (c.outputs.empty()) { + return "no output was set up!"; + } + auto &o = c.outputs.front(); auto &s = c.c->screens.begin()->second; auto &layers = c.c->layers; @@ -108,6 +116,8 @@ void init_layout(struct conn &c) { c.c->commit_changes(); // Note: this does not flush the display! + + return nullptr; } } // namespace @@ -129,7 +139,7 @@ int main(int /*argc*/, char ** /*argv*/) { fatal("Could not connect to compositor"); } - struct conn c {}; + struct connection c {}; d.r.add_global_handler( "ivi_controller", [&c](wl_registry *r, uint32_t name, uint32_t v) { @@ -148,22 +158,14 @@ int main(int /*argc*/, char ** /*argv*/) { // Third level objects d.roundtrip(); - if (!c.c) { - fatal("ivi_controller global not available"); - } - - if (c.outputs.empty()) { - fatal("no output was set up!"); + if (char const *e = init_layout(c)) { + fatal("Could not init layout: %s", e); } - init_layout(c); - while (check_events(d, c, STDIN_FILENO) != -1) { c.c->execute_pending(); d.flush(); } - d.roundtrip(); - return 0; } -- 2.16.6