summary refs log tree commit diff
path: root/bin/gfb.c
diff options
context:
space:
mode:
authorJune McEnroe <programble@gmail.com>2018-02-07 12:07:01 -0500
committerJune McEnroe <programble@gmail.com>2018-02-07 12:07:01 -0500
commit11c23c1f97eefd5f748469d4c88b8c67e95a93dd (patch)
treee85603171f1ebb0de3f1398f5973ef9e259a6ddd /bin/gfb.c
parentRename title to status in gfcocoa (diff)
downloadsrc-11c23c1f97eefd5f748469d4c88b8c67e95a93dd.tar.gz
src-11c23c1f97eefd5f748469d4c88b8c67e95a93dd.zip
Exit by returning false from input to gf{b,cocoa}
I haven't built gfb yet, so a fix commit is probably incoming.
Diffstat (limited to '')
-rw-r--r--bin/gfb.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/bin/gfb.c b/bin/gfb.c
index 3606bb05..d843c694 100644
--- a/bin/gfb.c
+++ b/bin/gfb.c
@@ -17,6 +17,7 @@
 #include <err.h>
 #include <fcntl.h>
 #include <linux/fb.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
@@ -27,18 +28,9 @@
 #include <unistd.h>
 
 extern int init(int argc, char *argv[]);
+extern const char *status(void);
 extern void draw(uint32_t *buf, size_t xres, size_t yres);
-extern void input(char in);
-
-static uint32_t *buf;
-static struct fb_var_screeninfo info;
-
-static uint32_t saveBg;
-static void restoreBg(void) {
-    for (size_t i = 0; i < info.xres * info.yres; ++i) {
-        buf[i] = saveBg;
-    }
-}
+extern bool input(char in);
 
 static struct termios saveTerm;
 static void restoreTerm(void) {
@@ -57,16 +49,14 @@ int main(int argc, char *argv[]) {
     int fb = open(path, O_RDWR);
     if (fb < 0) err(EX_OSFILE, "%s", path);
 
+    struct fb_var_screeninfo info;
     error = ioctl(fb, FBIOGET_VSCREENINFO, &info);
     if (error) err(EX_IOERR, "%s", path);
 
     size_t size = 4 * info.xres * info.yres;
-    buf = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0);
+    uint32_t *buf = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0);
     if (buf == MAP_FAILED) err(EX_IOERR, "%s", path);
 
-    saveBg = buf[0];
-    atexit(restoreBg);
-
     error = tcgetattr(STDERR_FILENO, &saveTerm);
     if (error) err(EX_IOERR, "tcgetattr");
     atexit(restoreTerm);
@@ -76,6 +66,8 @@ int main(int argc, char *argv[]) {
     error = tcsetattr(STDERR_FILENO, TCSADRAIN, &term);
     if (error) err(EX_IOERR, "tcsetattr");
 
+    uint32_t saveBg = buf[0];
+
     uint32_t back[info.xres * info.yres];
     for (;;) {
         draw(back, info.xres, info.yres);
@@ -86,6 +78,12 @@ int main(int argc, char *argv[]) {
         if (len < 0) err(EX_IOERR, "read");
         if (!len) return EX_DATAERR;
 
-        input(in);
+        if (!input(in)) {
+            for (uint32_t i = 0; i < info.xres * info.yres; ++i) {
+                buf[i] = saveBg;
+            }
+            fprintf(stderr, "%s\n", status());
+            return EX_OK;
+        }
     }
 }