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; int internal_line_source = 0;
/* bool for showing the clock; why am I commenting this? */ /* bool for showing the clock; why am I commenting this? */
bool show_clock = false; 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]; uint32_t last_resolution[2];
xcb_window_t win; xcb_window_t win;
@ -849,7 +856,10 @@ int main(int argc, char *argv[]) {
{"line-uses-inside", no_argument, NULL, 's'}, {"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 */ /* 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'}, {"screen", required_argument, NULL, 'S'},
{"clock", no_argument, NULL, 'k'}, {"clock", no_argument, NULL, 'k'},
{"timestr", required_argument, NULL, 0},
{"datestr", required_argument, NULL, 0},
{"ignore-empty-password", no_argument, NULL, 'e'}, {"ignore-empty-password", no_argument, NULL, 'e'},
{"inactivity-timeout", required_argument, NULL, 'I'}, {"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) 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"); 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; break;
case 'f': case 'f':
show_failed_attempts = true; 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 * received up until now. ev will only pick up new events (when the X11
* file descriptor becomes readable). */ * file descriptor becomes readable). */
ev_invoke(main_loop, xcb_check, 0); ev_invoke(main_loop, xcb_check, 0);
if (show_clock) { if (show_clock) {
start_time_redraw_tick(main_loop); start_time_redraw_tick(main_loop);
} }
ev_loop(main_loop, 0); ev_loop(main_loop, 0);
} }

15
unlock_indicator.c

@ -75,7 +75,8 @@ extern int internal_line_source;
extern int screen_number; extern int screen_number;
extern bool show_clock; extern bool show_clock;
extern char time_format[32];
extern char date_format[32];
/* Whether the failed attempts should be displayed. */ /* Whether the failed attempts should be displayed. */
extern bool show_failed_attempts; extern bool show_failed_attempts;
/* Number of failed unlock 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)) { (unlock_state >= STATE_KEY_PRESSED || pam_state > STATE_PAM_IDLE || show_clock)) {
cairo_scale(ctx, scaling_factor(), scaling_factor()); cairo_scale(ctx, scaling_factor(), scaling_factor());
/* Draw a (centered) circle with transparent background. */ /* Draw a (centered) circle with transparent background. */
cairo_set_line_width(ctx, 10.0); cairo_set_line_width(ctx, 7.0);
cairo_arc(ctx, cairo_arc(ctx,
BUTTON_CENTER /* x */, BUTTON_CENTER /* x */,
BUTTON_CENTER /* y */, 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_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); cairo_set_font_size(ctx, 32.0);
} else if (show_clock) { } else if (show_clock) {
// TODO: allow for custom string times strftime(time_text, 40, time_format, timeinfo);
strftime(time_text, 40, "%R", timeinfo); strftime(date_text, 40, date_format, timeinfo);
strftime(date_text, 40, "%a %m. %b", timeinfo);
text = time_text; text = time_text;
date = date_text; date = date_text;
} }
@ -452,6 +452,7 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
/* For backspace, we use red. */ //lol no /* 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_set_source_rgba(ctx, (double)bshl16[0]/255, (double)bshl16[1]/255, (double)bshl16[2]/255, (double)bshl16[3]/255);
} }
cairo_stroke(ctx); cairo_stroke(ctx);
/* Draw two little separators for the highlighted part of the /* 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) { void start_time_redraw_tick(struct ev_loop* main_loop) {
if (time_redraw_tick) { 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); ev_periodic_again(main_loop, time_redraw_tick);
} else { } else {
if (!(time_redraw_tick = calloc(sizeof(struct ev_periodic), 1))) { if (!(time_redraw_tick = calloc(sizeof(struct ev_periodic), 1))) {
return; 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); 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 redraw_screen(void);
void clear_indicator(void); void clear_indicator(void);
void start_time_redraw_timeout(void); void start_time_redraw_timeout(void);
void start_time_redraw_tick(struct ev_loop*);
#endif #endif

Loading…
Cancel
Save