From 0e9e295161a1fe048fafbbfad6b587497b3b009d Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Thu, 1 Feb 2018 18:10:54 -0500 Subject: Blank framebuffer with sampled background on exit This should work like 99% of the time, probably. --- bin/gfxx.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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); -- cgit 1.4.1