mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-20 03:35:41 +02:00
module: remove ready_fd
All modules are expected to handle a call to content() after having been instantiated. I.e. modules *cannot* even expect run() to have started running.
This commit is contained in:
parent
65cfcfb2de
commit
acdeff3b6e
14 changed files with 27 additions and 66 deletions
20
bar.c
20
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_center[bar->center.count];
|
||||||
struct module_run_context run_ctx_right[bar->right.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++) {
|
for (size_t i = 0; i < bar->left.count; i++) {
|
||||||
struct module_run_context *ctx = &run_ctx_left[i];
|
struct module_run_context *ctx = &run_ctx_left[i];
|
||||||
|
|
||||||
ctx->module = bar->left.mods[i];
|
ctx->module = bar->left.mods[i];
|
||||||
ctx->ready_fd = ready_fd;
|
|
||||||
ctx->abort_fd = run_ctx->abort_fd;
|
ctx->abort_fd = run_ctx->abort_fd;
|
||||||
|
|
||||||
thrd_create(&thrd_left[i], (int (*)(void *))bar->left.mods[i]->run, ctx);
|
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];
|
struct module_run_context *ctx = &run_ctx_center[i];
|
||||||
|
|
||||||
ctx->module = bar->center.mods[i];
|
ctx->module = bar->center.mods[i];
|
||||||
ctx->ready_fd = ready_fd;
|
|
||||||
ctx->abort_fd = run_ctx->abort_fd;
|
ctx->abort_fd = run_ctx->abort_fd;
|
||||||
|
|
||||||
thrd_create(&thrd_center[i], (int (*)(void *))bar->center.mods[i]->run, ctx);
|
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];
|
struct module_run_context *ctx = &run_ctx_right[i];
|
||||||
|
|
||||||
ctx->module = bar->right.mods[i];
|
ctx->module = bar->right.mods[i];
|
||||||
ctx->ready_fd = ready_fd;
|
|
||||||
ctx->abort_fd = run_ctx->abort_fd;
|
ctx->abort_fd = run_ctx->abort_fd;
|
||||||
|
|
||||||
thrd_create(&thrd_right[i], (int (*)(void *))bar->right.mods[i]->run, ctx);
|
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");
|
LOG_DBG("all modules started");
|
||||||
|
|
||||||
refresh(_bar);
|
|
||||||
|
|
||||||
int fd = xcb_get_file_descriptor(bar->conn);
|
int fd = xcb_get_file_descriptor(bar->conn);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -646,6 +628,8 @@ run(struct bar_run_context *run_ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_DBG("shutting down");
|
||||||
|
|
||||||
/* Wait for modules to terminate */
|
/* Wait for modules to terminate */
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int mod_ret;
|
int mod_ret;
|
||||||
|
|
6
module.c
6
module.c
|
@ -27,12 +27,6 @@ module_default_destroy(struct module *mod)
|
||||||
free(mod);
|
free(mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
module_signal_ready(struct module_run_context *ctx)
|
|
||||||
{
|
|
||||||
write(ctx->ready_fd, &(uint64_t){1}, sizeof(uint64_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
struct exposable *
|
struct exposable *
|
||||||
module_begin_expose(struct module *mod)
|
module_begin_expose(struct module *mod)
|
||||||
{
|
{
|
||||||
|
|
3
module.h
3
module.h
|
@ -24,7 +24,6 @@ struct module_info {
|
||||||
|
|
||||||
struct module_run_context {
|
struct module_run_context {
|
||||||
struct module *module;
|
struct module *module;
|
||||||
int ready_fd;
|
|
||||||
int abort_fd;
|
int abort_fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -54,6 +53,4 @@ struct module {
|
||||||
|
|
||||||
struct module *module_common_new(void);
|
struct module *module_common_new(void);
|
||||||
void module_default_destroy(struct module *mod);
|
void module_default_destroy(struct module *mod);
|
||||||
|
|
||||||
void module_signal_ready(struct module_run_context *ctx);
|
|
||||||
struct exposable *module_begin_expose(struct module *mod);
|
struct exposable *module_begin_expose(struct module *mod);
|
||||||
|
|
|
@ -179,8 +179,6 @@ run(struct module_run_context *ctx)
|
||||||
struct module *mod = ctx->module;
|
struct module *mod = ctx->module;
|
||||||
struct private *m = mod->private;
|
struct private *m = mod->private;
|
||||||
|
|
||||||
module_signal_ready(ctx);
|
|
||||||
|
|
||||||
snd_mixer_t *handle;
|
snd_mixer_t *handle;
|
||||||
snd_mixer_open(&handle, 0);
|
snd_mixer_open(&handle, 0);
|
||||||
snd_mixer_attach(handle, m->card);
|
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->card, m->mixer, m->vol_min, m->vol_max, m->vol_cur,
|
||||||
m->muted ? ", muted" : "");
|
m->muted ? ", muted" : "");
|
||||||
|
|
||||||
|
mod->bar->refresh(mod->bar);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int fd_count = snd_mixer_poll_descriptors_count(handle);
|
int fd_count = snd_mixer_poll_descriptors_count(handle);
|
||||||
assert(fd_count >= 1);
|
assert(fd_count >= 1);
|
||||||
|
|
|
@ -144,8 +144,6 @@ run(struct module_run_context *ctx)
|
||||||
struct private *m = ctx->module->private;
|
struct private *m = ctx->module->private;
|
||||||
|
|
||||||
int current_fd = initialize(m);
|
int current_fd = initialize(m);
|
||||||
module_signal_ready(ctx);
|
|
||||||
|
|
||||||
if (current_fd == -1)
|
if (current_fd == -1)
|
||||||
return 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_filter_add_match_subsystem_devtype(mon, "backlight", NULL);
|
||||||
udev_monitor_enable_receiving(mon);
|
udev_monitor_enable_receiving(mon);
|
||||||
|
|
||||||
|
bar->refresh(bar);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
struct pollfd fds[] = {
|
struct pollfd fds[] = {
|
||||||
{.fd = ctx->abort_fd, .events = POLLIN},
|
{.fd = ctx->abort_fd, .events = POLLIN},
|
||||||
|
|
|
@ -248,10 +248,8 @@ run(struct module_run_context *ctx)
|
||||||
struct private *m = ctx->module->private;
|
struct private *m = ctx->module->private;
|
||||||
|
|
||||||
int base_dir_fd = initialize(m);
|
int base_dir_fd = initialize(m);
|
||||||
if (base_dir_fd == -1) {
|
if (base_dir_fd == -1)
|
||||||
module_signal_ready(ctx);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
LOG_INFO("%s: %s %s (at %.1f%% of original capacity)",
|
LOG_INFO("%s: %s %s (at %.1f%% of original capacity)",
|
||||||
m->battery, m->manufacturer, m->model,
|
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 ||
|
if (status_fd == -1 || capacity_fd == -1 || energy_fd == -1 ||
|
||||||
power_fd == -1 || udev == NULL || mon == NULL)
|
power_fd == -1 || udev == NULL || mon == NULL)
|
||||||
{
|
{
|
||||||
module_signal_ready(ctx);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +274,7 @@ run(struct module_run_context *ctx)
|
||||||
udev_monitor_enable_receiving(mon);
|
udev_monitor_enable_receiving(mon);
|
||||||
|
|
||||||
update_status(ctx->module, capacity_fd, energy_fd, power_fd, status_fd);
|
update_status(ctx->module, capacity_fd, energy_fd, power_fd, status_fd);
|
||||||
module_signal_ready(ctx);
|
bar->refresh(bar);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
struct pollfd fds[] = {
|
struct pollfd fds[] = {
|
||||||
|
|
|
@ -54,8 +54,7 @@ static int
|
||||||
run(struct module_run_context *ctx)
|
run(struct module_run_context *ctx)
|
||||||
{
|
{
|
||||||
const struct bar *bar = ctx->module->bar;
|
const struct bar *bar = ctx->module->bar;
|
||||||
|
bar->refresh(bar);
|
||||||
module_signal_ready(ctx);
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
|
|
@ -376,7 +376,6 @@ run(struct module_run_context *ctx)
|
||||||
FILE *out = popen("i3 --get-socketpath", "r");
|
FILE *out = popen("i3 --get-socketpath", "r");
|
||||||
if (out == NULL) {
|
if (out == NULL) {
|
||||||
LOG_ERRNO("failed to execute 'i3 --get-socketpath'");
|
LOG_ERRNO("failed to execute 'i3 --get-socketpath'");
|
||||||
module_signal_ready(ctx);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,7 +391,6 @@ run(struct module_run_context *ctx)
|
||||||
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (sock == -1) {
|
if (sock == -1) {
|
||||||
LOG_ERRNO("failed to create UNIX socket");
|
LOG_ERRNO("failed to create UNIX socket");
|
||||||
module_signal_ready(ctx);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,7 +398,6 @@ run(struct module_run_context *ctx)
|
||||||
if (r == -1) {
|
if (r == -1) {
|
||||||
LOG_ERRNO("failed to connect to i3 socket");
|
LOG_ERRNO("failed to connect to i3 socket");
|
||||||
close(sock);
|
close(sock);
|
||||||
module_signal_ready(ctx);
|
|
||||||
return 1;
|
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_GET_WORKSPACES, NULL);
|
||||||
send_pkg(sock, I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[\"workspace\"]");
|
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 */
|
char buf[1 * 1024 * 1024]; /* Some replies are *big*. TODO: grow dynamically */
|
||||||
size_t buf_idx = 0;
|
size_t buf_idx = 0;
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,6 @@ content(struct module *mod)
|
||||||
static int
|
static int
|
||||||
run(struct module_run_context *ctx)
|
run(struct module_run_context *ctx)
|
||||||
{
|
{
|
||||||
module_signal_ready(ctx);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -260,8 +260,6 @@ update_status(struct module *mod)
|
||||||
static int
|
static int
|
||||||
run(struct module_run_context *ctx)
|
run(struct module_run_context *ctx)
|
||||||
{
|
{
|
||||||
module_signal_ready(ctx);
|
|
||||||
|
|
||||||
struct module *mod = ctx->module;
|
struct module *mod = ctx->module;
|
||||||
const struct bar *bar = mod->bar;
|
const struct bar *bar = mod->bar;
|
||||||
struct private *m = mod->private;
|
struct private *m = mod->private;
|
||||||
|
|
|
@ -459,8 +459,6 @@ run(struct module_run_context *ctx)
|
||||||
struct module *mod = ctx->module;
|
struct module *mod = ctx->module;
|
||||||
struct private *m = mod->private;
|
struct private *m = mod->private;
|
||||||
|
|
||||||
module_signal_ready(ctx);
|
|
||||||
|
|
||||||
m->nl_sock = netlink_connect();
|
m->nl_sock = netlink_connect();
|
||||||
if (m->nl_sock == -1)
|
if (m->nl_sock == -1)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -450,8 +450,6 @@ run(struct module_run_context *ctx)
|
||||||
struct module *mod = ctx->module;
|
struct module *mod = ctx->module;
|
||||||
struct private *m = mod->private;
|
struct private *m = mod->private;
|
||||||
|
|
||||||
module_signal_ready(ctx);
|
|
||||||
|
|
||||||
struct udev *udev = udev_new();
|
struct udev *udev = udev_new();
|
||||||
struct udev_monitor *dev_mon = udev_monitor_new_from_netlink(udev, "udev");
|
struct udev_monitor *dev_mon = udev_monitor_new_from_netlink(udev, "udev");
|
||||||
|
|
||||||
|
|
|
@ -288,7 +288,8 @@ static bool
|
||||||
event_loop(struct module_run_context *ctx, xcb_connection_t *conn,
|
event_loop(struct module_run_context *ctx, xcb_connection_t *conn,
|
||||||
int xkb_event_base)
|
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;
|
const struct bar *bar = ctx->module->bar;
|
||||||
|
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
@ -352,13 +353,17 @@ event_loop(struct module_run_context *ctx, xcb_connection_t *conn,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current < layouts.count) {
|
if (current < layouts.count) {
|
||||||
|
mtx_lock(&mod->lock);
|
||||||
free_layouts(m->layouts);
|
free_layouts(m->layouts);
|
||||||
m->layouts = layouts;
|
m->layouts = layouts;
|
||||||
m->current = current;
|
m->current = current;
|
||||||
|
mtx_unlock(&mod->lock);
|
||||||
bar->refresh(bar);
|
bar->refresh(bar);
|
||||||
} else {
|
} else {
|
||||||
/* Can happen while transitioning to a new map */
|
/* Can happen while transitioning to a new map */
|
||||||
|
mtx_lock(&mod->lock);
|
||||||
free_layouts(layouts);
|
free_layouts(layouts);
|
||||||
|
mtx_unlock(&mod->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -369,7 +374,9 @@ event_loop(struct module_run_context *ctx, xcb_connection_t *conn,
|
||||||
(const xcb_xkb_state_notify_event_t *)_evt;
|
(const xcb_xkb_state_notify_event_t *)_evt;
|
||||||
|
|
||||||
if (evt->changed & XCB_XKB_STATE_PART_GROUP_STATE) {
|
if (evt->changed & XCB_XKB_STATE_PART_GROUP_STATE) {
|
||||||
|
mtx_lock(&mod->lock);
|
||||||
m->current = evt->group;
|
m->current = evt->group;
|
||||||
|
mtx_unlock(&mod->lock);
|
||||||
bar->refresh(bar);
|
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;
|
struct private *m = ctx->module->private;
|
||||||
|
|
||||||
if (!xkb_enable(conn))
|
if (!xkb_enable(conn))
|
||||||
goto err;
|
return false;
|
||||||
|
|
||||||
if (!register_for_events(conn))
|
if (!register_for_events(conn))
|
||||||
goto err;
|
return false;
|
||||||
|
|
||||||
int xkb_event_base = get_xkb_event_base(conn);
|
int xkb_event_base = get_xkb_event_base(conn);
|
||||||
if (xkb_event_base == -1)
|
if (xkb_event_base == -1)
|
||||||
goto err;
|
return false;
|
||||||
|
|
||||||
int current = get_current_layout(conn);
|
int current = get_current_layout(conn);
|
||||||
if (current == -1)
|
if (current == -1)
|
||||||
goto err;
|
return false;
|
||||||
|
|
||||||
struct layouts layouts = get_layouts(conn);
|
struct layouts layouts = get_layouts(conn);
|
||||||
if (layouts.count == -1)
|
if (layouts.count == -1)
|
||||||
goto err;
|
return false;
|
||||||
|
|
||||||
if (current >= layouts.count) {
|
if (current >= layouts.count) {
|
||||||
LOG_ERR("current layout index: %d >= %zd", current, layouts.count);
|
LOG_ERR("current layout index: %d >= %zd", current, layouts.count);
|
||||||
free_layouts(layouts);
|
free_layouts(layouts);
|
||||||
goto err;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mtx_lock(&ctx->module->lock);
|
||||||
m->layouts = layouts;
|
m->layouts = layouts;
|
||||||
m->current = current;
|
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);
|
return event_loop(ctx, conn, xkb_event_base);
|
||||||
|
|
||||||
err:
|
|
||||||
module_signal_ready(ctx);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -438,7 +443,6 @@ run(struct module_run_context *ctx)
|
||||||
xcb_connection_t *conn = xcb_connect(NULL, NULL);
|
xcb_connection_t *conn = xcb_connect(NULL, NULL);
|
||||||
if (conn == NULL) {
|
if (conn == NULL) {
|
||||||
LOG_ERR("failed to connect to X server");
|
LOG_ERR("failed to connect to X server");
|
||||||
module_signal_ready(ctx);
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -189,7 +189,6 @@ run(struct module_run_context *ctx)
|
||||||
m->conn = xcb_connect(NULL, NULL);
|
m->conn = xcb_connect(NULL, NULL);
|
||||||
if (m->conn == NULL) {
|
if (m->conn == NULL) {
|
||||||
LOG_ERR("failed to connect to X");
|
LOG_ERR("failed to connect to X");
|
||||||
module_signal_ready(ctx);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,8 +217,7 @@ run(struct module_run_context *ctx)
|
||||||
update_active_window(m);
|
update_active_window(m);
|
||||||
update_application(mod);
|
update_application(mod);
|
||||||
update_title(mod);
|
update_title(mod);
|
||||||
|
mod->bar->refresh(mod->bar);
|
||||||
module_signal_ready(ctx);
|
|
||||||
|
|
||||||
int xcb_fd = xcb_get_file_descriptor(m->conn);
|
int xcb_fd = xcb_get_file_descriptor(m->conn);
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue