Compare commits
4 Commits
38cf36403d
...
be57a7995c
| Author | SHA1 | Date |
|---|---|---|
|
|
be57a7995c | |
|
|
f99733cd99 | |
|
|
6f645ea4af | |
|
|
69f39f0bf8 |
13
config.def.h
13
config.def.h
|
|
@ -9,6 +9,16 @@ static const char *colorname[NUMCOLS] = {
|
||||||
[FAILED] = "#CC3333", /* wrong password */
|
[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) */
|
/* treat a cleared input like a wrong password (color) */
|
||||||
static const int failonclear = 1;
|
static const int failonclear = 1;
|
||||||
|
|
||||||
|
|
@ -36,3 +46,6 @@ static const int blurRadius=5;
|
||||||
//#define PIXELATION
|
//#define PIXELATION
|
||||||
/*Set pixelation radius*/
|
/*Set pixelation radius*/
|
||||||
static const int pixelSize=0;
|
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 = "nobody";
|
||||||
|
static const char *group = "nogroup";
|
||||||
|
|
||||||
|
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[] = {
|
||||||
|
{ "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;
|
||||||
|
|
||||||
|
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;
|
||||||
92
slock.c
92
slock.c
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <math.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
@ -19,9 +20,11 @@
|
||||||
#ifdef XINERAMA
|
#ifdef XINERAMA
|
||||||
#include <X11/extensions/Xinerama.h>
|
#include <X11/extensions/Xinerama.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <X11/extensions/dpms.h>
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
|
#include <X11/Xresource.h>
|
||||||
#include <Imlib2.h>
|
#include <Imlib2.h>
|
||||||
|
|
||||||
#include "arg.h"
|
#include "arg.h"
|
||||||
|
|
@ -37,6 +40,19 @@ enum {
|
||||||
NUMCOLS
|
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"
|
#include "config.h"
|
||||||
|
|
||||||
struct lock {
|
struct lock {
|
||||||
|
|
@ -324,8 +340,8 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
|
||||||
CopyFromParent,
|
CopyFromParent,
|
||||||
DefaultVisual(dpy, lock->screen),
|
DefaultVisual(dpy, lock->screen),
|
||||||
CWOverrideRedirect | CWBackPixel, &wa);
|
CWOverrideRedirect | CWBackPixel, &wa);
|
||||||
if(lock->bgmap)
|
if (lock->bgmap)
|
||||||
XSetWindowBackgroundPixmap(dpy, lock->win, lock->bgmap);
|
XSetWindowBackgroundPixmap(dpy, lock->win, lock->bgmap);
|
||||||
lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8);
|
lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8);
|
||||||
invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap,
|
invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap,
|
||||||
&color, &color, 0, 0);
|
&color, &color, 0, 0);
|
||||||
|
|
@ -375,6 +391,57 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
|
||||||
return NULL;
|
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
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
|
|
@ -392,6 +459,7 @@ main(int argc, char **argv) {
|
||||||
const char *hash;
|
const char *hash;
|
||||||
Display *dpy;
|
Display *dpy;
|
||||||
int s, nlocks, nscreens;
|
int s, nlocks, nscreens;
|
||||||
|
CARD16 standby, suspend, off;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'v':
|
case 'v':
|
||||||
|
|
@ -487,6 +555,8 @@ main(int argc, char **argv) {
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
config_init(dpy);
|
||||||
|
|
||||||
/* check for Xrandr support */
|
/* check for Xrandr support */
|
||||||
rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase);
|
rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase);
|
||||||
|
|
||||||
|
|
@ -506,6 +576,20 @@ main(int argc, char **argv) {
|
||||||
if (nlocks != nscreens)
|
if (nlocks != nscreens)
|
||||||
return 1;
|
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 */
|
/* run post-lock command */
|
||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
switch (fork()) {
|
switch (fork()) {
|
||||||
|
|
@ -530,5 +614,9 @@ main(int argc, char **argv) {
|
||||||
|
|
||||||
XSync(dpy, 0);
|
XSync(dpy, 0);
|
||||||
XCloseDisplay(dpy);
|
XCloseDisplay(dpy);
|
||||||
|
/* reset DPMS values to inital ones */
|
||||||
|
DPMSSetTimeouts(dpy, standby, suspend, off);
|
||||||
|
XSync(dpy, 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue