Browse Source

allow variable refresh rates

idk why you'd do this, but alright
master
Chris Guillott 8 years ago
parent
commit
32d99ccd6f
  1. 15
      i3lock.c
  2. 6
      unlock_indicator.c

15
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");
}
}

6
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);
}
}

Loading…
Cancel
Save