diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-13 16:04:37 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-15 00:26:27 +1000 |
commit | 4056c09e13c1aeead6dd4085fc7e263a17a0b195 (patch) | |
tree | a3413f2a5717968e370d68521b689580d5adc5a0 /swaybar/bar.c | |
parent | Document `border csd` (diff) | |
download | sway-4056c09e13c1aeead6dd4085fc7e263a17a0b195.tar.gz sway-4056c09e13c1aeead6dd4085fc7e263a17a0b195.tar.zst sway-4056c09e13c1aeead6dd4085fc7e263a17a0b195.zip |
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 @@ | |||
18 | #endif | 18 | #endif |
19 | #include "swaybar/bar.h" | 19 | #include "swaybar/bar.h" |
20 | #include "swaybar/config.h" | 20 | #include "swaybar/config.h" |
21 | #include "swaybar/event_loop.h" | ||
22 | #include "swaybar/i3bar.h" | 21 | #include "swaybar/i3bar.h" |
23 | #include "swaybar/ipc.h" | 22 | #include "swaybar/ipc.h" |
24 | #include "swaybar/status_line.h" | 23 | #include "swaybar/status_line.h" |
@@ -26,6 +25,7 @@ | |||
26 | #include "ipc-client.h" | 25 | #include "ipc-client.h" |
27 | #include "list.h" | 26 | #include "list.h" |
28 | #include "log.h" | 27 | #include "log.h" |
28 | #include "loop.h" | ||
29 | #include "pool-buffer.h" | 29 | #include "pool-buffer.h" |
30 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | 30 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" |
31 | #include "xdg-output-unstable-v1-client-protocol.h" | 31 | #include "xdg-output-unstable-v1-client-protocol.h" |
@@ -573,7 +573,7 @@ static void set_bar_dirty(struct swaybar *bar) { | |||
573 | 573 | ||
574 | bool bar_setup(struct swaybar *bar, const char *socket_path) { | 574 | bool bar_setup(struct swaybar *bar, const char *socket_path) { |
575 | bar_init(bar); | 575 | bar_init(bar); |
576 | init_event_loop(); | 576 | bar->eventloop = loop_create(); |
577 | 577 | ||
578 | bar->ipc_socketfd = ipc_open_socket(socket_path); | 578 | bar->ipc_socketfd = ipc_open_socket(socket_path); |
579 | bar->ipc_event_socketfd = ipc_open_socket(socket_path); | 579 | bar->ipc_event_socketfd = ipc_open_socket(socket_path); |
@@ -582,6 +582,7 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) { | |||
582 | } | 582 | } |
583 | if (bar->config->status_command) { | 583 | if (bar->config->status_command) { |
584 | bar->status = status_line_init(bar->config->status_command); | 584 | bar->status = status_line_init(bar->config->status_command); |
585 | bar->status->bar = bar; | ||
585 | } | 586 | } |
586 | 587 | ||
587 | bar->display = wl_display_connect(NULL); | 588 | bar->display = wl_display_connect(NULL); |
@@ -646,21 +647,23 @@ static void status_in(int fd, short mask, void *data) { | |||
646 | if (mask & (POLLHUP | POLLERR)) { | 647 | if (mask & (POLLHUP | POLLERR)) { |
647 | status_error(bar->status, "[error reading from status command]"); | 648 | status_error(bar->status, "[error reading from status command]"); |
648 | set_bar_dirty(bar); | 649 | set_bar_dirty(bar); |
649 | remove_event(fd); | 650 | loop_remove_event(bar->eventloop, bar->status_event); |
650 | } else if (status_handle_readable(bar->status)) { | 651 | } else if (status_handle_readable(bar->status)) { |
651 | set_bar_dirty(bar); | 652 | set_bar_dirty(bar); |
652 | } | 653 | } |
653 | } | 654 | } |
654 | 655 | ||
655 | void bar_run(struct swaybar *bar) { | 656 | void bar_run(struct swaybar *bar) { |
656 | add_event(wl_display_get_fd(bar->display), POLLIN, display_in, bar); | 657 | loop_add_fd(bar->eventloop, wl_display_get_fd(bar->display), POLLIN, |
657 | add_event(bar->ipc_event_socketfd, POLLIN, ipc_in, bar); | 658 | display_in, bar); |
659 | loop_add_fd(bar->eventloop, bar->ipc_event_socketfd, POLLIN, ipc_in, bar); | ||
658 | if (bar->status) { | 660 | if (bar->status) { |
659 | add_event(bar->status->read_fd, POLLIN, status_in, bar); | 661 | bar->status_event = loop_add_fd( |
662 | bar->eventloop, bar->status->read_fd, POLLIN, status_in, bar); | ||
660 | } | 663 | } |
661 | while (1) { | 664 | while (1) { |
662 | wl_display_flush(bar->display); | 665 | wl_display_flush(bar->display); |
663 | event_loop_poll(); | 666 | loop_poll(bar->eventloop); |
664 | } | 667 | } |
665 | } | 668 | } |
666 | 669 | ||