aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar
diff options
context:
space:
mode:
authorLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-02-24 13:30:54 +0100
committerLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-02-27 22:12:35 +0100
commitaf7a251806661bbe7ed7a7573ffd8e16ef4b28a2 (patch)
tree0a73776dd6c92bdb100742b984e0d20b54cbedd5 /swaybar
parentDifferentiate between all or no outputs (diff)
downloadsway-af7a251806661bbe7ed7a7573ffd8e16ef4b28a2.tar.gz
sway-af7a251806661bbe7ed7a7573ffd8e16ef4b28a2.tar.zst
sway-af7a251806661bbe7ed7a7573ffd8e16ef4b28a2.zip
Poll before wl_display_dispatch
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/bar.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 6d2872c3..b6329123 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -3,8 +3,8 @@
3#include <string.h> 3#include <string.h>
4#include <fcntl.h> 4#include <fcntl.h>
5#include <errno.h> 5#include <errno.h>
6#include <sys/types.h>
7#include <sys/wait.h> 6#include <sys/wait.h>
7#include <poll.h>
8 8
9#include "ipc-client.h" 9#include "ipc-client.h"
10#include "list.h" 10#include "list.h"
@@ -95,10 +95,22 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {
95} 95}
96 96
97void bar_run(struct bar *bar) { 97void bar_run(struct bar *bar) {
98 fd_set readfds; 98 int pfds = bar->outputs->length + 2;
99 int activity; 99 struct pollfd *pfd = malloc(pfds * sizeof(struct pollfd));
100 bool dirty = true; 100 bool dirty = true;
101 101
102 pfd[0].fd = bar->ipc_event_socketfd;
103 pfd[0].events = POLLIN;
104 pfd[1].fd = bar->status_read_fd;
105 pfd[1].events = POLLIN;
106
107 int i;
108 for (i = 0; i < bar->outputs->length; ++i) {
109 struct output *output = bar->outputs->items[i];
110 pfd[i+2].fd = wl_display_get_fd(output->registry->display);
111 pfd[i+2].events = POLLIN;
112 }
113
102 while (1) { 114 while (1) {
103 if (dirty) { 115 if (dirty) {
104 int i; 116 int i;
@@ -107,32 +119,36 @@ void bar_run(struct bar *bar) {
107 if (window_prerender(output->window) && output->window->cairo) { 119 if (window_prerender(output->window) && output->window->cairo) {
108 render(output, bar->config, bar->status); 120 render(output, bar->config, bar->status);
109 window_render(output->window); 121 window_render(output->window);
110 if (wl_display_dispatch(output->registry->display) == -1) { 122 wl_display_flush(output->registry->display);
111 break;
112 }
113 } 123 }
114 } 124 }
115 } 125 }
116 126
117 dirty = false; 127 dirty = false;
118 FD_ZERO(&readfds);
119 FD_SET(bar->ipc_event_socketfd, &readfds);
120 FD_SET(bar->status_read_fd, &readfds);
121 128
122 activity = select(FD_SETSIZE, &readfds, NULL, NULL, NULL); 129 poll(pfd, pfds, -1);
123 if (activity < 0) {
124 sway_log(L_ERROR, "polling failed: %d", errno);
125 }
126 130
127 if (FD_ISSET(bar->ipc_event_socketfd, &readfds)) { 131 if (pfd[0].revents & POLLIN) {
128 sway_log(L_DEBUG, "Got IPC event."); 132 sway_log(L_DEBUG, "Got IPC event.");
129 dirty = handle_ipc_event(bar); 133 dirty = handle_ipc_event(bar);
130 } 134 }
131 135
132 if (bar->config->status_command && FD_ISSET(bar->status_read_fd, &readfds)) { 136 if (bar->config->status_command && pfd[1].revents & POLLIN) {
133 sway_log(L_DEBUG, "Got update from status command."); 137 sway_log(L_DEBUG, "Got update from status command.");
134 dirty = handle_status_line(bar); 138 dirty = handle_status_line(bar);
135 } 139 }
140
141 // dispatch wl_display events
142 for (i = 0; i < bar->outputs->length; ++i) {
143 struct output *output = bar->outputs->items[i];
144 if (pfd[i+2].revents & POLLIN) {
145 if (wl_display_dispatch(output->registry->display) == -1) {
146 sway_log(L_ERROR, "failed to dispatch wl: %d", errno);
147 }
148 } else {
149 wl_display_dispatch_pending(output->registry->display);
150 }
151 }
136 } 152 }
137} 153}
138 154