This commit is contained in:
Daniel Jankowski 2018-01-15 20:36:47 +00:00 committed by GitHub
commit 5adc904ea6
1 changed files with 7 additions and 3 deletions

View File

@ -7,6 +7,7 @@
#include <ctype.h> #include <ctype.h>
#include <signal.h> #include <signal.h>
#include <poll.h> #include <poll.h>
#include <fcntl.h>
#include <getopt.h> #include <getopt.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
@ -1348,6 +1349,9 @@ main (int argc, char **argv)
// Get the fd to Xserver // Get the fd to Xserver
pollin[1].fd = xcb_get_file_descriptor(c); pollin[1].fd = xcb_get_file_descriptor(c);
// Prevent fgets to block
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
for (;;) { for (;;) {
bool redraw = false; bool redraw = false;
@ -1361,9 +1365,9 @@ main (int argc, char **argv)
else break; // ...bail out else break; // ...bail out
} }
if (pollin[0].revents & POLLIN) { // New input, process it if (pollin[0].revents & POLLIN) { // New input, process it
if (fgets(input, sizeof(input), stdin) == NULL) input[0] = '\0';
break; // EOF received while (fgets(input, sizeof(input), stdin) != NULL)
; // Drain the buffer, the last line is actually used
parse(input); parse(input);
redraw = true; redraw = true;
} }