diff options
| author | Zach DeCook <zachdecook@librem.one> | 2022-01-21 16:31:20 -0500 |
|---|---|---|
| committer | Zach DeCook <zachdecook@librem.one> | 2022-01-21 16:31:20 -0500 |
| commit | 707cf18d0ce882504c19a534e236c050f745ca81 (patch) | |
| tree | dec808e6d6a837b733b03bed816ce21170995275 /main.c | |
| parent | cd230615440ff5e8e0cde5f39c37070b48e436bc (diff) | |
| download | suggpicker-707cf18d0ce882504c19a534e236c050f745ca81.tar.gz | |
Event Loop: Handle stdin
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/main.c b/main.c index e204af9..f1cb6ad 100644 --- a/main.c +++ b/main.c @@ -1,3 +1,4 @@ +#include <poll.h> #include "proto/wlr-layer-shell-unstable-v1-client-protocol.h" #include <stdio.h> #include <stdlib.h> @@ -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); } } |
