forked from dannydulai/xl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxl-nopw.c
70 lines (64 loc) · 1.85 KB
/
xl-nopw.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Simple, transparent screen locker in X11
*
* Based on Danny Dulai's "xl", https://github.com/dannydulai/xl/
*
* Modified by Glenn Horton-Smith as follows:
*
* - Avoids the need for any password management by simply
* not having any way to unlock, by password or otherwise.
* You must arrange some other way to kill the program.
* - Added a countdown so that user has time to hide the terminal
* window if this is invoked from the terminal.
* - Also added some checks for failure to obtain the pointer
* and keyboard grabs.
*
*/
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int
main(int argc, char *argv[])
{
Display *display;
Window root;
XEvent ev;
int status;
int countdown = 5;
if ((display = XOpenDisplay(NULL)) == NULL) {
fprintf(stderr, "could not connect to display\n");
exit(1);
}
printf("This display will be transparently locked.\n"
"There will be no way to unlock except by killing this program,\n"
"which will be impossible to do from this display.\n"
"Locking in ");
for (; countdown > 0; --countdown) {
printf("%d... ", countdown);
fflush(stdout);
sleep(1);
}
printf("0.\n");
root = DefaultRootWindow(display);
status = XGrabPointer(display, root, 0,
ButtonPressMask|ButtonReleaseMask|PointerMotionMask,
GrabModeAsync, GrabModeAsync,
None, None, CurrentTime);
if (status != GrabSuccess) {
fprintf(stderr, "Could not grab pointer.\n");
exit(1);
}
status = XGrabKeyboard(display, root, 0,
GrabModeAsync, GrabModeAsync, CurrentTime);
if (status != GrabSuccess) {
fprintf(stderr, "Could not grab keyboard.\n");
exit(1);
}
printf("Locked.\n");
while (1) {
XNextEvent(display, &ev);
}
}