Browse Source

add custom time formatter strings

master
Chris Guillott 8 years ago
parent
commit
e4301604e5
  1. 28
      i3lock.c
  2. 15
      unlock_indicator.c
  3. 2
      unlock_indicator.h

28
i3lock.c

@ -68,6 +68,13 @@ int screen_number = -1;
int internal_line_source = 0;
/* bool for showing the clock; why am I commenting this? */
bool show_clock = false;
/* 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?
*/
char time_format[32] = "%R\0";
char date_format[32] = "%a %m. %b\0";
uint32_t last_resolution[2];
xcb_window_t win;
@ -849,7 +856,10 @@ int main(int argc, char *argv[]) {
{"line-uses-inside", no_argument, NULL, 's'},
/* s for in_s_ide; ideally I'd use -I but that's used for timeout, which should use -T, but compatibility argh */
{"screen", required_argument, NULL, 'S'},
{"clock", no_argument, NULL, 'k'},
{"timestr", required_argument, NULL, 0},
{"datestr", required_argument, NULL, 0},
{"ignore-empty-password", no_argument, NULL, 'e'},
{"inactivity-timeout", required_argument, NULL, 'I'},
@ -1044,6 +1054,20 @@ int main(int argc, char *argv[]) {
if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", separatorcolor) != 1)
errx(1, "separator is invalid, color must be given in 8-byte format: rrggbb\n");
}
else if (strcmp(longopts[optind].name, "timestr") == 0) {
//read in to timestr
if (strlen(optarg) > 31) {
errx(1, "time format string can be at most 31 characters");
}
strcpy(time_format,optarg);
}
else if (strcmp(longopts[optind].name, "datestr") == 0) {
//read in to datestr
if (strlen(optarg) > 31) {
errx(1, "time format string can be at most 31 characters");
}
strcpy(date_format,optarg);
}
break;
case 'f':
show_failed_attempts = true;
@ -1215,8 +1239,8 @@ int main(int argc, char *argv[]) {
* received up until now. ev will only pick up new events (when the X11
* file descriptor becomes readable). */
ev_invoke(main_loop, xcb_check, 0);
if (show_clock) {
start_time_redraw_tick(main_loop);
if (show_clock) {
start_time_redraw_tick(main_loop);
}
ev_loop(main_loop, 0);
}

15
unlock_indicator.c

@ -75,7 +75,8 @@ extern int internal_line_source;
extern int screen_number;
extern bool show_clock;
extern char time_format[32];
extern char date_format[32];
/* Whether the failed attempts should be displayed. */
extern bool show_failed_attempts;
/* Number of failed unlock attempts. */
@ -263,7 +264,7 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
(unlock_state >= STATE_KEY_PRESSED || pam_state > STATE_PAM_IDLE || show_clock)) {
cairo_scale(ctx, scaling_factor(), scaling_factor());
/* Draw a (centered) circle with transparent background. */
cairo_set_line_width(ctx, 10.0);
cairo_set_line_width(ctx, 7.0);
cairo_arc(ctx,
BUTTON_CENTER /* x */,
BUTTON_CENTER /* y */,
@ -373,9 +374,8 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
cairo_set_source_rgba(ctx, (double)text16[0]/255, (double)text16[1]/255, (double)text16[2]/255, (double)text16[3]/255);
cairo_set_font_size(ctx, 32.0);
} else if (show_clock) {
// TODO: allow for custom string times
strftime(time_text, 40, "%R", timeinfo);
strftime(date_text, 40, "%a %m. %b", timeinfo);
strftime(time_text, 40, time_format, timeinfo);
strftime(date_text, 40, date_format, timeinfo);
text = time_text;
date = date_text;
}
@ -452,6 +452,7 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
/* For backspace, we use red. */ //lol no
cairo_set_source_rgba(ctx, (double)bshl16[0]/255, (double)bshl16[1]/255, (double)bshl16[2]/255, (double)bshl16[3]/255);
}
cairo_stroke(ctx);
/* Draw two little separators for the highlighted part of the
@ -544,13 +545,13 @@ static void time_redraw_cb(struct ev_loop *loop, ev_periodic *w, int revents) {
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_set(time_redraw_tick, 0., 1.0, 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, 1.0, 60., 0);
ev_periodic_init(time_redraw_tick, time_redraw_cb, 0., 1., 0);
ev_periodic_start(main_loop, time_redraw_tick);
}
}

2
unlock_indicator.h

@ -22,5 +22,5 @@ xcb_pixmap_t draw_image(uint32_t* resolution);
void redraw_screen(void);
void clear_indicator(void);
void start_time_redraw_timeout(void);
void start_time_redraw_tick(struct ev_loop*);
#endif

Loading…
Cancel
Save