slock-blur_pixelated_screen-1.4.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       slock-blur_pixelated_screen-1.4.diff (10550B)
       ---
            1 From 36a4863f9a399740aaf8b1e01926485c0a055e1c Mon Sep 17 00:00:00 2001
            2 From: Lars Niesen <iah71niesen@gso-koeln.de>
            3 Date: Wed, 29 Apr 2020 13:52:42 +0200
            4 Subject: [PATCH 1/8] Added Bg patch and screenshot capabilities
            5 
            6 ---
            7  config.mk |  2 +-
            8  slock.c   | 35 +++++++++++++++++++++++++++++++----
            9  2 files changed, 32 insertions(+), 5 deletions(-)
           10 
           11 diff --git a/config.mk b/config.mk
           12 index 74429ae..987819e 100644
           13 --- a/config.mk
           14 +++ b/config.mk
           15 @@ -12,7 +12,7 @@ X11LIB = /usr/X11R6/lib
           16  
           17  # includes and libs
           18  INCS = -I. -I/usr/include -I${X11INC}
           19 -LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr
           20 +LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr -lImlib2
           21  
           22  # flags
           23  CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H
           24 diff --git a/slock.c b/slock.c
           25 index 5ae738c..7c63f34 100644
           26 --- a/slock.c
           27 +++ b/slock.c
           28 @@ -18,6 +18,7 @@
           29  #include <X11/keysym.h>
           30  #include <X11/Xlib.h>
           31  #include <X11/Xutil.h>
           32 +#include <Imlib2.h>
           33  
           34  #include "arg.h"
           35  #include "util.h"
           36 @@ -35,6 +36,7 @@ struct lock {
           37          int screen;
           38          Window root, win;
           39          Pixmap pmap;
           40 +        Pixmap bgmap;
           41          unsigned long colors[NUMCOLS];
           42  };
           43  
           44 @@ -46,6 +48,8 @@ struct xrandr {
           45  
           46  #include "config.h"
           47  
           48 +Imlib_Image image;
           49 +
           50  static void
           51  die(const char *errstr, ...)
           52  {
           53 @@ -190,9 +194,10 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
           54                          color = len ? INPUT : ((failure || failonclear) ? FAILED : INIT);
           55                          if (running && oldc != color) {
           56                                  for (screen = 0; screen < nscreens; screen++) {
           57 -                                        XSetWindowBackground(dpy,
           58 -                                                             locks[screen]->win,
           59 -                                                             locks[screen]->colors[color]);
           60 +                    if(locks[screen]->bgmap)
           61 +                        XSetWindowBackgroundPixmap(dpy, locks[screen]->win, locks[screen]->bgmap);
           62 +                    else
           63 +                        XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[0]);
           64                                          XClearWindow(dpy, locks[screen]->win);
           65                                  }
           66                                  oldc = color;
           67 @@ -235,6 +240,17 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
           68          lock->screen = screen;
           69          lock->root = RootWindow(dpy, lock->screen);
           70  
           71 +    if(image) 
           72 +    {
           73 +        lock->bgmap = XCreatePixmap(dpy, lock->root, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen), DefaultDepth(dpy, lock->screen));
           74 +        imlib_context_set_image(image);
           75 +        imlib_context_set_display(dpy);
           76 +        imlib_context_set_visual(DefaultVisual(dpy, lock->screen));
           77 +        imlib_context_set_colormap(DefaultColormap(dpy, lock->screen));
           78 +        imlib_context_set_drawable(lock->bgmap);
           79 +        imlib_render_image_on_drawable(0, 0);
           80 +        imlib_free_image();
           81 +    }
           82          for (i = 0; i < NUMCOLS; i++) {
           83                  XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen),
           84                                   colorname[i], &color, &dummy);
           85 @@ -251,6 +267,8 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
           86                                    CopyFromParent,
           87                                    DefaultVisual(dpy, lock->screen),
           88                                    CWOverrideRedirect | CWBackPixel, &wa);
           89 +    if(lock->bgmap)
           90 +        XSetWindowBackgroundPixmap(dpy, lock->win, lock->bgmap);
           91          lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8);
           92          invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap,
           93                                          &color, &color, 0, 0);
           94 @@ -354,7 +372,16 @@ main(int argc, char **argv) {
           95                  die("slock: setgid: %s\n", strerror(errno));
           96          if (setuid(duid) < 0)
           97                  die("slock: setuid: %s\n", strerror(errno));
           98 -
           99 +                
          100 +        /*Create screenshot Image*/
          101 +        Screen *scr = ScreenOfDisplay(dpy, DefaultScreen(dpy));
          102 +        image = imlib_create_image(scr->width,scr->height);
          103 +        imlib_context_set_image(image);
          104 +        imlib_context_set_display(dpy);
          105 +        imlib_context_set_visual(DefaultVisual(dpy,0));
          106 +        imlib_context_set_drawable(RootWindow(dpy,XScreenNumberOfScreen(scr)));        
          107 +        imlib_copy_drawable_to_image(0,0,0,scr->width,scr->height,0,0,1);
          108 +        
          109          /* check for Xrandr support */
          110          rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase);
          111  
          112 -- 
          113 2.27.0
          114 
          115 
          116 From 9d89604ac52b0949d047dae2f9b78cb5085ee1a2 Mon Sep 17 00:00:00 2001
          117 From: Lars Niesen <iah71niesen@gso-koeln.de>
          118 Date: Wed, 29 Apr 2020 14:15:59 +0200
          119 Subject: [PATCH 2/8] Added blur function
          120 
          121 ---
          122  config.def.h | 3 +++
          123  slock.c      | 3 ++-
          124  2 files changed, 5 insertions(+), 1 deletion(-)
          125 
          126 diff --git a/config.def.h b/config.def.h
          127 index c8e52d6..fcc1b39 100644
          128 --- a/config.def.h
          129 +++ b/config.def.h
          130 @@ -10,3 +10,6 @@ static const char *colorname[NUMCOLS] = {
          131  
          132  /* treat a cleared input like a wrong password (color) */
          133  static const int failonclear = 1;
          134 +
          135 +/*Set Blur radius*/
          136 +static const int blurRadius=5;
          137 \ No newline at end of file
          138 diff --git a/slock.c b/slock.c
          139 index 7c63f34..0f24cd7 100644
          140 --- a/slock.c
          141 +++ b/slock.c
          142 @@ -372,7 +372,7 @@ main(int argc, char **argv) {
          143                  die("slock: setgid: %s\n", strerror(errno));
          144          if (setuid(duid) < 0)
          145                  die("slock: setuid: %s\n", strerror(errno));
          146 -                
          147 +
          148          /*Create screenshot Image*/
          149          Screen *scr = ScreenOfDisplay(dpy, DefaultScreen(dpy));
          150          image = imlib_create_image(scr->width,scr->height);
          151 @@ -381,6 +381,7 @@ main(int argc, char **argv) {
          152          imlib_context_set_visual(DefaultVisual(dpy,0));
          153          imlib_context_set_drawable(RootWindow(dpy,XScreenNumberOfScreen(scr)));        
          154          imlib_copy_drawable_to_image(0,0,0,scr->width,scr->height,0,0,1);
          155 +        imlib_image_blur(blurRadius);
          156          
          157          /* check for Xrandr support */
          158          rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase);
          159 -- 
          160 2.27.0
          161 
          162 
          163 From 069aabd7e30244befd4efe74c85d3468ed076c21 Mon Sep 17 00:00:00 2001
          164 From: Lars Niesen <iah71niesen@gso-koeln.de>
          165 Date: Wed, 29 Apr 2020 17:33:09 +0200
          166 Subject: [PATCH 4/8] added Pixelation
          167 
          168 ---
          169  config.def.h |  3 ++-
          170  slock.c      | 42 ++++++++++++++++++++++++++++++++++++++++++
          171  2 files changed, 44 insertions(+), 1 deletion(-)
          172 
          173 diff --git a/config.def.h b/config.def.h
          174 index fcc1b39..1c1aef3 100644
          175 --- a/config.def.h
          176 +++ b/config.def.h
          177 @@ -12,4 +12,5 @@ static const char *colorname[NUMCOLS] = {
          178  static const int failonclear = 1;
          179  
          180  /*Set Blur radius*/
          181 -static const int blurRadius=5;
          182 \ No newline at end of file
          183 +static const int blurRadius=0;
          184 +static const int pixelSize=5;
          185 diff --git a/slock.c b/slock.c
          186 index 0f24cd7..33ca569 100644
          187 --- a/slock.c
          188 +++ b/slock.c
          189 @@ -381,7 +381,49 @@ main(int argc, char **argv) {
          190          imlib_context_set_visual(DefaultVisual(dpy,0));
          191          imlib_context_set_drawable(RootWindow(dpy,XScreenNumberOfScreen(scr)));        
          192          imlib_copy_drawable_to_image(0,0,0,scr->width,scr->height,0,0,1);
          193 +        
          194 +        /*Blur function*/
          195          imlib_image_blur(blurRadius);
          196 +
          197 +
          198 +        /*Pixelation*/
          199 +        int width = scr->width;
          200 +        int height = scr->height;
          201 +        
          202 +        for(int y = 0; y < height; y += pixelSize)
          203 +        {
          204 +                for(int x = 0; x < width; x += pixelSize)
          205 +                {
          206 +                        int red = 0;
          207 +                        int green = 0;
          208 +                        int blue = 0;
          209 +
          210 +                        Imlib_Color pixel; 
          211 +                        Imlib_Color* pp;
          212 +                        pp = &pixel;
          213 +                        for(int j = 0; j < pixelSize && j < height; j++)
          214 +                        {
          215 +                                for(int i = 0; i < pixelSize && i < width; i++)
          216 +                                {
          217 +                                        imlib_image_query_pixel(x+i,y+j,pp);
          218 +                                        red += pixel.red;
          219 +                                        green += pixel.green;
          220 +                                        blue += pixel.blue;
          221 +                                }
          222 +                        }
          223 +                        red /= (pixelSize*pixelSize);
          224 +                        green /= (pixelSize*pixelSize);
          225 +                        blue /= (pixelSize*pixelSize);
          226 +                        printf("R/G/B: %i/%i/%i\n",red,green,blue);
          227 +                        imlib_context_set_color(red,green,blue,pixel.alpha);
          228 +                        imlib_image_fill_rectangle(x,y,pixelSize,pixelSize);
          229 +                        red = 0;
          230 +                        green = 0;
          231 +                        blue = 0;
          232 +                }
          233 +        }
          234 +        
          235 +        
          236          
          237          /* check for Xrandr support */
          238          rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase);
          239 -- 
          240 2.27.0
          241 
          242 
          243 From 109bac015c1c7fbf8440fb42588fe7e0e9cb5e62 Mon Sep 17 00:00:00 2001
          244 From: Lars Niesen <iah71niesen@gso-koeln.de>
          245 Date: Wed, 29 Apr 2020 17:42:39 +0200
          246 Subject: [PATCH 6/8] removed debug printf
          247 
          248 ---
          249  slock.c | 1 -
          250  1 file changed, 1 deletion(-)
          251 
          252 diff --git a/slock.c b/slock.c
          253 index 33ca569..f54c459 100644
          254 --- a/slock.c
          255 +++ b/slock.c
          256 @@ -414,7 +414,6 @@ main(int argc, char **argv) {
          257                          red /= (pixelSize*pixelSize);
          258                          green /= (pixelSize*pixelSize);
          259                          blue /= (pixelSize*pixelSize);
          260 -                        printf("R/G/B: %i/%i/%i\n",red,green,blue);
          261                          imlib_context_set_color(red,green,blue,pixel.alpha);
          262                          imlib_image_fill_rectangle(x,y,pixelSize,pixelSize);
          263                          red = 0;
          264 -- 
          265 2.27.0
          266 
          267 
          268 From a13a0f4ac86f82e4dff145b7ebd93e52d07492c9 Mon Sep 17 00:00:00 2001
          269 From: Lars Niesen <iah71niesen@gso-koeln.de>
          270 Date: Sun, 3 May 2020 18:03:38 +0200
          271 Subject: [PATCH 7/8] Changed compilerflag to fast
          272 
          273 ---
          274  config.mk | 2 +-
          275  1 file changed, 1 insertion(+), 1 deletion(-)
          276 
          277 diff --git a/config.mk b/config.mk
          278 index 987819e..d0c2f01 100644
          279 --- a/config.mk
          280 +++ b/config.mk
          281 @@ -16,7 +16,7 @@ LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr -lImlib2
          282  
          283  # flags
          284  CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H
          285 -CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
          286 +CFLAGS = -std=c99 -pedantic -Wall -Ofast ${INCS} ${CPPFLAGS}
          287  LDFLAGS = -s ${LIBS}
          288  COMPATSRC = explicit_bzero.c
          289  
          290 -- 
          291 2.27.0
          292 
          293 
          294 From 31a7001c4954606c066cc3df4318fafd6d216bcd Mon Sep 17 00:00:00 2001
          295 From: Lars Niesen <iah71niesen@gso-koeln.de>
          296 Date: Mon, 4 May 2020 10:00:40 +0200
          297 Subject: [PATCH 8/8] Added defines for BLUR/PIXELATION to remove from code by
          298  compilation
          299 
          300 ---
          301  config.def.h | 11 ++++++++---
          302  slock.c      |  9 ++++++---
          303  2 files changed, 14 insertions(+), 6 deletions(-)
          304 
          305 diff --git a/config.def.h b/config.def.h
          306 index 1c1aef3..5407953 100644
          307 --- a/config.def.h
          308 +++ b/config.def.h
          309 @@ -11,6 +11,11 @@ static const char *colorname[NUMCOLS] = {
          310  /* treat a cleared input like a wrong password (color) */
          311  static const int failonclear = 1;
          312  
          313 -/*Set Blur radius*/
          314 -static const int blurRadius=0;
          315 -static const int pixelSize=5;
          316 +/*Enable blur*/
          317 +#define BLUR
          318 +/*Set blur radius*/
          319 +static const int blurRadius=5;
          320 +/*Enable Pixelation*/
          321 +//#define PIXELATION
          322 +/*Set pixelation radius*/
          323 +static const int pixelSize=0;
          324 diff --git a/slock.c b/slock.c
          325 index f54c459..1a4d6e3 100644
          326 --- a/slock.c
          327 +++ b/slock.c
          328 @@ -381,11 +381,14 @@ main(int argc, char **argv) {
          329          imlib_context_set_visual(DefaultVisual(dpy,0));
          330          imlib_context_set_drawable(RootWindow(dpy,XScreenNumberOfScreen(scr)));        
          331          imlib_copy_drawable_to_image(0,0,0,scr->width,scr->height,0,0,1);
          332 -        
          333 +
          334 +#ifdef BLUR
          335 +
          336          /*Blur function*/
          337          imlib_image_blur(blurRadius);
          338 +#endif // BLUR        
          339  
          340 -
          341 +#ifdef PIXELATION
          342          /*Pixelation*/
          343          int width = scr->width;
          344          int height = scr->height;
          345 @@ -423,7 +426,7 @@ main(int argc, char **argv) {
          346          }
          347          
          348          
          349 -        
          350 +#endif
          351          /* check for Xrandr support */
          352          rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase);
          353  
          354 -- 
          355 2.27.0
          356