Skip to content

Commit

Permalink
fix: wrong time displayed after system wakeup.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tangxinfa committed Nov 5, 2019
1 parent be2a08a commit 61337df
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions unlock_indicator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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');
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

0 comments on commit 61337df

Please sign in to comment.