Xinqi Bao's Git
projects
/
slock.git
/ diff
summary
|
log
|
commit
|
diff
|
tree
raw
|
patch
|
inline
| side by side (parent:
f013cb2
)
added XRaiseWindow workaround when new clients are launched
author
[email protected]
<unknown>
Sun, 5 Feb 2012 15:38:58 +0000
(16:38 +0100)
committer
[email protected]
<unknown>
Sun, 5 Feb 2012 15:38:58 +0000
(16:38 +0100)
LICENSE
diff
|
blob
|
history
slock.c
diff
|
blob
|
history
diff --git
a/LICENSE
b/LICENSE
index
faf1c09
..
5626eab
100644
(file)
--- a/
LICENSE
+++ b/
LICENSE
@@
-1,6
+1,6
@@
MIT/X Consortium License
MIT/X Consortium License
-© 2006-20
08 Anselm R Garbe <garbeam at gmail dot com
>
+© 2006-20
12 Anselm R Garbe <
[email protected]
>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
diff --git
a/slock.c
b/slock.c
index
d150009
..
28cb4f9
100644
(file)
--- a/
slock.c
+++ b/
slock.c
@@
-22,25
+22,23
@@
#include <bsd_auth.h>
#endif
#include <bsd_auth.h>
#endif
-
struct st_lock
{
+
typedef struct
{
int screen;
int screen;
- Window root, w;
+ Window root, w
in
;
Pixmap pmap;
Pixmap pmap;
-};
+}
Lock
;
-extern const char *__progname;
+static Lock **locks;
+static int nscreens;
+static Bool running = True;
static void
die(const char *errstr, ...) {
va_list ap;
static void
die(const char *errstr, ...) {
va_list ap;
- fprintf(stderr, "%s: ", __progname);
va_start(ap, errstr);
vfprintf(stderr, errstr, ap);
va_end(ap);
va_start(ap, errstr);
vfprintf(stderr, errstr, ap);
va_end(ap);
- fprintf(stderr, "\n");
- fflush(stderr);
-
exit(EXIT_FAILURE);
}
exit(EXIT_FAILURE);
}
@@
-52,7
+50,7
@@
getpw(void) { /* only run as root */
pw = getpwuid(getuid());
if(!pw)
pw = getpwuid(getuid());
if(!pw)
- die("cannot retrieve password entry (make sure to suid or sgid slock)");
+ die("
slock:
cannot retrieve password entry (make sure to suid or sgid slock)");
endpwent();
rval = pw->pw_passwd;
endpwent();
rval = pw->pw_passwd;
@@
-69,7
+67,7
@@
getpw(void) { /* only run as root */
/* drop privileges */
if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0)
/* drop privileges */
if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0)
- die("cannot drop privileges");
+ die("
slock:
cannot drop privileges");
return rval;
}
#endif
return rval;
}
#endif
@@
-82,10
+80,8
@@
readpw(Display *dpy, const char *pws)
#endif
{
char buf[32], passwd[256];
#endif
{
char buf[32], passwd[256];
- int num;
-
+ int num, screen;
unsigned int len;
unsigned int len;
- Bool running = True;
KeySym ksym;
XEvent ev;
KeySym ksym;
XEvent ev;
@@
-96,7
+92,6
@@
readpw(Display *dpy, const char *pws)
* had been removed and you can set it with "xset" or some other
* utility. This way the user can easily set a customized DPMS
* timeout. */
* had been removed and you can set it with "xset" or some other
* utility. This way the user can easily set a customized DPMS
* timeout. */
-
while(running && !XNextEvent(dpy, &ev)) {
if(ev.type == KeyPress) {
buf[0] = 0;
while(running && !XNextEvent(dpy, &ev)) {
if(ev.type == KeyPress) {
buf[0] = 0;
@@
-119,7
+114,7
@@
readpw(Display *dpy, const char *pws)
#else
running = strcmp(crypt(passwd, pws), pws);
#endif
#else
running = strcmp(crypt(passwd, pws), pws);
#endif
- if
(running != 0
)
+ if
(running != False
)
XBell(dpy, 100);
len = 0;
break;
XBell(dpy, 100);
len = 0;
break;
@@
-138,36
+133,37
@@
readpw(Display *dpy, const char *pws)
break;
}
}
break;
}
}
+ else for(screen = 0; screen < nscreens; screen++)
+ XMapRaised(dpy, locks[screen]->win);
}
}
static void
}
}
static void
-unlockscreen(Display *dpy,
struct st_l
ock *lock) {
- if
(dpy == NULL || lock == NULL)
+unlockscreen(Display *dpy,
L
ock *lock) {
+ if(dpy == NULL || lock == NULL)
return;
XUngrabPointer(dpy, CurrentTime);
XFreePixmap(dpy, lock->pmap);
return;
XUngrabPointer(dpy, CurrentTime);
XFreePixmap(dpy, lock->pmap);
- XDestroyWindow(dpy, lock->w);
+ XDestroyWindow(dpy, lock->w
in
);
free(lock);
}
free(lock);
}
-static
struct st_l
ock *
+static
L
ock *
lockscreen(Display *dpy, int screen) {
char curs[] = {0, 0, 0, 0, 0, 0, 0, 0};
unsigned int len;
lockscreen(Display *dpy, int screen) {
char curs[] = {0, 0, 0, 0, 0, 0, 0, 0};
unsigned int len;
- struct st_lock *lock;
- Bool running = True;
+ Lock *lock;
XColor black, dummy;
XSetWindowAttributes wa;
Cursor invisible;
XColor black, dummy;
XSetWindowAttributes wa;
Cursor invisible;
- if
(dpy == NULL || screen < 0)
+ if(dpy == NULL || screen < 0)
return NULL;
return NULL;
- lock = malloc(sizeof(
struct st_l
ock));
- if
(lock == NULL)
+ lock = malloc(sizeof(
L
ock));
+ if(lock == NULL)
return NULL;
lock->screen = screen;
return NULL;
lock->screen = screen;
@@
-177,21
+173,21
@@
lockscreen(Display *dpy, int screen) {
/* init */
wa.override_redirect = 1;
wa.background_pixel = BlackPixel(dpy, lock->screen);
/* init */
wa.override_redirect = 1;
wa.background_pixel = BlackPixel(dpy, lock->screen);
- lock->w = XCreateWindow(dpy, lock->root, 0, 0, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen),
+ lock->w
in
= XCreateWindow(dpy, lock->root, 0, 0, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen),
0, DefaultDepth(dpy, lock->screen), CopyFromParent,
DefaultVisual(dpy, lock->screen), CWOverrideRedirect | CWBackPixel, &wa);
XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), "black", &black, &dummy);
0, DefaultDepth(dpy, lock->screen), CopyFromParent,
DefaultVisual(dpy, lock->screen), CWOverrideRedirect | CWBackPixel, &wa);
XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), "black", &black, &dummy);
- lock->pmap = XCreateBitmapFromData(dpy, lock->w, curs, 8, 8);
+ lock->pmap = XCreateBitmapFromData(dpy, lock->w
in
, curs, 8, 8);
invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &black, &black, 0, 0);
invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &black, &black, 0, 0);
- XDefineCursor(dpy, lock->w, invisible);
- XMapRaised(dpy, lock->w);
+ XDefineCursor(dpy, lock->w
in
, invisible);
+ XMapRaised(dpy, lock->w
in
);
for(len = 1000; len; len--) {
if(XGrabPointer(dpy, lock->root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess)
break;
usleep(1000);
}
for(len = 1000; len; len--) {
if(XGrabPointer(dpy, lock->root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess)
break;
usleep(1000);
}
- if(
(running = running && (len > 0)
)) {
+ if(
running && (len > 0
)) {
for(len = 1000; len; len--) {
if(XGrabKeyboard(dpy, lock->root, True, GrabModeAsync, GrabModeAsync, CurrentTime)
== GrabSuccess)
for(len = 1000; len; len--) {
if(XGrabKeyboard(dpy, lock->root, True, GrabModeAsync, GrabModeAsync, CurrentTime)
== GrabSuccess)
@@
-201,7
+197,7
@@
lockscreen(Display *dpy, int screen) {
running = (len > 0);
}
running = (len > 0);
}
- if
(!running) {
+ if(!running) {
unlockscreen(dpy, lock);
lock = NULL;
}
unlockscreen(dpy, lock);
lock = NULL;
}
@@
-211,24
+207,17
@@
lockscreen(Display *dpy, int screen) {
static void
usage(void) {
static void
usage(void) {
- fprintf(stderr, "usage:
%s -v", __progname
);
+ fprintf(stderr, "usage:
slock [-v]"
);
exit(EXIT_FAILURE);
}
exit(EXIT_FAILURE);
}
-static int
-xerrordummy(Display *dpy, XErrorEvent *ee) {
- return 0;
-}
-
int
main(int argc, char **argv) {
#ifndef HAVE_BSD_AUTH
const char *pws;
#endif
Display *dpy;
int
main(int argc, char **argv) {
#ifndef HAVE_BSD_AUTH
const char *pws;
#endif
Display *dpy;
- int nscreens, screen;
-
- struct st_lock **locks;
+ int screen;
if((argc == 2) && !strcmp("-v", argv[1]))
die("slock-%s, © 2006-2012 Anselm R Garbe", VERSION);
if((argc == 2) && !strcmp("-v", argv[1]))
die("slock-%s, © 2006-2012 Anselm R Garbe", VERSION);
@@
-236,25
+225,21
@@
main(int argc, char **argv) {
usage();
if(!getpwuid(getuid()))
usage();
if(!getpwuid(getuid()))
- die("no passwd entry for you");
+ die("
slock:
no passwd entry for you");
#ifndef HAVE_BSD_AUTH
pws = getpw();
#endif
if(!(dpy = XOpenDisplay(0)))
#ifndef HAVE_BSD_AUTH
pws = getpw();
#endif
if(!(dpy = XOpenDisplay(0)))
- die("cannot open display");
- /* prevent default error handler to take over */
- XSetErrorHandler(xerrordummy);
+ die("slock: cannot open display");
/* Get the number of screens in display "dpy" and blank them all. */
nscreens = ScreenCount(dpy);
/* Get the number of screens in display "dpy" and blank them all. */
nscreens = ScreenCount(dpy);
- locks = malloc(sizeof(struct st_lock *) * nscreens);
- if (locks == NULL)
- die("malloc: %s", strerror(errno));
-
- for (screen = 0; screen < nscreens; screen++)
+ locks = malloc(sizeof(Lock *) * nscreens);
+ if(locks == NULL)
+ die("slock: malloc: %s", strerror(errno));
+ for(screen = 0; screen < nscreens; screen++)
locks[screen] = lockscreen(dpy, screen);
locks[screen] = lockscreen(dpy, screen);
-
XSync(dpy, False);
/* Everything is now blank. Now wait for the correct password. */
XSync(dpy, False);
/* Everything is now blank. Now wait for the correct password. */
@@
-265,11
+250,10
@@
main(int argc, char **argv) {
#endif
/* Password ok, unlock everything and quit. */
#endif
/* Password ok, unlock everything and quit. */
- for
(screen = 0; screen < nscreens; screen++)
+ for(screen = 0; screen < nscreens; screen++)
unlockscreen(dpy, locks[screen]);
free(locks);
unlockscreen(dpy, locks[screen]);
free(locks);
-
XCloseDisplay(dpy);
return 0;
XCloseDisplay(dpy);
return 0;