i3 - improved tiling WM


Add `-e` option to not validate empty password.

Patch status: superseded

Patch by Vincent Bernat

Long description:

When the XF86ScreenSaver key is used to put a laptop to sleep (or to
trigger the screensaver), the key may "bounce" on resume. This is
annoying as i3lock will try to validate several empty passwords and
wait several seconds before accepting a legit password.

Some users may want to validate an empty password: PAM may rely on
other sources to unlock the screen, like the presence of a token or
the proximity of some Bluetooth device. Hence, we don't forbid this
possibility and provide an command-line option for users not willing
to validate empty passwords.

To apply this patch, use:
curl http://cr.i3wm.org/patch/207/raw.patch | git am

b/i3lock.1

24
@@ -27,6 +27,7 @@ i3lock \- improved screen locker
25
 .RB [\|\-p
26
 .IR pointer\|]
27
 .RB [\|\-u\|]
28
+.RB [\|\-e\|]
29
 
30
 .SH DESCRIPTION
31
 .B i3lock
32
@@ -100,6 +101,13 @@ does not hide your Mousepointer. If you specify "win",
33
 displays a hardcoded Windows-Pointer (thus enabling you to fuck with your
34
 friends by using a Screenshot of a Windows-Desktop as a locking-screen).
35
 
36
+.TP
37
+.B \-e, \-\-no-empty-password
38
+When an empty password is provided by the user, do not validate
39
+it. Without this option, the empty password will be provided to PAM
40
+and, if invalid, the user will have to wait a few seconds before
41
+another try.
42
+
43
 .SH SEE ALSO
44
 .IR xautolock(1)
45
 \- use i3lock as your screen saver

b/i3lock.c

50
@@ -60,6 +60,7 @@ static struct xkb_keymap *xkb_keymap;
51
 
52
 cairo_surface_t *img = NULL;
53
 bool tile = false;
54
+bool noempty = false;
55
 
56
 /* isutf, u8_dec © 2005 Jeff Bezanson, public domain */
57
 #define isutf(c) (((c) & 0xC0) != 0x80)
58
@@ -264,9 +265,13 @@ static void handle_key_press(xcb_key_press_event_t *event) {
59
     n = xkb_keysym_to_utf8(ksym, buffer, sizeof(buffer));
60
 
61
     switch (ksym) {
62
+    case XKB_KEY_XF86ScreenSaver:
63
     case XKB_KEY_Return:
64
     case XKB_KEY_KP_Enter:
65
-    case XKB_KEY_XF86ScreenSaver:
66
+        if (noempty && input_position == 0) {
67
+            clear_input();
68
+            return;
69
+        }
70
         password[input_position] = '\0';
71
         unlock_state = STATE_KEY_PRESSED;
72
         redraw_screen();
73
@@ -533,13 +538,14 @@ int main(int argc, char *argv[]) {
74
         {"no-unlock-indicator", no_argument, NULL, 'u'},
75
         {"image", required_argument, NULL, 'i'},
76
         {"tiling", no_argument, NULL, 't'},
77
+        {"no-empty-password", no_argument, NULL, 'e'},
78
         {NULL, no_argument, NULL, 0}
79
     };
80
 
81
     if ((username = getenv("USER")) == NULL)
82
         errx(1, "USER environment variable not set, please set it.\n");
83
 
84
-    while ((o = getopt_long(argc, argv, "hvnbdc:p:ui:t", longopts, &optind)) != -1) {
85
+    while ((o = getopt_long(argc, argv, "hvnbdc:p:ui:te", longopts, &optind)) != -1) {
86
         switch (o) {
87
         case 'v':
88
             errx(EXIT_SUCCESS, "version " VERSION " © 2010-2012 Michael Stapelberg");
89
@@ -582,6 +588,9 @@ int main(int argc, char *argv[]) {
90
                 errx(1, "i3lock: Invalid pointer type given. Expected one of \"win\" or \"default\".\n");
91
             }
92
             break;
93
+        case 'e':
94
+            noempty = true;
95
+            break;
96
         case 0:
97
             if (strcmp(longopts[optind].name, "debug") == 0)
98
                 debug_mode = true;