| slock-multi-shapes-1.5.diff - sites - public wiki contents of suckless.org | |
| git clone git://git.suckless.org/sites | |
| Log | |
| Files | |
| Refs | |
| --- | |
| slock-multi-shapes-1.5.diff (5707B) | |
| --- | |
| 1 diff --git a/config.def.h b/config.def.h | |
| 2 index 9855e21..e681e8b 100644 | |
| 3 --- a/config.def.h | |
| 4 +++ b/config.def.h | |
| 5 @@ -3,10 +3,21 @@ static const char *user = "nobody"; | |
| 6 static const char *group = "nogroup"; | |
| 7 | |
| 8 static const char *colorname[NUMCOLS] = { | |
| 9 - [INIT] = "black", /* after initialization */ | |
| 10 + [BG] = "black", /* background */ | |
| 11 + [INIT] = "#4f525c", /* after initialization */ | |
| 12 [INPUT] = "#005577", /* during input */ | |
| 13 [FAILED] = "#CC3333", /* wrong password */ | |
| 14 }; | |
| 15 | |
| 16 /* treat a cleared input like a wrong password (color) */ | |
| 17 static const int failonclear = 1; | |
| 18 + | |
| 19 +/* | |
| 20 +* Shapes: | |
| 21 +* 0: square | |
| 22 +* 1: circle | |
| 23 +*/ | |
| 24 +static const int shape = 0; | |
| 25 +/* size of square in px */ | |
| 26 +static const int shapesize = 50; | |
| 27 +static const int shapegap = 35; | |
| 28 diff --git a/slock.c b/slock.c | |
| 29 index b2f14e3..501b3be 100644 | |
| 30 --- a/slock.c | |
| 31 +++ b/slock.c | |
| 32 @@ -25,6 +25,7 @@ | |
| 33 char *argv0; | |
| 34 | |
| 35 enum { | |
| 36 + BG, | |
| 37 INIT, | |
| 38 INPUT, | |
| 39 FAILED, | |
| 40 @@ -36,6 +37,8 @@ struct lock { | |
| 41 Window root, win; | |
| 42 Pixmap pmap; | |
| 43 unsigned long colors[NUMCOLS]; | |
| 44 + GC gc; | |
| 45 + XRRScreenResources *rrsr; | |
| 46 }; | |
| 47 | |
| 48 struct xrandr { | |
| 49 @@ -124,13 +127,69 @@ gethash(void) | |
| 50 return hash; | |
| 51 } | |
| 52 | |
| 53 +static void | |
| 54 +draw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, | |
| 55 + unsigned int color, unsigned int len) | |
| 56 +{ | |
| 57 + int screen, crtc; | |
| 58 + XRRCrtcInfo* rrci; | |
| 59 + | |
| 60 + if (rr->active) { | |
| 61 + for (screen = 0; screen < nscreens; screen++) { | |
| 62 + XSetWindowBackground(dpy, locks[screen]->win,lo… | |
| 63 + XClearWindow(dpy, locks[screen]->win); | |
| 64 + XSetForeground(dpy, locks[screen]->gc, locks[sc… | |
| 65 + for (crtc = 0; crtc < locks[screen]->rrsr->ncrt… | |
| 66 + rrci = XRRGetCrtcInfo(dpy, | |
| 67 + locks[screen]->rr… | |
| 68 + locks[screen]->rr… | |
| 69 + /* skip disabled crtc */ | |
| 70 + if (rrci->noutput > 0) { | |
| 71 + int leftBound = rrci->x + (rrci… | |
| 72 + for (int shapei = 0; shapei < l… | |
| 73 + int x = leftBound + sha… | |
| 74 + if (shape == 0) { | |
| 75 + XFillRectangle(… | |
| 76 + … | |
| 77 + … | |
| 78 + … | |
| 79 + … | |
| 80 + … | |
| 81 + … | |
| 82 + } else if (shape == 1) { | |
| 83 + XFillArc(dpy, | |
| 84 + locks[… | |
| 85 + locks[… | |
| 86 + x, | |
| 87 + rrci->… | |
| 88 + shapes… | |
| 89 + shapes… | |
| 90 + 0, | |
| 91 + 360 * … | |
| 92 + } | |
| 93 + } | |
| 94 + | |
| 95 + } | |
| 96 + XRRFreeCrtcInfo(rrci); | |
| 97 + } | |
| 98 + } | |
| 99 + } else { | |
| 100 + for (screen = 0; screen < nscreens; screen++) { | |
| 101 + XSetWindowBackground(dpy, | |
| 102 + locks[screen]->win, | |
| 103 + locks[screen]->colors[colo… | |
| 104 + XClearWindow(dpy, locks[screen]->win); | |
| 105 + } | |
| 106 + } | |
| 107 +} | |
| 108 + | |
| 109 static void | |
| 110 readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscree… | |
| 111 const char *hash) | |
| 112 { | |
| 113 XRRScreenChangeNotifyEvent *rre; | |
| 114 char buf[32], passwd[256], *inputhash; | |
| 115 - int num, screen, running, failure, oldc; | |
| 116 + int num, screen, running, failure, oldc, oldlen; | |
| 117 unsigned int len, color; | |
| 118 KeySym ksym; | |
| 119 XEvent ev; | |
| 120 @@ -139,6 +198,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock … | |
| 121 running = 1; | |
| 122 failure = 0; | |
| 123 oldc = INIT; | |
| 124 + oldlen = 0; | |
| 125 | |
| 126 while (running && !XNextEvent(dpy, &ev)) { | |
| 127 if (ev.type == KeyPress) { | |
| 128 @@ -188,14 +248,14 @@ readpw(Display *dpy, struct xrandr *rr, struct loc… | |
| 129 break; | |
| 130 } | |
| 131 color = len ? INPUT : ((failure || failonclear)… | |
| 132 - if (running && oldc != color) { | |
| 133 - for (screen = 0; screen < nscreens; scr… | |
| 134 - XSetWindowBackground(dpy, | |
| 135 - locks[scre… | |
| 136 - locks[scre… | |
| 137 - XClearWindow(dpy, locks[screen]… | |
| 138 + if (running && (oldc != color || oldlen != len)… | |
| 139 + int lenToUse = len; | |
| 140 + if (lenToUse < 1) { | |
| 141 + lenToUse = 1; | |
| 142 } | |
| 143 + draw(dpy, rr, locks, nscreens, color, l… | |
| 144 oldc = color; | |
| 145 + oldlen = len; | |
| 146 } | |
| 147 } else if (rr->active && ev.type == rr->evbase + RRScre… | |
| 148 rre = (XRRScreenChangeNotifyEvent*)&ev; | |
| 149 @@ -228,6 +288,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int scre… | |
| 150 XColor color, dummy; | |
| 151 XSetWindowAttributes wa; | |
| 152 Cursor invisible; | |
| 153 + XGCValues gcvalues; | |
| 154 | |
| 155 if (dpy == NULL || screen < 0 || !(lock = malloc(sizeof(struct … | |
| 156 return NULL; | |
| 157 @@ -243,7 +304,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int scre… | |
| 158 | |
| 159 /* init */ | |
| 160 wa.override_redirect = 1; | |
| 161 - wa.background_pixel = lock->colors[INIT]; | |
| 162 + wa.background_pixel = lock->colors[BG]; | |
| 163 lock->win = XCreateWindow(dpy, lock->root, 0, 0, | |
| 164 DisplayWidth(dpy, lock->screen), | |
| 165 DisplayHeight(dpy, lock->screen), | |
| 166 @@ -255,6 +316,10 @@ lockscreen(Display *dpy, struct xrandr *rr, int scr… | |
| 167 invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, | |
| 168 &color, &color, 0, 0); | |
| 169 XDefineCursor(dpy, lock->win, invisible); | |
| 170 + lock->gc = XCreateGC(dpy, lock->win, 0, &gcvalues); | |
| 171 + XSetForeground(dpy, lock->gc, lock->colors[INIT]); | |
| 172 + if (rr->active) | |
| 173 + lock->rrsr = XRRGetScreenResourcesCurrent(dpy, lock->ro… | |
| 174 | |
| 175 /* Try to grab mouse pointer *and* keyboard for 600ms, else fai… | |
| 176 for (i = 0, ptgrab = kbgrab = -1; i < 6; i++) { | |
| 177 @@ -388,6 +453,9 @@ main(int argc, char **argv) { | |
| 178 } | |
| 179 } | |
| 180 | |
| 181 + /* draw the initial rectangle */ | |
| 182 + draw(dpy, &rr, locks, nscreens, INIT, 1); | |
| 183 + | |
| 184 /* everything is now blank. Wait for the correct password */ | |
| 185 readpw(dpy, &rr, locks, nscreens, hash); | |
| 186 |