b558d9e8ce57f989f886aa95afcdfb1df39c67f1 — William Casarin 2 months ago 79a250f
not sure if this is the right approach
1 files changed, 30 insertions(+), 3 deletions(-)

M viscal.c
M viscal.c => viscal.c +30 -3
@@ 9,6 9,7 @@ #include <stdlib.h>
  #include <math.h>
  #include <locale.h>
+ #include <stdbool.h>
  
  #define ARRAY_SIZE(array) (sizeof((array))/sizeof((array)[0]))
  


@@ 74,6 75,7 @@ enum source source;
  	const char *source_location;
  	union rgba color;
+ 	bool visible;
  };
  
  struct event {


@@ 537,6 539,7 @@   	ical = &cal->calendars[cal->ncalendars++];
  	ical->calendar = calendar;
+ 	ical->visible = true;
  
  	free((void*)str);
  	return ical;


@@ 1499,11 1502,17 @@ struct ical *to;
  
  	from = &cal->calendars[cal->selected_calendar_ind];
- 
  	cal->selected_calendar_ind =
  		(cal->selected_calendar_ind + 1) % cal->ncalendars;
  
- 	to = &cal->calendars[cal->selected_calendar_ind];
+ 	while((to = &cal->calendars[cal->selected_calendar_ind]) != from && !to->visible) {
+ 		cal->selected_calendar_ind =
+ 			(cal->selected_calendar_ind + 1) % cal->ncalendars;
+ 	}
+ 
+ 	// only one selectable calendar
+ 	if (from == to)
+ 		return;
  
  	printf("using calendar %s\n", to->source_location);
  


@@ 1517,6 1526,14 @@ }
  }
  
+ static void toggle_calendar_visibility(struct cal *cal, int ind)
+ {
+ 	if (ind+1 > cal->ncalendars)
+ 		return;
+ 	cal->calendars[ind].visible =
+ 		!cal->calendars[ind].visible;
+ }
+ 
  static gboolean on_keypress (GtkWidget *widget, GdkEvent *event,
  			     gpointer user_data)
  {


@@ 1573,6 1590,15 @@   		switch (key) {
  
+ 		case '1': case '2': case '3':
+ 		case '4': case '5': case '6':
+ 		case '7': case '8': case '9':
+ 			printf("num %c\n", key);
+ 			int ind = key-'1';
+ 			assert(ind >= 0);
+ 			toggle_calendar_visibility(cal, ind);
+ 			break;
+ 
  		// Ctrl-d
  		case 0x4:
  			cal->scroll += scroll_amt;


@@ 2261,7 2287,8 @@ // draw calendar events
  	for (i = 0; i < cal->nevents; ++i) {
  		struct event *ev = &cal->events[i];
- 		draw_event(cr, cal, ev, selected, get_target(cal));
+ 		if (ev->ical->visible)
+ 			draw_event(cr, cal, ev, selected, get_target(cal));
  	}
  
  	if (cal->selected_event_ind == -1)