From 32d99ccd6f81179aa114dadfb4b47fba18a8ae44 Mon Sep 17 00:00:00 2001 From: Chris Guillott Date: Mon, 22 May 2017 13:05:11 -0500 Subject: [PATCH] allow variable refresh rates idk why you'd do this, but alright --- i3lock.c | 15 ++++++++++++++- unlock_indicator.c | 6 ++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/i3lock.c b/i3lock.c index 6051ed0..f9ef53b 100644 --- a/i3lock.c +++ b/i3lock.c @@ -79,6 +79,7 @@ int internal_line_source = 0; /* bool for showing the clock; why am I commenting this? */ bool show_clock = false; bool show_indicator = false; +float refresh_rate = 1.0; /* time formatter strings for date/time I picked 32-length char arrays because some people might want really funky time formatters. Who am I to judge? @@ -912,6 +913,8 @@ int main(int argc, char *argv[]) { {"clock", no_argument, NULL, 'k'}, {"indicator", no_argument, NULL, 0}, + {"refresh-rate", required_argument, NULL, 0}, + {"timestr", required_argument, NULL, 0}, {"datestr", required_argument, NULL, 0}, {"timefont", required_argument, NULL, 0}, @@ -1209,14 +1212,24 @@ int main(int argc, char *argv[]) { errx(1, "datepos must be of the form x:y\n"); } } + else if (strcmp(longopts[optind].name, "refresh-rate") == 0) { + //read in to date_x_expr and date_y_expr + char* arg = optarg; + refresh_rate = strtof(arg, NULL); + if (refresh_rate < 1.0) { + fprintf(stderr, "The given refresh rate of %fs is less than one second and was ignored.\n", refresh_rate); + refresh_rate = 1.0; + } + } break; case 'f': show_failed_attempts = true; break; default: + // TODO: clean this up, use newlines errx(EXIT_FAILURE, "Syntax: i3lock-color [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]" " [-i image.png] [-t] [-e] [-I timeout] [-f] [-r|s] [-S screen_number] [-k]" - " [-B blur_strength] [--variety-of-color-args=rrggbbaa]"); + " [-B blur_strength] [--indicator] [--refresh-rate rate] [--variety-of-color-args=rrggbbaa] [--[time|date][pos|color|font|size]=[arg]]\n"); } } diff --git a/unlock_indicator.c b/unlock_indicator.c index 2467fe9..229f6ae 100644 --- a/unlock_indicator.c +++ b/unlock_indicator.c @@ -78,6 +78,7 @@ extern char separatorcolor[9]; extern int internal_line_source; extern int screen_number; +extern float refresh_rate; extern bool show_clock; extern bool show_indicator; @@ -671,14 +672,15 @@ static void time_redraw_cb(struct ev_loop *loop, ev_periodic *w, int revents) { } void start_time_redraw_tick(struct ev_loop* main_loop) { + fprintf(stderr, "redraw rate: %f\n", refresh_rate); if (time_redraw_tick) { - ev_periodic_set(time_redraw_tick, 0., 1.0, 0); + ev_periodic_set(time_redraw_tick, 0., refresh_rate, 0); ev_periodic_again(main_loop, time_redraw_tick); } else { if (!(time_redraw_tick = calloc(sizeof(struct ev_periodic), 1))) { return; } - ev_periodic_init(time_redraw_tick, time_redraw_cb, 0., 1., 0); + ev_periodic_init(time_redraw_tick, time_redraw_cb, 0., refresh_rate, 0); ev_periodic_start(main_loop, time_redraw_tick); } }