i3 - improved tiling WM


implemented logging the number of failed attempts

Patch status: needinfo

Patch by koebi

Long description:

This closes #1243

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

b/i3lock.1

16
@@ -115,6 +115,10 @@ another try. This can be useful if the XF86ScreenSaver key is used to
17
 put a laptop to sleep and bounce on resume or if you happen to wake up
18
 your computer with the enter key.
19
 
20
+.TP
21
+.B \-f, \-\-failed-attempts
22
+Show the number of failed attempts, if any.
23
+
24
 .SH SEE ALSO
25
 .IR xautolock(1)
26
 \- use i3lock as your screen saver

b/i3lock.c

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

b/unlock_indicator.c

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