Code Review
/
staging
/
windowmanager.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
main: rename connection, streamline init_layout and error handling
[staging/windowmanager.git]
/
src
/
main.cpp
diff --git
a/src/main.cpp
b/src/main.cpp
index
c85f053
..
52d6b32
100644
(file)
--- a/
src/main.cpp
+++ b/
src/main.cpp
@@
-3,11
+3,9
@@
#include <unistd.h>
#include <unistd.h>
-#include <cstdlib>
-
#include <sys/poll.h>
#include <sys/poll.h>
-struct conn {
+struct conn
ection
{
std::vector<std::unique_ptr<wl::output>> outputs;
std::unique_ptr<genivi::controller> c;
};
std::vector<std::unique_ptr<wl::output>> outputs;
std::unique_ptr<genivi::controller> c;
};
@@
-19,7
+17,7
@@
namespace {
// | (__| | | | __/ (__| < | __/\ V / __/ | | | |_\__ \ | | |
// \___|_| |_|\___|\___|_|\_\___\___| \_/ \___|_| |_|\__|___/ | | |
// |_____| \_\/_/
// | (__| | | | __/ (__| < | __/\ V / __/ | | | |_\__ \ | | |
// \___|_| |_|\___|\___|_|\_\___\___| \_/ \___|_| |_|\__|___/ | | |
// |_____| \_\/_/
-int check_events(struct wl::display &d, struct conn &c, int fd) {
+int check_events(struct wl::display &d, struct conn
ection
&c, int fd) {
struct pollfd pfd[2] = {{.fd = d.get_fd(), .events = POLLIN, .revents = 0},
{.fd = fd, .events = POLLIN, .revents = 0}};
struct pollfd pfd[2] = {{.fd = d.get_fd(), .events = POLLIN, .revents = 0},
{.fd = fd, .events = POLLIN, .revents = 0}};
@@
-78,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;
auto &o = c.outputs.front();
auto &s = c.c->screens.begin()->second;
auto &layers = c.c->layers;
@@
-110,6
+116,8
@@
void init_layout(struct conn &c) {
c.c->commit_changes();
// Note: this does not flush the display!
c.c->commit_changes();
// Note: this does not flush the display!
+
+ return nullptr;
}
} // namespace
}
} // namespace
@@
-131,7
+139,7
@@
int main(int /*argc*/, char ** /*argv*/) {
fatal("Could not connect to compositor");
}
fatal("Could not connect to compositor");
}
- struct conn c {};
+ struct conn
ection
c {};
d.r.add_global_handler(
"ivi_controller", [&c](wl_registry *r, uint32_t name, uint32_t v) {
d.r.add_global_handler(
"ivi_controller", [&c](wl_registry *r, uint32_t name, uint32_t v) {
@@
-150,22
+158,14
@@
int main(int /*argc*/, char ** /*argv*/) {
// Third level objects
d.roundtrip();
// 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();
}
while (check_events(d, c, STDIN_FILENO) != -1) {
c.c->execute_pending();
d.flush();
}
- d.roundtrip();
-
return 0;
}
return 0;
}