slock-dwmlogo-20210324.diff 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. diff --git a/config.def.h b/config.def.h
  2. index 9855e21..0940fb8 100644
  3. --- a/config.def.h
  4. +++ b/config.def.h
  5. @@ -3,10 +3,30 @@ static const char *user = "nobody";
  6. static const char *group = "nogroup";
  7. static const char *colorname[NUMCOLS] = {
  8. - [INIT] = "black", /* after initialization */
  9. + [BACKGROUND] = "black", /* after initialization */
  10. + [INIT] = "#2d2d2d", /* after initialization */
  11. [INPUT] = "#005577", /* during input */
  12. [FAILED] = "#CC3333", /* wrong password */
  13. };
  14. /* treat a cleared input like a wrong password (color) */
  15. static const int failonclear = 1;
  16. +
  17. +/* insert grid pattern with scale 1:1, the size can be changed with logosize */
  18. +static const int logosize = 75;
  19. +static const int logow = 12; /* grid width and height for right center alignment*/
  20. +static const int logoh = 6;
  21. +
  22. +static XRectangle rectangles[9] = {
  23. + /* x y w h */
  24. + { 0, 3, 1, 3 },
  25. + { 1, 3, 2, 1 },
  26. + { 0, 5, 8, 1 },
  27. + { 3, 0, 1, 5 },
  28. + { 5, 3, 1, 2 },
  29. + { 7, 3, 1, 2 },
  30. + { 8, 3, 4, 1 },
  31. + { 9, 4, 1, 2 },
  32. + { 11, 4, 1, 2 },
  33. +
  34. +};
  35. diff --git a/config.mk b/config.mk
  36. index 74429ae..08356e8 100644
  37. --- a/config.mk
  38. +++ b/config.mk
  39. @@ -10,12 +10,20 @@ MANPREFIX = ${PREFIX}/share/man
  40. X11INC = /usr/X11R6/include
  41. X11LIB = /usr/X11R6/lib
  42. +# Xinerama, comment if you don't want it
  43. +XINERAMALIBS = -lXinerama
  44. +XINERAMAFLAGS = -DXINERAMA
  45. +
  46. +# freetype
  47. +FREETYPELIBS = -lXft
  48. +FREETYPEINC = /usr/include/freetype2
  49. +
  50. # includes and libs
  51. -INCS = -I. -I/usr/include -I${X11INC}
  52. -LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr
  53. +INCS = -I. -I/usr/include -I${X11INC} -I${FREETYPEINC}
  54. +LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXext -lXrandr
  55. # flags
  56. -CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H
  57. +CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H ${XINERAMAFLAGS}
  58. CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
  59. LDFLAGS = -s ${LIBS}
  60. COMPATSRC = explicit_bzero.c
  61. diff --git a/slock.c b/slock.c
  62. index 5ae738c..3ea9b7f 100644
  63. --- a/slock.c
  64. +++ b/slock.c
  65. @@ -1,5 +1,6 @@
  66. /* See LICENSE file for license details. */
  67. -#define _XOPEN_SOURCE 500
  68. +#define _XOPEN_SOURCE 500
  69. +#define LENGTH(X) (sizeof X / sizeof X[0])
  70. #if HAVE_SHADOW_H
  71. #include <shadow.h>
  72. #endif
  73. @@ -15,9 +16,13 @@
  74. #include <unistd.h>
  75. #include <sys/types.h>
  76. #include <X11/extensions/Xrandr.h>
  77. +#ifdef XINERAMA
  78. +#include <X11/extensions/Xinerama.h>
  79. +#endif
  80. #include <X11/keysym.h>
  81. #include <X11/Xlib.h>
  82. #include <X11/Xutil.h>
  83. +#include <X11/Xft/Xft.h>
  84. #include "arg.h"
  85. #include "util.h"
  86. @@ -25,17 +30,25 @@
  87. char *argv0;
  88. enum {
  89. + BACKGROUND,
  90. INIT,
  91. INPUT,
  92. FAILED,
  93. NUMCOLS
  94. };
  95. +#include "config.h"
  96. +
  97. struct lock {
  98. int screen;
  99. Window root, win;
  100. Pixmap pmap;
  101. unsigned long colors[NUMCOLS];
  102. + unsigned int x, y;
  103. + unsigned int xoff, yoff, mw, mh;
  104. + Drawable drawable;
  105. + GC gc;
  106. + XRectangle rectangles[LENGTH(rectangles)];
  107. };
  108. struct xrandr {
  109. @@ -44,8 +57,6 @@ struct xrandr {
  110. int errbase;
  111. };
  112. -#include "config.h"
  113. -
  114. static void
  115. die(const char *errstr, ...)
  116. {
  117. @@ -124,6 +135,32 @@ gethash(void)
  118. return hash;
  119. }
  120. +static void
  121. +resizerectangles(struct lock *lock)
  122. +{
  123. + int i;
  124. +
  125. + for (i = 0; i < LENGTH(rectangles); i++){
  126. + lock->rectangles[i].x = (rectangles[i].x * logosize)
  127. + + lock->xoff + ((lock->mw) / 2) - (logow / 2 * logosize);
  128. + lock->rectangles[i].y = (rectangles[i].y * logosize)
  129. + + lock->yoff + ((lock->mh) / 2) - (logoh / 2 * logosize);
  130. + lock->rectangles[i].width = rectangles[i].width * logosize;
  131. + lock->rectangles[i].height = rectangles[i].height * logosize;
  132. + }
  133. +}
  134. +
  135. +static void
  136. +drawlogo(Display *dpy, struct lock *lock, int color)
  137. +{
  138. + XSetForeground(dpy, lock->gc, lock->colors[BACKGROUND]);
  139. + XFillRectangle(dpy, lock->drawable, lock->gc, 0, 0, lock->x, lock->y);
  140. + XSetForeground(dpy, lock->gc, lock->colors[color]);
  141. + XFillRectangles(dpy, lock->drawable, lock->gc, lock->rectangles, LENGTH(rectangles));
  142. + XCopyArea(dpy, lock->drawable, lock->win, lock->gc, 0, 0, lock->x, lock->y, 0, 0);
  143. + XSync(dpy, False);
  144. +}
  145. +
  146. static void
  147. readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
  148. const char *hash)
  149. @@ -190,10 +227,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
  150. color = len ? INPUT : ((failure || failonclear) ? FAILED : INIT);
  151. if (running && oldc != color) {
  152. for (screen = 0; screen < nscreens; screen++) {
  153. - XSetWindowBackground(dpy,
  154. - locks[screen]->win,
  155. - locks[screen]->colors[color]);
  156. - XClearWindow(dpy, locks[screen]->win);
  157. + drawlogo(dpy, locks[screen], color);
  158. }
  159. oldc = color;
  160. }
  161. @@ -228,6 +262,10 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
  162. XColor color, dummy;
  163. XSetWindowAttributes wa;
  164. Cursor invisible;
  165. +#ifdef XINERAMA
  166. + XineramaScreenInfo *info;
  167. + int n;
  168. +#endif
  169. if (dpy == NULL || screen < 0 || !(lock = malloc(sizeof(struct lock))))
  170. return NULL;
  171. @@ -241,12 +279,31 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
  172. lock->colors[i] = color.pixel;
  173. }
  174. + lock->x = DisplayWidth(dpy, lock->screen);
  175. + lock->y = DisplayHeight(dpy, lock->screen);
  176. +#ifdef XINERAMA
  177. + if ((info = XineramaQueryScreens(dpy, &n))) {
  178. + lock->xoff = info[0].x_org;
  179. + lock->yoff = info[0].y_org;
  180. + lock->mw = info[0].width;
  181. + lock->mh = info[0].height;
  182. + } else
  183. +#endif
  184. + {
  185. + lock->xoff = lock->yoff = 0;
  186. + lock->mw = lock->x;
  187. + lock->mh = lock->y;
  188. + }
  189. + lock->drawable = XCreatePixmap(dpy, lock->root,
  190. + lock->x, lock->y, DefaultDepth(dpy, screen));
  191. + lock->gc = XCreateGC(dpy, lock->root, 0, NULL);
  192. + XSetLineAttributes(dpy, lock->gc, 1, LineSolid, CapButt, JoinMiter);
  193. +
  194. /* init */
  195. wa.override_redirect = 1;
  196. - wa.background_pixel = lock->colors[INIT];
  197. + wa.background_pixel = lock->colors[BACKGROUND];
  198. lock->win = XCreateWindow(dpy, lock->root, 0, 0,
  199. - DisplayWidth(dpy, lock->screen),
  200. - DisplayHeight(dpy, lock->screen),
  201. + lock->x, lock->y,
  202. 0, DefaultDepth(dpy, lock->screen),
  203. CopyFromParent,
  204. DefaultVisual(dpy, lock->screen),
  205. @@ -256,6 +313,8 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
  206. &color, &color, 0, 0);
  207. XDefineCursor(dpy, lock->win, invisible);
  208. + resizerectangles(lock);
  209. +
  210. /* Try to grab mouse pointer *and* keyboard for 600ms, else fail the lock */
  211. for (i = 0, ptgrab = kbgrab = -1; i < 6; i++) {
  212. if (ptgrab != GrabSuccess) {
  213. @@ -276,6 +335,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
  214. XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask);
  215. XSelectInput(dpy, lock->root, SubstructureNotifyMask);
  216. + drawlogo(dpy, lock, INIT);
  217. return lock;
  218. }
  219. @@ -391,5 +451,12 @@ main(int argc, char **argv) {
  220. /* everything is now blank. Wait for the correct password */
  221. readpw(dpy, &rr, locks, nscreens, hash);
  222. + for (nlocks = 0, s = 0; s < nscreens; s++) {
  223. + XFreePixmap(dpy, locks[s]->drawable);
  224. + XFreeGC(dpy, locks[s]->gc);
  225. + }
  226. +
  227. + XSync(dpy, 0);
  228. + XCloseDisplay(dpy);
  229. return 0;
  230. }