diff --git a/bar.c b/bar.c index 007fbf2..0c8bef7 100644 --- a/bar.c +++ b/bar.c @@ -537,14 +537,10 @@ run(struct bar_run_context *run_ctx) struct module_run_context run_ctx_center[bar->center.count]; struct module_run_context run_ctx_right[bar->right.count]; - int ready_fd = eventfd(0, EFD_CLOEXEC | EFD_SEMAPHORE); - assert(ready_fd != -1); - for (size_t i = 0; i < bar->left.count; i++) { struct module_run_context *ctx = &run_ctx_left[i]; ctx->module = bar->left.mods[i]; - ctx->ready_fd = ready_fd; ctx->abort_fd = run_ctx->abort_fd; thrd_create(&thrd_left[i], (int (*)(void *))bar->left.mods[i]->run, ctx); @@ -553,7 +549,6 @@ run(struct bar_run_context *run_ctx) struct module_run_context *ctx = &run_ctx_center[i]; ctx->module = bar->center.mods[i]; - ctx->ready_fd = ready_fd; ctx->abort_fd = run_ctx->abort_fd; thrd_create(&thrd_center[i], (int (*)(void *))bar->center.mods[i]->run, ctx); @@ -562,26 +557,13 @@ run(struct bar_run_context *run_ctx) struct module_run_context *ctx = &run_ctx_right[i]; ctx->module = bar->right.mods[i]; - ctx->ready_fd = ready_fd; ctx->abort_fd = run_ctx->abort_fd; thrd_create(&thrd_right[i], (int (*)(void *))bar->right.mods[i]->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++) { - uint64_t b; - read(ready_fd, &b, sizeof(b)); - } - - close(ready_fd); LOG_DBG("all modules started"); - refresh(_bar); - int fd = xcb_get_file_descriptor(bar->conn); while (true) { @@ -646,6 +628,8 @@ run(struct bar_run_context *run_ctx) } } + LOG_DBG("shutting down"); + /* Wait for modules to terminate */ int ret = 0; int mod_ret; diff --git a/module.c b/module.c index be2099d..bf4ec3e 100644 --- a/module.c +++ b/module.c @@ -27,12 +27,6 @@ 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 exposable * module_begin_expose(struct module *mod) { diff --git a/module.h b/module.h index c82ef76..5263540 100644 --- a/module.h +++ b/module.h @@ -24,7 +24,6 @@ struct module_info { struct module_run_context { struct module *module; - int ready_fd; int abort_fd; }; @@ -54,6 +53,4 @@ struct module { struct module *module_common_new(void); void module_default_destroy(struct module *mod); - -void module_signal_ready(struct module_run_context *ctx); struct exposable *module_begin_expose(struct module *mod); diff --git a/modules/alsa.c b/modules/alsa.c index d528196..01af17c 100644 --- a/modules/alsa.c +++ b/modules/alsa.c @@ -179,8 +179,6 @@ run(struct module_run_context *ctx) struct module *mod = ctx->module; struct private *m = mod->private; - module_signal_ready(ctx); - snd_mixer_t *handle; snd_mixer_open(&handle, 0); snd_mixer_attach(handle, m->card); @@ -219,6 +217,8 @@ run(struct module_run_context *ctx) m->card, m->mixer, m->vol_min, m->vol_max, m->vol_cur, m->muted ? ", muted" : ""); + mod->bar->refresh(mod->bar); + while (true) { int fd_count = snd_mixer_poll_descriptors_count(handle); assert(fd_count >= 1); diff --git a/modules/backlight.c b/modules/backlight.c index dff2e1a..9eab89b 100644 --- a/modules/backlight.c +++ b/modules/backlight.c @@ -144,8 +144,6 @@ run(struct module_run_context *ctx) struct private *m = ctx->module->private; int current_fd = initialize(m); - module_signal_ready(ctx); - if (current_fd == -1) return 1; @@ -165,6 +163,8 @@ run(struct module_run_context *ctx) udev_monitor_filter_add_match_subsystem_devtype(mon, "backlight", NULL); udev_monitor_enable_receiving(mon); + bar->refresh(bar); + while (true) { struct pollfd fds[] = { {.fd = ctx->abort_fd, .events = POLLIN}, diff --git a/modules/battery.c b/modules/battery.c index 6564af0..2b681da 100644 --- a/modules/battery.c +++ b/modules/battery.c @@ -248,10 +248,8 @@ run(struct module_run_context *ctx) struct private *m = ctx->module->private; int base_dir_fd = initialize(m); - if (base_dir_fd == -1) { - module_signal_ready(ctx); + if (base_dir_fd == -1) return -1; - } LOG_INFO("%s: %s %s (at %.1f%% of original capacity)", m->battery, m->manufacturer, m->model, @@ -269,7 +267,6 @@ run(struct module_run_context *ctx) if (status_fd == -1 || capacity_fd == -1 || energy_fd == -1 || power_fd == -1 || udev == NULL || mon == NULL) { - module_signal_ready(ctx); goto out; } @@ -277,7 +274,7 @@ run(struct module_run_context *ctx) udev_monitor_enable_receiving(mon); update_status(ctx->module, capacity_fd, energy_fd, power_fd, status_fd); - module_signal_ready(ctx); + bar->refresh(bar); while (true) { struct pollfd fds[] = { diff --git a/modules/clock.c b/modules/clock.c index edb9005..64a33d0 100644 --- a/modules/clock.c +++ b/modules/clock.c @@ -54,8 +54,7 @@ static int run(struct module_run_context *ctx) { const struct bar *bar = ctx->module->bar; - - module_signal_ready(ctx); + bar->refresh(bar); while (true) { time_t now = time(NULL); diff --git a/modules/i3.c b/modules/i3.c index 70040f6..4a1c2d4 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -376,7 +376,6 @@ run(struct module_run_context *ctx) FILE *out = popen("i3 --get-socketpath", "r"); if (out == NULL) { LOG_ERRNO("failed to execute 'i3 --get-socketpath'"); - module_signal_ready(ctx); return 1; } @@ -392,7 +391,6 @@ run(struct module_run_context *ctx) int sock = socket(AF_UNIX, SOCK_STREAM, 0); if (sock == -1) { LOG_ERRNO("failed to create UNIX socket"); - module_signal_ready(ctx); return 1; } @@ -400,7 +398,6 @@ run(struct module_run_context *ctx) if (r == -1) { LOG_ERRNO("failed to connect to i3 socket"); close(sock); - module_signal_ready(ctx); return 1; } @@ -408,8 +405,6 @@ 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\"]"); - 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.c b/modules/label.c index 71d6455..ea2013f 100644 --- a/modules/label.c +++ b/modules/label.c @@ -29,7 +29,6 @@ content(struct module *mod) static int run(struct module_run_context *ctx) { - module_signal_ready(ctx); return 0; } diff --git a/modules/mpd.c b/modules/mpd.c index 985b953..928235e 100644 --- a/modules/mpd.c +++ b/modules/mpd.c @@ -260,8 +260,6 @@ update_status(struct module *mod) static int run(struct module_run_context *ctx) { - module_signal_ready(ctx); - struct module *mod = ctx->module; const struct bar *bar = mod->bar; struct private *m = mod->private; diff --git a/modules/network.c b/modules/network.c index 7354ccb..1b8148b 100644 --- a/modules/network.c +++ b/modules/network.c @@ -459,8 +459,6 @@ run(struct module_run_context *ctx) struct module *mod = ctx->module; struct private *m = mod->private; - module_signal_ready(ctx); - m->nl_sock = netlink_connect(); if (m->nl_sock == -1) return 1; diff --git a/modules/removables.c b/modules/removables.c index 889b55c..1337d47 100644 --- a/modules/removables.c +++ b/modules/removables.c @@ -450,8 +450,6 @@ run(struct module_run_context *ctx) struct module *mod = ctx->module; struct private *m = mod->private; - module_signal_ready(ctx); - struct udev *udev = udev_new(); struct udev_monitor *dev_mon = udev_monitor_new_from_netlink(udev, "udev"); diff --git a/modules/xkb.c b/modules/xkb.c index d7c0a7c..1fba910 100644 --- a/modules/xkb.c +++ b/modules/xkb.c @@ -288,7 +288,8 @@ static bool event_loop(struct module_run_context *ctx, xcb_connection_t *conn, int xkb_event_base) { - struct private *m = ctx->module->private; + struct module *mod = ctx->module; + struct private *m = mod->private; const struct bar *bar = ctx->module->bar; bool ret = false; @@ -352,13 +353,17 @@ event_loop(struct module_run_context *ctx, xcb_connection_t *conn, } if (current < layouts.count) { + mtx_lock(&mod->lock); free_layouts(m->layouts); m->layouts = layouts; m->current = current; + mtx_unlock(&mod->lock); bar->refresh(bar); } else { /* Can happen while transitioning to a new map */ + mtx_lock(&mod->lock); free_layouts(layouts); + mtx_unlock(&mod->lock); } break; @@ -369,7 +374,9 @@ event_loop(struct module_run_context *ctx, xcb_connection_t *conn, (const xcb_xkb_state_notify_event_t *)_evt; if (evt->changed & XCB_XKB_STATE_PART_GROUP_STATE) { + mtx_lock(&mod->lock); m->current = evt->group; + mtx_unlock(&mod->lock); bar->refresh(bar); } @@ -398,38 +405,36 @@ talk_to_xkb(struct module_run_context *ctx, xcb_connection_t *conn) struct private *m = ctx->module->private; if (!xkb_enable(conn)) - goto err; + return false; if (!register_for_events(conn)) - goto err; + return false; int xkb_event_base = get_xkb_event_base(conn); if (xkb_event_base == -1) - goto err; + return false; int current = get_current_layout(conn); if (current == -1) - goto err; + return false; struct layouts layouts = get_layouts(conn); if (layouts.count == -1) - goto err; + return false; if (current >= layouts.count) { LOG_ERR("current layout index: %d >= %zd", current, layouts.count); free_layouts(layouts); - goto err; + return false; } + mtx_lock(&ctx->module->lock); m->layouts = layouts; m->current = current; + mtx_unlock(&ctx->module->lock); + ctx->module->bar->refresh(ctx->module->bar); - module_signal_ready(ctx); return event_loop(ctx, conn, xkb_event_base); - -err: - module_signal_ready(ctx); - return false; } static int @@ -438,7 +443,6 @@ run(struct module_run_context *ctx) xcb_connection_t *conn = xcb_connect(NULL, NULL); if (conn == NULL) { LOG_ERR("failed to connect to X server"); - module_signal_ready(ctx); return EXIT_FAILURE; } diff --git a/modules/xwindow.c b/modules/xwindow.c index e571647..e787c80 100644 --- a/modules/xwindow.c +++ b/modules/xwindow.c @@ -189,7 +189,6 @@ run(struct module_run_context *ctx) m->conn = xcb_connect(NULL, NULL); if (m->conn == NULL) { LOG_ERR("failed to connect to X"); - module_signal_ready(ctx); return 1; } @@ -218,8 +217,7 @@ run(struct module_run_context *ctx) update_active_window(m); update_application(mod); update_title(mod); - - module_signal_ready(ctx); + mod->bar->refresh(mod->bar); int xcb_fd = xcb_get_file_descriptor(m->conn); while (true) {