Compare commits
5 Commits
be57a7995c
...
38cf36403d
| Author | SHA1 | Date |
|---|---|---|
|
|
38cf36403d | |
|
|
e055505b3d | |
|
|
133b34f860 | |
|
|
5a612138a9 | |
|
|
81508c6538 |
13
config.def.h
13
config.def.h
|
|
@ -9,6 +9,16 @@ static const char *colorname[NUMCOLS] = {
|
|||
[FAILED] = "#CC3333", /* wrong password */
|
||||
};
|
||||
|
||||
/*
|
||||
* Xresources preferences to load at startup
|
||||
*/
|
||||
ResourcePref resources[] = {
|
||||
{ "normbgcolor", STRING, &colorname[BACKGROUND] },
|
||||
{ "normfgcolor", STRING, &colorname[INIT] },
|
||||
{ "selfgcolor", STRING, &colorname[INPUT] },
|
||||
{ "failfgcolor", STRING, &colorname[FAILED] },
|
||||
};
|
||||
|
||||
/* treat a cleared input like a wrong password (color) */
|
||||
static const int failonclear = 1;
|
||||
|
||||
|
|
@ -36,3 +46,6 @@ static const int blurRadius=5;
|
|||
//#define PIXELATION
|
||||
/*Set pixelation radius*/
|
||||
static const int pixelSize=0;
|
||||
|
||||
/* time in seconds before the monitor shuts down */
|
||||
static const int monitortime = 5;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
/* user and group to drop privileges to */
|
||||
static const char *user = "ryan";
|
||||
static const char *group = "ryan";
|
||||
|
||||
static const char *colorname[NUMCOLS] = {
|
||||
[BACKGROUND] = "white",
|
||||
[INIT] = "2d2d2d", /* after initialization */
|
||||
[INPUT] = "#005577", /* during input */
|
||||
[FAILED] = "#CC3333", /* wrong password */
|
||||
};
|
||||
|
||||
/*
|
||||
* Xresources preferences to load at startup
|
||||
*/
|
||||
ResourcePref resources[] = {
|
||||
{ "background", STRING, &colorname[BACKGROUND] },
|
||||
{ "fadeColor", STRING, &colorname[INIT] },
|
||||
{ "accentColor", STRING, &colorname[INPUT] },
|
||||
{ "alertColor", STRING, &colorname[FAILED] },
|
||||
};
|
||||
|
||||
/* treat a cleared input like a wrong password (color) */
|
||||
static const int failonclear = 1;
|
||||
|
||||
static const int logosize = 75;
|
||||
static const int logow = 12; /* Grid width and height for right center alignment*/
|
||||
static const int logoh = 6;
|
||||
|
||||
static XRectangle rectangles[9] = {
|
||||
{0, 3, 1, 3},
|
||||
{1, 3, 2, 1},
|
||||
{0, 5, 8, 1},
|
||||
{3, 0, 1, 5},
|
||||
{5, 3, 1, 2},
|
||||
{7, 3, 1, 2},
|
||||
{8, 3, 4, 1},
|
||||
{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;
|
||||
93
slock.c
93
slock.c
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
#include <stdarg.h>
|
||||
|
|
@ -19,9 +20,11 @@
|
|||
#ifdef XINERAMA
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
#endif
|
||||
#include <X11/extensions/dpms.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xresource.h>
|
||||
#include <Imlib2.h>
|
||||
|
||||
#include "arg.h"
|
||||
|
|
@ -37,6 +40,19 @@ enum {
|
|||
NUMCOLS
|
||||
};
|
||||
|
||||
/* Xresources preferences */
|
||||
enum resource_type {
|
||||
STRING = 0,
|
||||
INTEGER = 1,
|
||||
FLOAT = 2
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
enum resource_type type;
|
||||
void *dst;
|
||||
} ResourcePref;
|
||||
|
||||
#include "config.h"
|
||||
|
||||
struct lock {
|
||||
|
|
@ -324,8 +340,8 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
|
|||
CopyFromParent,
|
||||
DefaultVisual(dpy, lock->screen),
|
||||
CWOverrideRedirect | CWBackPixel, &wa);
|
||||
if(lock->bgmap)
|
||||
XSetWindowBackgroundPixmap(dpy, lock->win, lock->bgmap);
|
||||
if (lock->bgmap)
|
||||
XSetWindowBackgroundPixmap(dpy, lock->win, lock->bgmap);
|
||||
lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8);
|
||||
invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap,
|
||||
&color, &color, 0, 0);
|
||||
|
|
@ -375,6 +391,57 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
|
||||
{
|
||||
char **sdst = dst;
|
||||
int *idst = dst;
|
||||
float *fdst = dst;
|
||||
|
||||
char fullname[256];
|
||||
char fullclass[256];
|
||||
char *type;
|
||||
XrmValue ret;
|
||||
|
||||
snprintf(fullname, sizeof(fullname), "%s.%s", "slock", name);
|
||||
snprintf(fullclass, sizeof(fullclass), "%s.%s", "Slock", name);
|
||||
fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0';
|
||||
|
||||
XrmGetResource(db, fullname, fullclass, &type, &ret);
|
||||
if (ret.addr == NULL || strncmp("String", type, 64))
|
||||
return 1;
|
||||
|
||||
switch (rtype) {
|
||||
case STRING:
|
||||
*sdst = ret.addr;
|
||||
break;
|
||||
case INTEGER:
|
||||
*idst = strtoul(ret.addr, NULL, 10);
|
||||
break;
|
||||
case FLOAT:
|
||||
*fdst = strtof(ret.addr, NULL);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
config_init(Display *dpy)
|
||||
{
|
||||
char *resm;
|
||||
XrmDatabase db;
|
||||
ResourcePref *p;
|
||||
|
||||
XrmInitialize();
|
||||
resm = XResourceManagerString(dpy);
|
||||
if (!resm)
|
||||
return;
|
||||
|
||||
db = XrmGetStringDatabase(resm);
|
||||
for (p = resources; p < resources + LEN(resources); p++)
|
||||
resource_load(db, p->name, p->type, p->dst);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
|
|
@ -392,6 +459,7 @@ main(int argc, char **argv) {
|
|||
const char *hash;
|
||||
Display *dpy;
|
||||
int s, nlocks, nscreens;
|
||||
CARD16 standby, suspend, off;
|
||||
|
||||
ARGBEGIN {
|
||||
case 'v':
|
||||
|
|
@ -487,6 +555,8 @@ main(int argc, char **argv) {
|
|||
|
||||
|
||||
#endif
|
||||
config_init(dpy);
|
||||
|
||||
/* check for Xrandr support */
|
||||
rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase);
|
||||
|
||||
|
|
@ -506,6 +576,20 @@ main(int argc, char **argv) {
|
|||
if (nlocks != nscreens)
|
||||
return 1;
|
||||
|
||||
/* DPMS magic to disable the monitor */
|
||||
if (!DPMSCapable(dpy))
|
||||
die("slock: DPMSCapable failed\n");
|
||||
if (!DPMSEnable(dpy))
|
||||
die("slock: DPMSEnable failed\n");
|
||||
if (!DPMSGetTimeouts(dpy, &standby, &suspend, &off))
|
||||
die("slock: DPMSGetTimeouts failed\n");
|
||||
if (!standby || !suspend || !off)
|
||||
die("slock: at least one DPMS variable is zero\n");
|
||||
if (!DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime))
|
||||
die("slock: DPMSSetTimeouts failed\n");
|
||||
|
||||
XSync(dpy, 0);
|
||||
|
||||
/* run post-lock command */
|
||||
if (argc > 0) {
|
||||
switch (fork()) {
|
||||
|
|
@ -523,6 +607,10 @@ main(int argc, char **argv) {
|
|||
/* everything is now blank. Wait for the correct password */
|
||||
readpw(dpy, &rr, locks, nscreens, hash);
|
||||
|
||||
/* reset DPMS values to inital ones */
|
||||
DPMSSetTimeouts(dpy, standby, suspend, off);
|
||||
XSync(dpy, 0);
|
||||
|
||||
for (nlocks = 0, s = 0; s < nscreens; s++) {
|
||||
XFreePixmap(dpy, locks[s]->drawable);
|
||||
XFreeGC(dpy, locks[s]->gc);
|
||||
|
|
@ -530,5 +618,6 @@ main(int argc, char **argv) {
|
|||
|
||||
XSync(dpy, 0);
|
||||
XCloseDisplay(dpy);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue