summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-02-01 18:10:54 -0500
committerJune McEnroe <june@causal.agency>2018-02-01 18:10:54 -0500
commit0e9e295161a1fe048fafbbfad6b587497b3b009d (patch)
tree0c095f45620c9f8ca8e9c0d4b0338f4e7e32f90a /bin
parentAdd bin/README (diff)
downloadsrc-0e9e295161a1fe048fafbbfad6b587497b3b009d.tar.gz
src-0e9e295161a1fe048fafbbfad6b587497b3b009d.zip
Blank framebuffer with sampled background on exit
This should work like 99% of the time, probably.
Diffstat (limited to 'bin')
-rw-r--r--bin/gfxx.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/bin/gfxx.c b/bin/gfxx.c
index cf7cfab5..8f0ddbee 100644
--- a/bin/gfxx.c
+++ b/bin/gfxx.c
@@ -35,6 +35,15 @@ static int init(int argc, char *argv[]);
 static void draw(struct Buffer buf);
 static void input(char in);
 
+static struct Buffer buf;
+
+static uint32_t saveBg;
+static void restoreBg(void) {
+    for (size_t i = 0; i < buf.xres * buf.yres; ++i) {
+        buf.data[i] = saveBg;
+    }
+}
+
 static struct termios saveTerm;
 static void restoreTerm(void) {
     tcsetattr(STDERR_FILENO, TCSADRAIN, &saveTerm);
@@ -57,13 +66,16 @@ int main(int argc, char *argv[]) {
     if (error) err(EX_IOERR, "%s", path);
 
     size_t size = 4 * info.xres * info.yres;
-    struct Buffer buf = {
+    buf = (struct Buffer) {
         .data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0),
         .xres = info.xres,
         .yres = info.yres,
     };
     if (buf.data == MAP_FAILED) err(EX_IOERR, "%s", path);
 
+    saveBg = buf.data[0];
+    atexit(restoreBg);
+
     error = tcgetattr(STDERR_FILENO, &saveTerm);
     if (error) err(EX_IOERR, "tcgetattr");
     atexit(restoreTerm);