From 61337df11c231952b1d6e0435223443a133bdab8 Mon Sep 17 00:00:00 2001 From: tangxinfa Date: Sat, 12 Oct 2019 09:25:57 +0800 Subject: [PATCH 1/2] fix: wrong time displayed after system wakeup. When system is hibernated or paused, the lock time draws on the screen may not take effects, when we wakeup our computer, the time displayed is wrong for minutes, use a one second interval timer will fix this problem. --- unlock_indicator.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/unlock_indicator.c b/unlock_indicator.c index 5962574..d8229a4 100644 --- a/unlock_indicator.c +++ b/unlock_indicator.c @@ -33,7 +33,7 @@ /******************************************************************************* * Variables defined in i3lock.c. ******************************************************************************/ -static struct ev_periodic *time_redraw_tick; +static struct ev_timer *time_redraw_tick; extern bool debug_mode; @@ -234,14 +234,13 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { cairo_stroke(ctx); /* Display (centered) Time */ - char *timetext = malloc(6); - + char timetext[100] = {'\0'}; time_t curtime = time(NULL); struct tm *tm = localtime(&curtime); if (use24hour) - strftime(timetext, 100, TIME_FORMAT_24, tm); + strftime(timetext, sizeof(timetext), TIME_FORMAT_24, tm); else - strftime(timetext, 100, TIME_FORMAT_12, tm); + strftime(timetext, sizeof(timetext), TIME_FORMAT_12, tm); /* Text */ set_auth_color('l'); @@ -259,8 +258,6 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { cairo_show_text(ctx, timetext); cairo_close_path(ctx); - free(timetext); - if (auth_state == STATE_AUTH_WRONG && (modifier_string != NULL)) { cairo_text_extents_t extents; double x, y; @@ -370,20 +367,19 @@ void clear_indicator(void) { /* Periodic redraw for clock updates - taken from github.com/ravinrabbid/i3lock-clock */ -static void time_redraw_cb(struct ev_loop *loop, ev_periodic *w, int revents) { +static void time_redraw_cb(struct ev_loop *loop, ev_timer *w, int revents) { redraw_screen(); } void start_time_redraw_tick(struct ev_loop* main_loop) { if (time_redraw_tick) { - ev_periodic_set(time_redraw_tick, 1.0, 60., 0); - ev_periodic_again(main_loop, time_redraw_tick); - } else { - /* When there is no memory, we just don’t have a timeout. We cannot - * exit() here, since that would effectively unlock the screen. */ - if (!(time_redraw_tick = calloc(sizeof(struct ev_periodic), 1))) return; - ev_periodic_init(time_redraw_tick,time_redraw_cb, 1.0, 60., 0); - ev_periodic_start(main_loop, time_redraw_tick); } + + /* When there is no memory, we just don’t have a timeout. We cannot + * exit() here, since that would effectively unlock the screen. */ + if (!(time_redraw_tick = calloc(sizeof(struct ev_timer), 1))) + return; + ev_timer_init(time_redraw_tick, time_redraw_cb, 1.0, 1.0); + ev_timer_start(main_loop, time_redraw_tick); } From edae208cc8683107d2585c0c95a3331c1a088bbd Mon Sep 17 00:00:00 2001 From: tangxinfa Date: Thu, 15 Oct 2020 11:00:10 +0800 Subject: [PATCH 2/2] fix: compilation error --- i3lock.c | 3 +++ unlock_indicator.c | 5 ----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/i3lock.c b/i3lock.c index d13f798..7de5892 100644 --- a/i3lock.c +++ b/i3lock.c @@ -76,6 +76,9 @@ static xcb_cursor_t cursor; #ifndef __OpenBSD__ static pam_handle_t *pam_handle; #endif +/* The current position in the input buffer. Useful to determine if any + * characters of the password have already been entered or not. + */ int input_position = 0; /* Holds the password you enter (in UTF-8). */ static char password[512]; diff --git a/unlock_indicator.c b/unlock_indicator.c index d8229a4..1201557 100644 --- a/unlock_indicator.c +++ b/unlock_indicator.c @@ -37,11 +37,6 @@ static struct ev_timer *time_redraw_tick; extern bool debug_mode; -/* The current position in the input buffer. Useful to determine if any - * characters of the password have already been entered or not. - */ -int input_position; - /* The lock window. */ extern xcb_window_t win;