i3 - improved tiling WM


Delay to turn off the screen after wrong passwd

Patch status: merged

Patch by Vytautas Šaltenis

Long description:

Also add flag for number of seconds to wait for it.

When user cancels the password or enters a wrong one, i3lock will wait
for some time before putting the monitors back to sleep. By default it's
30 seconds, but this flag allows to control that.

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

b/i3lock.1

19
@@ -28,6 +28,7 @@ i3lock \- improved screen locker
20
 .IR pointer\|]
21
 .RB [\|\-u\|]
22
 .RB [\|\-e\|]
23
+.RB [\|\-I\|]
24
 
25
 .SH DESCRIPTION
26
 .B i3lock
27
@@ -69,6 +70,13 @@ option, DPMS will turn off your screen after 15 minutes of inactivity anyways (i
28
 you did not disable this in your X server).
29
 
30
 .TP
31
+.B \-I, \-\-inactivity-timeout
32
+Specifies the number of seconds i3lock will wait for another password before
33
+turning off the monitors, in case you entered a wrong password or canceled by
34
+pressing Escape. Only makes sense together with \-d. If omitted, the default is
35
+30 seconds.
36
+
37
+.TP
38
 .B \-u, \-\-no-unlock-indicator
39
 Disable the unlock indicator. i3lock will by default show an unlock indicator
40
 after pressing keys. This will give feedback for every keypress and it will

b/i3lock.c

45
@@ -34,6 +34,7 @@
46
 #include "unlock_indicator.h"
47
 #include "xinerama.h"
48
 
49
+#define TSTAMP_N_SECS(n) (n * 1.0)
50
 #define START_TIMER(timer_obj, timeout, callback) \
51
     timer_obj = start_timer(timer_obj, timeout, callback)
52
 #define STOP_TIMER(timer_obj) \
53
@@ -44,6 +45,7 @@ typedef void (*ev_callback_t)(EV_P_ ev_timer *w, int revents);
54
 /* We need this for libxkbfile */
55
 static Display *display;
56
 char color[7] = "ffffff";
57
+int inactivity_timeout = 30;
58
 uint32_t last_resolution[2];
59
 xcb_window_t win;
60
 static xcb_cursor_t cursor;
61
@@ -59,6 +61,7 @@ static bool dont_fork = false;
62
 struct ev_loop *main_loop;
63
 static struct ev_timer *clear_pam_wrong_timeout;
64
 static struct ev_timer *clear_indicator_timeout;
65
+static struct ev_timer *dpms_timeout;
66
 extern unlock_state_t unlock_state;
67
 extern pam_state_t pam_state;
68
 
69
@@ -246,6 +249,13 @@ static void clear_input(void) {
70
     unlock_state = STATE_KEY_PRESSED;
71
 }
72
 
73
+static void turn_off_monitors_cb(EV_P_ ev_timer *w, int revents) {
74
+    if (input_position == 0)
75
+        turn_monitors_off();
76
+
77
+    STOP_TIMER(dpms_timeout);
78
+}
79
+
80
 static void input_done(void) {
81
     if (clear_pam_wrong_timeout) {
82
         ev_timer_stop(main_loop, clear_pam_wrong_timeout);
83
@@ -545,10 +555,11 @@ static void xcb_check_cb(EV_P_ ev_check *w, int revents) {
84
                 handle_key_release((xcb_key_release_event_t*)event);
85
 
86
                 /* If this was the backspace or escape key we are back at an
87
-                 * empty input, so turn off the screen if DPMS is enabled */
88
-                if (input_position == 0)
89
-                    turn_monitors_off();
90
-
91
+                 * empty input, so turn off the screen if DPMS is enabled, but
92
+                 * only do that after some timeout: maybe user mistyped and
93
+                 * will type again right away */
94
+                START_TIMER(dpms_timeout, TSTAMP_N_SECS(inactivity_timeout),
95
+                            turn_off_monitors_cb);
96
                 break;
97
 
98
             case XCB_VISIBILITY_NOTIFY:
99
@@ -660,13 +671,15 @@ int main(int argc, char *argv[]) {
100
         {"image", required_argument, NULL, 'i'},
101
         {"tiling", no_argument, NULL, 't'},
102
         {"ignore-empty-password", no_argument, NULL, 'e'},
103
+        {"inactivity-timeout", required_argument, NULL, 'I'},
104
         {NULL, no_argument, NULL, 0}
105
     };
106
 
107
     if ((username = getenv("USER")) == NULL)
108
         errx(EXIT_FAILURE, "USER environment variable not set, please set it.\n");
109
 
110
-    while ((o = getopt_long(argc, argv, "hvnbdc:p:ui:te", longopts, &optind)) != -1) {
111
+    char *optstring = "hvnbdc:p:ui:teI:";
112
+    while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) {
113
         switch (o) {
114
         case 'v':
115
             errx(EXIT_SUCCESS, "version " VERSION " © 2010-2012 Michael Stapelberg");
116
@@ -679,6 +692,13 @@ int main(int argc, char *argv[]) {
117
         case 'd':
118
             dpms = true;
119
             break;
120
+        case 'I': {
121
+            int time = 0;
122
+            if (sscanf(optarg, "%d", &time) != 1 || time < 0)
123
+                errx(EXIT_FAILURE, "invalid timeout, it must be a positive integer\n");
124
+            inactivity_timeout = time;
125
+            break;
126
+        }
127
         case 'c': {
128
             char *arg = optarg;
129
 
130
@@ -718,7 +738,7 @@ int main(int argc, char *argv[]) {
131
             break;
132
         default:
133
             errx(EXIT_FAILURE, "Syntax: i3lock [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]"
134
-            " [-i image.png] [-t] [-e]"
135
+            " [-i image.png] [-t] [-e] [-I]"
136
             );
137
         }
138
     }