about summary refs log tree commit diff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c31
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);
 		}
 	}