aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-03-15 12:36:35 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-03-15 12:36:35 +0000
commit71fde3bfac37f4a67f33ecd7888ee6c134162a95 (patch)
treec7b7688ce944976423f572b6b252173627676e3b
parentcompletions: zsh: don't strip spaces from font name completions (diff)
wayland: store display FD in wayland struct
This way we: * Don't have to call wl_display_get_fd() all the time * No longer call fdm_del_no_close() even though the FD hasn't been added to the FDM.
-rw-r--r--wayland.c12
-rw-r--r--wayland.h3
2 files changed, 9 insertions, 6 deletions
diff --git a/wayland.c b/wayland.c
index addfff84..7ae2e29f 100644
--- a/wayland.c
+++ b/wayland.c
@@ -734,6 +734,7 @@ wayl_init(const struct config *conf, struct fdm *fdm)
struct wayland *wayl = calloc(1, sizeof(*wayl));
wayl->conf = conf;
wayl->fdm = fdm;
+ wayl->fd = -1;
wayl->kbd.repeat.fd = -1;
if (!fdm_hook_add(fdm, &fdm_hook, wayl, FDM_HOOK_PRIORITY_LOW)) {
@@ -844,8 +845,8 @@ wayl_init(const struct config *conf, struct fdm *fdm)
/* All wayland initialization done - make it so */
wl_display_roundtrip(wayl->display);
- int wl_fd = wl_display_get_fd(wayl->display);
- if (fcntl(wl_fd, F_SETFL, fcntl(wl_fd, F_GETFL) | O_NONBLOCK) < 0) {
+ wayl->fd = wl_display_get_fd(wayl->display);
+ if (fcntl(wayl->fd, F_SETFL, fcntl(wayl->fd, F_GETFL) | O_NONBLOCK) < 0) {
LOG_ERRNO("failed to make Wayland socket non-blocking");
goto out;
}
@@ -973,8 +974,9 @@ wayl_destroy(struct wayland *wayl)
wl_compositor_destroy(wayl->compositor);
if (wayl->registry != NULL)
wl_registry_destroy(wayl->registry);
+ if (wayl->fd != -1)
+ fdm_del_no_close(wayl->fdm, wayl->fd);
if (wayl->display != NULL) {
- fdm_del_no_close(wayl->fdm, wl_display_get_fd(wayl->display));
wl_display_disconnect(wayl->display);
}
@@ -1163,9 +1165,7 @@ wayl_flush(struct wayland *wayl)
assert(errno == EAGAIN);
while (true) {
- struct pollfd fds[] = {
- {.fd = wl_display_get_fd(wayl->display), .events = POLLOUT},
- };
+ struct pollfd fds[] = {{.fd = wayl->fd, .events = POLLOUT}};
r = poll(fds, sizeof(fds) / sizeof(fds[0]), -1);
diff --git a/wayland.h b/wayland.h
index 761af73b..70b21d4b 100644
--- a/wayland.h
+++ b/wayland.h
@@ -198,6 +198,9 @@ struct terminal;
struct wayland {
const struct config *conf;
struct fdm *fdm;
+
+ int fd;
+
struct wl_display *display;
struct wl_registry *registry;
struct wl_compositor *compositor;