diff options
author | June McEnroe <programble@gmail.com> | 2018-02-01 18:10:54 -0500 |
---|---|---|
committer | June McEnroe <programble@gmail.com> | 2018-02-01 18:10:54 -0500 |
commit | 4b7c45a74a7124b90273d8d8fa2922ea1524a13b (patch) | |
tree | a24c21824d6a980d530576150b0ec553f27aa3d7 | |
parent | Add bin/README (diff) | |
download | src-4b7c45a74a7124b90273d8d8fa2922ea1524a13b.tar.gz src-4b7c45a74a7124b90273d8d8fa2922ea1524a13b.zip |
Blank framebuffer with sampled background on exit
This should work like 99% of the time, probably.
Diffstat (limited to '')
-rw-r--r-- | bin/gfxx.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/bin/gfxx.c b/bin/gfxx.c index cee4568d..eeedf1df 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); |