From 1422499f1e467d7e17897bf220087bec44b3d7bc Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Sun, 4 Nov 2012 19:14:16 +0330 Subject: [PATCH] fbpad: c-m-l locks the screen After this command, fbpad freezes until PASS (specified in config.h) followed by return is entered. A NULL PASS disables locking. --- README | 1 + config.h | 3 +++ fbpad.c | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/README b/README index 4750d2b..6b84374 100644 --- a/README +++ b/README @@ -20,6 +20,7 @@ m-o jump to last tag m-tab show next terminal m-s create a text screenshot (SCRSHOT) m-y redraw terminal +c-m-l lock the screen; use PASS to unlock c-m-q quit fbpad ============== ======================================= diff --git a/config.h b/config.h index 81a9c01..3e5aae2 100644 --- a/config.h +++ b/config.h @@ -18,6 +18,9 @@ typedef unsigned int fbval_t; /* where to write the screen shot */ #define SCRSHOT "/tmp/scr" +/* lock command password; NULL disables locking */ +#define PASS NULL + /* optimized version of fb_val() */ #define FB_VAL(r, g, b) fb_val((r), (g), (b)) diff --git a/fbpad.c b/fbpad.c index 7b57dee..4032a28 100644 --- a/fbpad.c +++ b/fbpad.c @@ -37,6 +37,9 @@ static int ctag; /* current tag */ static int ltag; /* the last tag */ static int exitit; static int hidden; +static int locked; +static char pass[1024]; +static int passlen; static int readchar(void) { @@ -138,6 +141,18 @@ static void showtags(void) static void directkey(void) { int c = readchar(); + if (PASS && locked) { + if (c == '\r') { + pass[passlen] = '\0'; + if (!strcmp(PASS, pass)) + locked = 0; + passlen = 0; + return; + } + if (isprint(c) && passlen + 1 < sizeof(pass)) + pass[passlen++] = c; + return; + } if (c == ESC) { switch ((c = readchar())) { case 'c': @@ -171,6 +186,10 @@ static void directkey(void) case 'y': term_switch(cterm(), cterm(), 1, 0, 1); return; + case CTRLKEY('l'): + locked = 1; + passlen = 0; + return; default: if (strchr(tags, c)) { showtag(strchr(tags, c) - tags); -- 2.11.4.GIT