From 707cf18d0ce882504c19a534e236c050f745ca81 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Fri, 21 Jan 2022 16:31:20 -0500 Subject: Event Loop: Handle stdin --- README.md | 6 +----- main.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1dad1f0..8a66e80 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,7 @@ This is derived from wvkbd. ## Interface -Reads from a FIFO, implementing the 'normal strings' mode from fbp. - -* `\f` Clear the list of strings -* `\r` Enable newlines -* `\t` Restore default strings +Each line of input is treated as TSV. ## Install diff --git a/main.c b/main.c index e204af9..f1cb6ad 100644 --- a/main.c +++ b/main.c @@ -1,3 +1,4 @@ +#include #include "proto/wlr-layer-shell-unstable-v1-client-protocol.h" #include #include @@ -383,6 +384,18 @@ show(int sigint) { drwsurf_flip(&draw_surf); } +void +handle_input(FILE *fd) { + char *line; + line = malloc(1024); + + if (fgets(line, 1024, fd) != NULL) { + printf("Retrieved line: %s\n", line); + } + + free(line); +} + int main(int argc, char **argv) { /* parse command line arguments */ @@ -494,11 +507,27 @@ main(int argc, char **argv) { signal(SIGUSR1, hide); signal(SIGUSR2, show); + // We need a more complicated event loop than wayland's default. + struct pollfd fds[2]; + fds[0].fd = STDIN_FILENO; + fds[0].events = POLLIN; + fds[1].fd = wl_display_get_fd(display); + fds[1].events = POLLIN; + // Initial dispatch so that bar appears (and can take events). + wl_display_dispatch(display); while (run_display) { - while (wl_display_dispatch(display) != -1 && layer_surface) { + while(layer_surface && poll(fds, 2, -1) != -1) { + if (fds[0].revents & POLLIN) { + handle_input(stdin); + } + if (wl_display_dispatch(display) == -1) { + break; + } + wl_display_flush(display); } wl_display_roundtrip(display); while (run_display && !layer_surface) { + // Hidden sleep(1); } } -- cgit 1.4.1