i3 - improved tiling WM


Cleanup scattered timer calls to use macros

Patch status: merged

Patch by Vytautas Ĺ altenis

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

b/i3lock.c

13
@@ -229,9 +229,7 @@ static void clear_pam_wrong(EV_P_ ev_timer *w, int revents) {
14
     redraw_screen();
15
 
16
     /* Now free this timeout. */
17
-    ev_timer_stop(main_loop, clear_pam_wrong_timeout);
18
-    free(clear_pam_wrong_timeout);
19
-    clear_pam_wrong_timeout = NULL;
20
+    STOP_TIMER(clear_pam_wrong_timeout);
21
 }
22
 
23
 static void clear_indicator_cb(EV_P_ ev_timer *w, int revents) {
24
@@ -266,12 +264,7 @@ static void discard_passwd_cb(EV_P_ ev_timer *w, int revents) {
25
 }
26
 
27
 static void input_done(void) {
28
-    if (clear_pam_wrong_timeout) {
29
-        ev_timer_stop(main_loop, clear_pam_wrong_timeout);
30
-        free(clear_pam_wrong_timeout);
31
-        clear_pam_wrong_timeout = NULL;
32
-    }
33
-
34
+    STOP_TIMER(clear_pam_wrong_timeout);
35
     pam_state = STATE_PAM_VERIFY;
36
     redraw_screen();
37
 
38
@@ -294,10 +287,7 @@ static void input_done(void) {
39
     /* Clear this state after 2 seconds (unless the user enters another
40
      * password during that time). */
41
     ev_now_update(main_loop);
42
-    if ((clear_pam_wrong_timeout = calloc(sizeof(struct ev_timer), 1))) {
43
-        ev_timer_init(clear_pam_wrong_timeout, clear_pam_wrong, 2.0, 0.);
44
-        ev_timer_start(main_loop, clear_pam_wrong_timeout);
45
-    }
46
+    START_TIMER(clear_pam_wrong_timeout, TSTAMP_N_SECS(2), clear_pam_wrong);
47
 
48
     /* Cancel the clear_indicator_timeout, it would hide the unlock indicator
49
      * too early. */
50
@@ -321,9 +311,7 @@ static void handle_key_release(xcb_key_release_event_t *event) {
51
 
52
 static void redraw_timeout(EV_P_ ev_timer *w, int revents) {
53
     redraw_screen();
54
-
55
-    ev_timer_stop(main_loop, w);
56
-    free(w);
57
+    STOP_TIMER(w);
58
 }
59
 
60
 static bool skip_without_validation(void) {
61
@@ -430,12 +418,8 @@ static void handle_key_press(xcb_key_press_event_t *event) {
62
     redraw_screen();
63
     unlock_state = STATE_KEY_PRESSED;
64
 
65
-    struct ev_timer *timeout = calloc(sizeof(struct ev_timer), 1);
66
-    if (timeout) {
67
-        ev_timer_init(timeout, redraw_timeout, 0.25, 0.);
68
-        ev_timer_start(main_loop, timeout);
69
-    }
70
-
71
+    struct ev_timer *timeout = NULL;
72
+    START_TIMER(timeout, TSTAMP_N_SECS(0.25), redraw_timeout);
73
     STOP_TIMER(clear_indicator_timeout);
74
     START_TIMER(discard_passwd_timeout, TSTAMP_N_MINS(3), discard_passwd_cb);
75
 }