i3 - improved tiling WM


implemented logging the number of failed attempts

Patch status: merged

Patch by koebi

Long description:

This closes #1243

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

b/i3lock.1

16
@@ -29,6 +29,7 @@ i3lock \- improved screen locker
17
 .RB [\|\-u\|]
18
 .RB [\|\-e\|]
19
 .RB [\|\-I\|]
20
+.RB [\|\-f\|]
21
 
22
 .SH DESCRIPTION
23
 .B i3lock
24
@@ -115,6 +116,10 @@ another try. This can be useful if the XF86ScreenSaver key is used to
25
 put a laptop to sleep and bounce on resume or if you happen to wake up
26
 your computer with the enter key.
27
 
28
+.TP
29
+.B \-f, \-\-show-failed-attempts
30
+Show the number of failed attempts, if any.
31
+
32
 .SH SEE ALSO
33
 .IR xautolock(1)
34
 \- use i3lock as your screen saver

b/i3lock.c

39
@@ -64,6 +64,8 @@ static struct ev_timer *dpms_timeout;
40
 static struct ev_timer *discard_passwd_timeout;
41
 extern unlock_state_t unlock_state;
42
 extern pam_state_t pam_state;
43
+int failed_attempts = 0;
44
+bool show_failed_attempts = false;
45
 
46
 static struct xkb_state *xkb_state;
47
 static struct xkb_context *xkb_context;
48
@@ -239,6 +241,7 @@ static void input_done(void) {
49
         fprintf(stderr, "Authentication failure\n");
50
 
51
     pam_state = STATE_PAM_WRONG;
52
+    failed_attempts += 1;
53
     clear_input();
54
     redraw_screen();
55
 
56
@@ -671,13 +674,14 @@ int main(int argc, char *argv[]) {
57
         {"tiling", no_argument, NULL, 't'},
58
         {"ignore-empty-password", no_argument, NULL, 'e'},
59
         {"inactivity-timeout", required_argument, NULL, 'I'},
60
+        {"show-failed-attempts", no_argument, NULL, 'f'},
61
         {NULL, no_argument, NULL, 0}
62
     };
63
 
64
     if ((username = getenv("USER")) == NULL)
65
         errx(EXIT_FAILURE, "USER environment variable not set, please set it.\n");
66
 
67
-    char *optstring = "hvnbdc:p:ui:teI:";
68
+    char *optstring = "hvnbdc:p:ui:teI:f";
69
     while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) {
70
         switch (o) {
71
         case 'v':
72
@@ -735,9 +739,12 @@ int main(int argc, char *argv[]) {
73
             if (strcmp(longopts[optind].name, "debug") == 0)
74
                 debug_mode = true;
75
             break;
76
+        case 'f':
77
+            show_failed_attempts = true;
78
+            break;
79
         default:
80
             errx(EXIT_FAILURE, "Syntax: i3lock [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]"
81
-            " [-i image.png] [-t] [-e] [-I]"
82
+            " [-i image.png] [-t] [-e] [-I] [-f]"
83
             );
84
         }
85
     }

b/unlock_indicator.c

90
@@ -52,6 +52,11 @@ extern bool tile;
91
 /* The background color to use (in hex). */
92
 extern char color[7];
93
 
94
+/* Whether the failed attempts should be displayed. */
95
+extern bool show_failed_attempts;
96
+/* Number of failed unlock attempts. */
97
+extern int failed_attempts;
98
+
99
 /*******************************************************************************
100
  * Variables defined in xcb.c.
101
  ******************************************************************************/
102
@@ -185,6 +190,11 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
103
 
104
         /* Display a (centered) text of the current PAM state. */
105
         char *text = NULL;
106
+        /* We don't want to show more than a 3-digit number. */
107
+        char buf[4];
108
+
109
+        cairo_set_source_rgb(ctx, 0, 0, 0);
110
+        cairo_set_font_size(ctx, 28.0);
111
         switch (pam_state) {
112
             case STATE_PAM_VERIFY:
113
                 text = "verifying…";
114
@@ -193,6 +203,16 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
115
                 text = "wrong!";
116
                 break;
117
             default:
118
+                if (show_failed_attempts && failed_attempts > 0){
119
+                    if (failed_attempts > 999) {
120
+                        text = "> 999";
121
+                    } else {
122
+                        snprintf(buf, sizeof(buf), "%d", failed_attempts);
123
+                        text = buf;
124
+                    }
125
+                    cairo_set_source_rgb(ctx, 1, 0, 0);
126
+                    cairo_set_font_size(ctx, 32.0);
127
+                }
128
                 break;
129
         }
130
 
131
@@ -200,9 +220,6 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
132
             cairo_text_extents_t extents;
133
             double x, y;
134
 
135
-            cairo_set_source_rgb(ctx, 0, 0, 0);
136
-            cairo_set_font_size(ctx, 28.0);
137
-
138
             cairo_text_extents(ctx, text, &extents);
139
             x = BUTTON_CENTER - ((extents.width / 2) + extents.x_bearing);
140
             y = BUTTON_CENTER - ((extents.height / 2) + extents.y_bearing);