From 34f21a3c2127161f70c8749b07971aefc4142c2c Mon Sep 17 00:00:00 2001 From: Ted Meyer Date: Wed, 30 Sep 2015 00:31:32 -0400 Subject: [PATCH 1/3] better arg handling --- robolock.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/robolock.c b/robolock.c index 2f7849f..36eaf17 100644 --- a/robolock.c +++ b/robolock.c @@ -591,13 +591,17 @@ int lockscreen(Display *disp, lock_t *lock){ int main(const int argc, char ** argv){ const char *pws = 0; Display * disp; - /* default blur size */ - opts.blur_size = 25; + + { + /* default blur size */ + opts.blur_size = 25; /* default thread count */ opts.threads = 8; - opts.imagename = 0; + /* default image name */ + opts.imagename = 0; + } int c; while((c = getopt(argc, argv, "b:t:i:")) != -1) { @@ -612,10 +616,18 @@ int main(const int argc, char ** argv){ opts.blur_size = atoi(optarg); break; case '?': - if (optopt == 'b') { - fprintf(stderr, "-b --blur [int]: missing [int]"); - } - break; + switch(optopt) { + case 'b': + fprintf(stderr, "-b --blur [int]: missing [int]"); + break; + case 'i': + fprintf(stderr, "-i --image [path]: missing [path]"); + break; + case 't': + fprintf(stderr, "-t --threads [int]: missing [int]"); + break; + } + break; } } if(!getpwuid(getuid())){ From ce2785e6bddef7ce68331828d357aff38edc2456 Mon Sep 17 00:00:00 2001 From: Ted Meyer Date: Wed, 30 Sep 2015 01:35:01 -0400 Subject: [PATCH 2/3] added ability to specify the color set for keystrokes --- robolock.c | 110 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 95 insertions(+), 15 deletions(-) diff --git a/robolock.c b/robolock.c index 176a603..b580667 100644 --- a/robolock.c +++ b/robolock.c @@ -31,7 +31,7 @@ typedef struct lock_s { Window root, win; Pixmap pmap; GC gc; - XImage * screenshot; + XImage *screenshot; unsigned char *scrdata; unsigned int depth; unsigned int width; @@ -41,7 +41,9 @@ typedef struct lock_s { typedef struct options_s { unsigned int blur_size; unsigned int threads; - char * imagename; + char *imagename; + XColor *colors; + unsigned int color_count; } options_t; int running = TRUE; @@ -305,13 +307,10 @@ void postprocesscolor(ppargs_t *args){ } - float lastr = 0.0; float lastg = 0.0; float lastb = 0.0; - - int updateColor(Display *disp, lock_t *lock, float red, float green, float blue){ if(opts.threads < 1) return FALSE; @@ -347,6 +346,15 @@ int updateColor(Display *disp, lock_t *lock, float red, float green, float blue) return TRUE; } +int pickRandomColor(Display *disp, lock_t *lock, XColor *colors, int color_count) { + int color = rand() % color_count; + float r = colors[color].red / 65536.0; + float g = colors[color].green / 65536.0; + float b = colors[color].blue / 65536.0; + return updateColor(disp, lock, r-1.0, g-1.0, b-1.0); +} + + int getscreenshot(Display * disp, lock_t *lock){ if(opts.threads < 1) return FALSE; @@ -458,14 +466,17 @@ void readpw(Display *disp, const char *pws, lock_t *locks, unsigned int numlocks if(num && !iscntrl((int) buf[0]) && (len + num < sizeof(passwd))){ memcpy(passwd + len, buf, num); len+= num; - unsigned int i; + unsigned int i; for(i= 0; i Date: Wed, 30 Sep 2015 01:38:27 -0400 Subject: [PATCH 3/3] tabs are for tools, but whatever --- robolock.c | 194 ++++++++++++++++++++++++++--------------------------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/robolock.c b/robolock.c index 48c4b0f..cdb6723 100644 --- a/robolock.c +++ b/robolock.c @@ -42,8 +42,8 @@ typedef struct options_s { unsigned int blur_size; unsigned int threads; char *imagename; - XColor *colors; - unsigned int color_count; + XColor *colors; + unsigned int color_count; } options_t; int running = TRUE; @@ -347,11 +347,11 @@ int updateColor(Display *disp, lock_t *lock, float red, float green, float blue) } int pickRandomColor(Display *disp, lock_t *lock, XColor *colors, int color_count) { - int color = rand() % color_count; - float r = colors[color].red / 65536.0; - float g = colors[color].green / 65536.0; - float b = colors[color].blue / 65536.0; - return updateColor(disp, lock, r-1.0, g-1.0, b-1.0); + int color = rand() % color_count; + float r = colors[color].red / 65536.0; + float g = colors[color].green / 65536.0; + float b = colors[color].blue / 65536.0; + return updateColor(disp, lock, r-1.0, g-1.0, b-1.0); } @@ -466,17 +466,17 @@ void readpw(Display *disp, const char *pws, lock_t *locks, unsigned int numlocks if(num && !iscntrl((int) buf[0]) && (len + num < sizeof(passwd))){ memcpy(passwd + len, buf, num); len+= num; - unsigned int i; + unsigned int i; for(i= 0; i