From 831cc05ccef68d5f62cb6dfce13c594fab513b9c Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 21 Sep 2023 12:34:44 -0400 Subject: [PATCH] refactor config file Neatly organizes all the patch configuration sections. --- config.def.h | 32 +++++++++++-------------- slock.c | 66 +++++++++++++++++++++++++--------------------------- 2 files changed, 46 insertions(+), 52 deletions(-) diff --git a/config.def.h b/config.def.h index 770a936..87b7679 100644 --- a/config.def.h +++ b/config.def.h @@ -1,4 +1,10 @@ -/* user and group to drop privileges to */ +/* Treat a cleared input like a wrong password (color) */ +static const int failonclear = 1; + +/* Time in seconds before the monitor shuts down */ +static const int monitortime = 5; + +/* User and group to drop privileges to */ static const char *user = "nobody"; static const char *group = "nogroup"; @@ -9,9 +15,7 @@ static const char *colorname[NUMCOLS] = { [FAILED] = "#CC3333", /* wrong password */ }; -/* - * Xresources preferences to load at startup - */ +/* Xresources preferences to load at startup */ ResourcePref resources[] = { { "normbgcolor", STRING, &colorname[BACKGROUND] }, { "normfgcolor", STRING, &colorname[INIT] }, @@ -19,9 +23,13 @@ ResourcePref resources[] = { { "failfgcolor", STRING, &colorname[FAILED] }, }; -/* treat a cleared input like a wrong password (color) */ -static const int failonclear = 1; +/* Configure visual effects */ +#define BLUR 1 +#define PIXELATION 0 +static const int blurRadius = 5; +static const int pixelSize = 1; +/* Configure the logo */ static const int logosize = 75; static const int logow = 12; /* Grid width and height for right center alignment*/ static const int logoh = 6; @@ -37,15 +45,3 @@ static XRectangle rectangles[9] = { {9, 4, 1, 2}, {11,4, 1, 2}, }; - -/*Enable blur*/ -#define BLUR -/*Set blur radius*/ -static const int blurRadius=5; -/*Enable Pixelation*/ -//#define PIXELATION -/*Set pixelation radius*/ -static const int pixelSize=0; - -/* time in seconds before the monitor shuts down */ -static const int monitortime = 5; diff --git a/slock.c b/slock.c index bccb99a..a302723 100644 --- a/slock.c +++ b/slock.c @@ -510,51 +510,49 @@ main(int argc, char **argv) { imlib_context_set_drawable(RootWindow(dpy,XScreenNumberOfScreen(scr))); imlib_copy_drawable_to_image(0,0,0,scr->width,scr->height,0,0,1); -#ifdef BLUR + if (BLUR) + /*Blur function*/ + imlib_image_blur(blurRadius); - /*Blur function*/ - imlib_image_blur(blurRadius); -#endif // BLUR + if (PIXELATION) { + /*Pixelation*/ + int width = scr->width; + int height = scr->height; -#ifdef PIXELATION - /*Pixelation*/ - int width = scr->width; - int height = scr->height; - - for(int y = 0; y < height; y += pixelSize) - { - for(int x = 0; x < width; x += pixelSize) + for(int y = 0; y < height; y += pixelSize) { - int red = 0; - int green = 0; - int blue = 0; - - Imlib_Color pixel; - Imlib_Color* pp; - pp = &pixel; - for(int j = 0; j < pixelSize && j < height; j++) + for(int x = 0; x < width; x += pixelSize) { - for(int i = 0; i < pixelSize && i < width; i++) + int red = 0; + int green = 0; + int blue = 0; + + Imlib_Color pixel; + Imlib_Color* pp; + pp = &pixel; + for(int j = 0; j < pixelSize && j < height; j++) { - imlib_image_query_pixel(x+i,y+j,pp); - red += pixel.red; - green += pixel.green; - blue += pixel.blue; + for(int i = 0; i < pixelSize && i < width; i++) + { + imlib_image_query_pixel(x+i,y+j,pp); + red += pixel.red; + green += pixel.green; + blue += pixel.blue; + } } + red /= (pixelSize*pixelSize); + green /= (pixelSize*pixelSize); + blue /= (pixelSize*pixelSize); + imlib_context_set_color(red,green,blue,pixel.alpha); + imlib_image_fill_rectangle(x,y,pixelSize,pixelSize); + red = 0; + green = 0; + blue = 0; } - red /= (pixelSize*pixelSize); - green /= (pixelSize*pixelSize); - blue /= (pixelSize*pixelSize); - imlib_context_set_color(red,green,blue,pixel.alpha); - imlib_image_fill_rectangle(x,y,pixelSize,pixelSize); - red = 0; - green = 0; - blue = 0; } } -#endif config_init(dpy); /* check for Xrandr support */