From: Andy Spencer Date: Sun, 27 Nov 2016 08:12:55 +0000 (+0000) Subject: Auto select the first event from calendar X-Git-Url: http://pileus.org/git/?p=lackey;a=commitdiff_plain;h=22c454ba9b8a3493f83bb05f145e1398735d0fbc;ds=sidebyside Auto select the first event from calendar If the calendar listed on the command line as an event in the future, select soonest upcoming event. If all the events are in the past, then just pick the first event in the calendar. --- diff --git a/src/args.c b/src/args.c index d7a6c68..d577fdc 100644 --- a/src/args.c +++ b/src/args.c @@ -38,8 +38,9 @@ struct option long_options[] = { {"week", 2, NULL, 'w'}, }; -static int print_day = 0; -static int print_week = 0; +static int print_day = 0; +static int print_week = 0; +static char *calendar = NULL; /* Usage */ static void usage(char *name) @@ -83,6 +84,9 @@ void args_init(void) } } + /* Save default calendar */ + calendar = argv[optind]; + /* Load calendars */ for (int i = optind; i < argc; i++) cal_config("ical", argv[i], "location", argv[i]); @@ -94,6 +98,23 @@ void args_init(void) void args_main(void) { + /* Focus the default calendar */ + if (calendar) { + event_t *event = EVENTS; + date_t start = {SEL.year, SEL.month, SEL.day, 0, 0}; + while (event && compare(&start, &event->start) > 0) + event = event->next; + while (event && !match(calendar, event->cal->name)) + event = event->next; + if (!event) + event = EVENTS; + while (event && !match(calendar, event->cal->name)) + event = event->next; + if (event) + SEL = event->start; + } + + /* Print days or week */ if (print_day || print_week) { event_t *event = EVENTS; for (int d = 0; d < (print_day ? 1 : 7); d++) {