bar: remove struct bar_run_context; store abort_fd in bar struct

This commit is contained in:
Daniel Eklöf 2019-01-16 16:38:04 +01:00
parent a4ce3372ce
commit b195c19599
3 changed files with 11 additions and 19 deletions

13
bar.c
View file

@ -317,9 +317,8 @@ on_mouse(struct bar *bar, enum mouse_event event, int x, int y)
} }
static int static int
run(struct bar_run_context *run_ctx) run(struct bar *_bar)
{ {
struct bar *_bar = run_ctx->bar;
struct private *bar = _bar->private; struct private *bar = _bar->private;
/* TODO: a lot of this (up to mapping the window) could be done in bar_new() */ /* TODO: a lot of this (up to mapping the window) could be done in bar_new() */
@ -536,19 +535,19 @@ run(struct bar_run_context *run_ctx)
for (size_t i = 0; i < bar->left.count; i++) { for (size_t i = 0; i < bar->left.count; i++) {
struct module *mod = bar->left.mods[i]; struct module *mod = bar->left.mods[i];
mod->abort_fd = run_ctx->abort_fd; mod->abort_fd = _bar->abort_fd;
thrd_create(&thrd_left[i], (int (*)(void *))bar->left.mods[i]->run, mod); thrd_create(&thrd_left[i], (int (*)(void *))bar->left.mods[i]->run, mod);
} }
for (size_t i = 0; i < bar->center.count; i++) { for (size_t i = 0; i < bar->center.count; i++) {
struct module *mod = bar->center.mods[i]; struct module *mod = bar->center.mods[i];
mod->abort_fd = run_ctx->abort_fd; mod->abort_fd = _bar->abort_fd;
thrd_create(&thrd_center[i], (int (*)(void *))bar->center.mods[i]->run, mod); thrd_create(&thrd_center[i], (int (*)(void *))bar->center.mods[i]->run, mod);
} }
for (size_t i = 0; i < bar->right.count; i++) { for (size_t i = 0; i < bar->right.count; i++) {
struct module *mod = bar->right.mods[i]; struct module *mod = bar->right.mods[i];
mod->abort_fd = run_ctx->abort_fd; mod->abort_fd = _bar->abort_fd;
thrd_create(&thrd_right[i], (int (*)(void *))bar->right.mods[i]->run, mod); thrd_create(&thrd_right[i], (int (*)(void *))bar->right.mods[i]->run, mod);
} }
@ -558,7 +557,7 @@ run(struct bar_run_context *run_ctx)
while (true) { while (true) {
struct pollfd fds[] = { struct pollfd fds[] = {
{.fd = run_ctx->abort_fd, .events = POLLIN}, {.fd = _bar->abort_fd, .events = POLLIN},
{.fd = fd, .events = POLLIN} {.fd = fd, .events = POLLIN}
}; };
@ -569,7 +568,7 @@ run(struct bar_run_context *run_ctx)
if (fds[1].revents & POLLHUP) { if (fds[1].revents & POLLHUP) {
LOG_WARN("disconnected from XCB"); LOG_WARN("disconnected from XCB");
write(run_ctx->abort_fd, &(uint64_t){1}, sizeof(uint64_t)); write(_bar->abort_fd, &(uint64_t){1}, sizeof(uint64_t));
break; break;
} }

10
bar.h
View file

@ -3,15 +3,11 @@
#include "color.h" #include "color.h"
#include "module.h" #include "module.h"
struct bar;
struct bar_run_context {
struct bar *bar;
int abort_fd;
};
struct bar { struct bar {
int abort_fd;
void *private; void *private;
int (*run)(struct bar_run_context *ctx); int (*run)(struct bar *bar);
void (*destroy)(struct bar *bar); void (*destroy)(struct bar *bar);
void (*refresh)(const struct bar *bar); void (*refresh)(const struct bar *bar);

7
main.c
View file

@ -120,13 +120,10 @@ main(int argc, const char *const *argv)
xcb_init(); xcb_init();
struct bar_run_context bar_ctx = { bar->abort_fd = abort_fd;
.bar = bar,
.abort_fd = abort_fd,
};
thrd_t bar_thread; thrd_t bar_thread;
thrd_create(&bar_thread, (int (*)(void *))bar->run, &bar_ctx); thrd_create(&bar_thread, (int (*)(void *))bar->run, bar);
/* Now unblock. We should be only thread receiving SIGINT */ /* Now unblock. We should be only thread receiving SIGINT */
pthread_sigmask(SIG_UNBLOCK, &signal_mask, NULL); pthread_sigmask(SIG_UNBLOCK, &signal_mask, NULL);