void bar_run(struct bar *bar) { int pfds = bar->outputs->length + 2; struct pollfd *pfd = malloc(pfds * sizeof(struct pollfd)); bool dirty = true; pfd[0].fd = bar->ipc_event_socketfd; pfd[0].events = POLLIN; pfd[1].fd = bar->status_read_fd; pfd[1].events = POLLIN; int i; for (i = 0; i < bar->outputs->length; ++i) { struct output *output = bar->outputs->items[i]; pfd[i+2].fd = wl_display_get_fd(output->registry->display); pfd[i+2].events = POLLIN; } while (1) { if (dirty) { int i; for (i = 0; i < bar->outputs->length; ++i) { struct output *output = bar->outputs->items[i]; if (window_prerender(output->window) && output->window->cairo) { render(output, bar->config, bar->status); window_render(output->window); wl_display_flush(output->registry->display); } } } dirty = false; poll(pfd, pfds, -1); if (pfd[0].revents & POLLIN) { sway_log(L_DEBUG, "Got IPC event."); dirty = handle_ipc_event(bar); } if (bar->config->status_command && pfd[1].revents & POLLIN) { sway_log(L_DEBUG, "Got update from status command."); dirty = handle_status_line(bar); } // dispatch wl_display events for (i = 0; i < bar->outputs->length; ++i) { struct output *output = bar->outputs->items[i]; if (pfd[i+2].revents & POLLIN) { if (wl_display_dispatch(output->registry->display) == -1) { sway_log(L_ERROR, "failed to dispatch wl: %d", errno); } } else { wl_display_dispatch_pending(output->registry->display); } } } }
static int ipc_reap_events(void) { int len, events = 0; merlin_event *pkt; node_log_event_count(&ipc, 0); len = node_recv(&ipc); if (len < 0) return len; while ((pkt = node_get_event(&ipc))) { events++; handle_ipc_event(pkt); } ldebug("Read %d events in %s from %s", events, human_bytes(len), ipc.name); return 0; }
void bar_run(struct bar *bar) { fd_set readfds; int activity; bool dirty = true; while (1) { if (dirty) { struct output *output = bar->output; if (window_prerender(output->window) && output->window->cairo) { render(output, bar->config, bar->status); window_render(output->window); if (wl_display_dispatch(output->registry->display) == -1) { break; } } } dirty = false; FD_ZERO(&readfds); FD_SET(bar->ipc_event_socketfd, &readfds); FD_SET(bar->status_read_fd, &readfds); activity = select(FD_SETSIZE, &readfds, NULL, NULL, NULL); if (activity < 0) { sway_log(L_ERROR, "polling failed: %d", errno); } if (FD_ISSET(bar->ipc_event_socketfd, &readfds)) { sway_log(L_DEBUG, "Got IPC event."); dirty = handle_ipc_event(bar); } if (bar->config->status_command && FD_ISSET(bar->status_read_fd, &readfds)) { sway_log(L_DEBUG, "Got update from status command."); dirty = handle_status_line(bar); } } }