-namespace {
-// _ _ _ ____
-// ___| |__ ___ ___| | __ _____ _____ _ __ | |_ ___ / /\ \
-// / __| '_ \ / _ \/ __| |/ / / _ \ \ / / _ \ '_ \| __/ __| | | |
-// | (__| | | | __/ (__| < | __/\ V / __/ | | | |_\__ \ | | |
-// \___|_| |_|\___|\___|_|\_\___\___| \_/ \___|_| |_|\__|___/ | | |
-// |_____| \_\/_/
-int check_events(struct wl::display *d, struct conn *c, int fd) {
- struct pollfd pfd[2] = {{.fd = d->get_fd(), .events = POLLIN, .revents = 0},
- {.fd = fd, .events = POLLIN, .revents = 0}};
-
- d->flush();
-
- if (poll(pfd, fd != -1 ? 2 : 1, -1) != -1 && errno != EINTR) {
- int ret = 0;
-
- if (pfd[0].revents & POLLIN) {
- ret = d->dispatch();
- }
-
- if (ret == -1)
- return ret;
-
- if (fd != -1 && (pfd[1].revents & POLLIN)) {
- char buf[256];
-
- // read all there is ...
- while (read(pfd[1].fd, buf, sizeof(buf)) == sizeof(buf))
- ;
+// _ _ ____ _ _
+// ___| |_ _ __ _ _ ___| |_ | _ \ ___ | | | ___ _ __
+// / __| __| '__| | | |/ __| __| | |_) / _ \| | |/ _ \ '__|
+// \__ \ |_| | | |_| | (__| |_ | __/ (_) | | | __/ |
+// |___/\__|_| \__,_|\___|\__| |_| \___/|_|_|\___|_|
+//
+struct Poller {
+ std::vector<std::function<int(int)>> handlers;
+ std::vector<struct pollfd> pfds;
+
+ Poller() = default;
+ void add_fd(int fd, std::function<int(int)> handler);
+ int check_events();
+};