Skip to content

Instantly share code, notes, and snippets.

@Lerchensporn
Last active June 5, 2016 16:10
Show Gist options
  • Save Lerchensporn/990f83b0ac4277165c64 to your computer and use it in GitHub Desktop.
Save Lerchensporn/990f83b0ac4277165c64 to your computer and use it in GitHub Desktop.
diff --git a/bar.c b/bar.c
index 68b41ca..b9f2ae5 100644
--- a/bar.c
+++ b/bar.c
@@ -1,5 +1,6 @@
// vim:sw=4:ts=4:et:
#include <stdbool.h>
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -1287,6 +1288,9 @@ main (int argc, char **argv)
// Get the fd to Xserver
pollin[1].fd = xcb_get_file_descriptor(c);
+ // Prevent fgets to block
+ fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
+
for (;;) {
bool redraw = false;
@@ -1300,9 +1304,11 @@ main (int argc, char **argv)
else break; // ...bail out
}
if (pollin[0].revents & POLLIN) { // New input, process it
- if (fgets(input, sizeof(input), stdin) == NULL)
- break; // EOF received
-
+ *input = 0;
+ while (fgets(input, sizeof input, stdin)) { }
+ if (!*input) {
+ break;
+ }
parse(input);
redraw = true;
}
@tryone144
Copy link

Same here. 👍
Would like to see this patch upstream...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment