From 3413232ed6bec8591f9cec7da78e1dea12247193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 19 Dec 2018 20:23:53 +0100 Subject: [PATCH] module: add new function module_signal_ready() --- bar.c | 5 ++++- module.c | 8 ++++++++ module.h | 1 + modules/battery/battery.c | 3 +-- modules/clock/clock.c | 4 +--- modules/i3/i3.c | 3 +-- modules/label/label.c | 4 +--- modules/xkb/xkb.c | 3 +-- modules/xwindow/xwindow.c | 2 +- 9 files changed, 19 insertions(+), 14 deletions(-) diff --git a/bar.c b/bar.c index 2a84a3b..13b2ba5 100644 --- a/bar.c +++ b/bar.c @@ -417,7 +417,10 @@ run(struct bar_run_context *run_ctx) } LOG_DBG("waiting for modules to become ready"); - for (size_t i = 0; i < bar->left.count + bar->center.count + bar->right.count; i++) { + + for (size_t i = 0; i < (bar->left.count + + bar->center.count + + bar->right.count); i++) { uint64_t b; read(ready_fd, &b, sizeof(b)); } diff --git a/module.c b/module.c index 9dcf5d5..3622587 100644 --- a/module.c +++ b/module.c @@ -1,5 +1,7 @@ #include "module.h" #include +#include +#include struct module * module_common_new(void) @@ -24,6 +26,12 @@ module_default_destroy(struct module *mod) free(mod); } +void +module_signal_ready(struct module_run_context *ctx) +{ + write(ctx->ready_fd, &(uint64_t){1}, sizeof(uint64_t)); +} + struct module_expose_context module_default_begin_expose(struct module *mod, cairo_t *cr) { diff --git a/module.h b/module.h index 2bb12bd..1d55eda 100644 --- a/module.h +++ b/module.h @@ -39,6 +39,7 @@ struct module { }; struct module *module_common_new(void); +void module_signal_ready(struct module_run_context *ctx); void module_default_destroy(struct module *mod); diff --git a/modules/battery/battery.c b/modules/battery/battery.c index 61cacee..baaf5da 100644 --- a/modules/battery/battery.c +++ b/modules/battery/battery.c @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -203,7 +202,7 @@ run(struct module_run_context *ctx) udev_monitor_filter_add_match_subsystem_devtype(mon, "power_supply", NULL); udev_monitor_enable_receiving(mon); - write(ctx->ready_fd, &(uint64_t){1}, sizeof(uint64_t)); + module_signal_ready(ctx); bool first = true; while (true) { diff --git a/modules/clock/clock.c b/modules/clock/clock.c index 5e4ca46..3a05bf4 100644 --- a/modules/clock/clock.c +++ b/modules/clock/clock.c @@ -1,8 +1,6 @@ #include "clock.h" #include -#include #include -#include #include #include @@ -52,7 +50,7 @@ run(struct module_run_context *ctx) { const struct bar *bar = ctx->module->bar; - write(ctx->ready_fd, &(uint64_t){1}, sizeof(uint64_t)); + module_signal_ready(ctx); while (true) { time_t now = time(NULL); diff --git a/modules/i3/i3.c b/modules/i3/i3.c index 11e9caf..cdeb386 100644 --- a/modules/i3/i3.c +++ b/modules/i3/i3.c @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -287,7 +286,7 @@ run(struct module_run_context *ctx) send_pkg(sock, I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); send_pkg(sock, I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[\"workspace\"]"); - write(ctx->ready_fd, &(uint64_t){1}, sizeof(uint64_t)); + module_signal_ready(ctx); char buf[1 * 1024 * 1024]; /* Some replies are *big*. TODO: grow dynamically */ size_t buf_idx = 0; diff --git a/modules/label/label.c b/modules/label/label.c index 4e6c2dc..750082f 100644 --- a/modules/label/label.c +++ b/modules/label/label.c @@ -1,8 +1,6 @@ #include "label.h" #include -#include -#include #include #include @@ -30,7 +28,7 @@ content(struct module *mod) static int run(struct module_run_context *ctx) { - write(ctx->ready_fd, &(uint64_t){1}, sizeof(uint64_t)); + module_signal_ready(ctx); return 0; } diff --git a/modules/xkb/xkb.c b/modules/xkb/xkb.c index 6e70b98..5514fd4 100644 --- a/modules/xkb/xkb.c +++ b/modules/xkb/xkb.c @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -439,7 +438,7 @@ run(struct module_run_context *ctx) } /* TODO: move this to later */ - write(ctx->ready_fd, &(uint64_t){1}, sizeof(uint64_t)); + module_signal_ready(ctx); int ret = talk_to_xkb(ctx->abort_fd, ctx->module->bar, ctx->module->private, conn) ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/modules/xwindow/xwindow.c b/modules/xwindow/xwindow.c index 7200869..ab26a9a 100644 --- a/modules/xwindow/xwindow.c +++ b/modules/xwindow/xwindow.c @@ -207,7 +207,7 @@ run(struct module_run_context *ctx) update_title(m); mod->bar->refresh(mod->bar); - write(ctx->ready_fd, &(uint64_t){1}, sizeof(uint64_t)); + module_signal_ready(ctx); int xcb_fd = xcb_get_file_descriptor(m->conn); while (true) {