slock-blur_pixelated_screen-1.4.diff 10 KB

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