diff options
author | Ryan Dwyer <[email protected]> | 2018-10-13 16:04:37 +1000 |
---|---|---|
committer | Ryan Dwyer <[email protected]> | 2018-10-15 00:26:27 +1000 |
commit | 4056c09e13c1aeead6dd4085fc7e263a17a0b195 (patch) | |
tree | a3413f2a5717968e370d68521b689580d5adc5a0 /swaybar/bar.c | |
parent | 7f2e6d812a36e6c30623871c4640897593f6a6cd (diff) |
Move swaybar's event loop to common directory and refactor
* The loop functions are now prefixed with `loop_`.
* It is now easy to add timers to the loop.
* Timers are implemented using pollfd and timerfd, rather than manually
checking them when any other event happens to arrive.
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r-- | swaybar/bar.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index 9f72c94c..8e89c9a8 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -18,7 +18,6 @@ #endif #include "swaybar/bar.h" #include "swaybar/config.h" -#include "swaybar/event_loop.h" #include "swaybar/i3bar.h" #include "swaybar/ipc.h" #include "swaybar/status_line.h" @@ -26,6 +25,7 @@ #include "ipc-client.h" #include "list.h" #include "log.h" +#include "loop.h" #include "pool-buffer.h" #include "wlr-layer-shell-unstable-v1-client-protocol.h" #include "xdg-output-unstable-v1-client-protocol.h" @@ -573,7 +573,7 @@ static void set_bar_dirty(struct swaybar *bar) { bool bar_setup(struct swaybar *bar, const char *socket_path) { bar_init(bar); - init_event_loop(); + bar->eventloop = loop_create(); bar->ipc_socketfd = ipc_open_socket(socket_path); bar->ipc_event_socketfd = ipc_open_socket(socket_path); @@ -582,6 +582,7 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) { } if (bar->config->status_command) { bar->status = status_line_init(bar->config->status_command); + bar->status->bar = bar; } bar->display = wl_display_connect(NULL); @@ -646,21 +647,23 @@ static void status_in(int fd, short mask, void *data) { if (mask & (POLLHUP | POLLERR)) { status_error(bar->status, "[error reading from status command]"); set_bar_dirty(bar); - remove_event(fd); + loop_remove_event(bar->eventloop, bar->status_event); } else if (status_handle_readable(bar->status)) { set_bar_dirty(bar); } } void bar_run(struct swaybar *bar) { - add_event(wl_display_get_fd(bar->display), POLLIN, display_in, bar); - add_event(bar->ipc_event_socketfd, POLLIN, ipc_in, bar); + loop_add_fd(bar->eventloop, wl_display_get_fd(bar->display), POLLIN, + display_in, bar); + loop_add_fd(bar->eventloop, bar->ipc_event_socketfd, POLLIN, ipc_in, bar); if (bar->status) { - add_event(bar->status->read_fd, POLLIN, status_in, bar); + bar->status_event = loop_add_fd( + bar->eventloop, bar->status->read_fd, POLLIN, status_in, bar); } while (1) { wl_display_flush(bar->display); - event_loop_poll(); + loop_poll(bar->eventloop); } } |