summaryrefslogtreecommitdiffstats
path: root/src/calendar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/calendar.c')
-rw-r--r--src/calendar.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/calendar.c b/src/calendar.c
index df247df..0eebd4e 100644
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -77,6 +77,10 @@ static void (*draw_calendar[CAL_VIEWS]) (struct window *, struct date *,
unsigned) = {
draw_monthly_view, draw_weekly_view};
+static int monthly_view_cache[MAXDAYSPERMONTH];
+static int monthly_view_cache_valid = 0;
+static int monthly_view_cache_month = 0;
+
/* Switch between calendar views (monthly view is selected by default). */
void calendar_view_next(void)
{
@@ -264,12 +268,17 @@ static int date_change(struct tm *date, int delta_month, int delta_day)
}
}
+void calendar_monthly_view_cache_set_invalid(void)
+{
+ monthly_view_cache_valid = 0;
+}
+
/* Draw the monthly view inside calendar panel. */
static void
draw_monthly_view(struct window *cwin, struct date *current_day,
unsigned sunday_first)
{
- const int OFFY = 2 + (CALHEIGHT - 9) / 2;
+ const int OFFY = CALHEIGHT / 2 - (conf.compact_panels ? 3 : 1);
struct date check_day;
int c_day, c_day_1, day_1_sav, numdays, j;
unsigned yr, mo;
@@ -315,13 +324,25 @@ draw_monthly_view(struct window *cwin, struct date *current_day,
day_1_sav = (c_day_1 + 1) * 3 + c_day_1 - 7;
+ /* invalidate cache if a new month is selected */
+ if (yr * YEARINMONTHS + mo != monthly_view_cache_month) {
+ monthly_view_cache_month = yr * YEARINMONTHS + mo;
+ monthly_view_cache_valid = 0;
+ }
+
for (c_day = 1; c_day <= numdays; ++c_day, ++c_day_1, c_day_1 %= 7) {
check_day.dd = c_day;
check_day.mm = slctd_day.mm;
check_day.yyyy = slctd_day.yyyy;
/* check if the day contains an event or an appointment */
- item_this_day = day_check_if_item(check_day);
+ if (monthly_view_cache_valid) {
+ item_this_day = monthly_view_cache[c_day - 1];
+ }
+ else {
+ item_this_day = monthly_view_cache[c_day - 1] =
+ day_check_if_item(check_day);
+ }
/* Go to next line, the week is over. */
if (!c_day_1 && 1 != c_day) {
@@ -357,6 +378,8 @@ draw_monthly_view(struct window *cwin, struct date *current_day,
}
WINS_CALENDAR_UNLOCK;
}
+
+ monthly_view_cache_valid = 1;
}
static int weeknum(const struct tm *t, int firstweekday)
@@ -437,7 +460,7 @@ draw_weekly_view(struct window *cwin, struct date *current_day,
{
#define DAYSLICESNO 6
const int WCALWIDTH = 30;
- const int OFFY = 2 + (CALHEIGHT - 9) / 2;
+ const int OFFY = CALHEIGHT / 2 - (conf.compact_panels ? 3 : 1);
struct tm t;
int OFFX, j, c_wday, days_to_remove, weeknum;
@@ -461,7 +484,8 @@ draw_weekly_view(struct window *cwin, struct date *current_day,
weeknum = ISO8601weeknum(&t);
WINS_CALENDAR_LOCK;
custom_apply_attr(cwin->p, ATTR_HIGHEST);
- mvwprintw(cwin->p, 2, cwin->w - 9, "(# %02d)", weeknum);
+ mvwprintw(cwin->p, conf.compact_panels ? 0 : 2, cwin->w - 9, "(# %02d)",
+ weeknum);
custom_remove_attr(cwin->p, ATTR_HIGHEST);
WINS_CALENDAR_UNLOCK;
@@ -555,8 +579,10 @@ void calendar_update_panel(struct window *cwin)
calendar_store_current_date(&current_day);
WINS_CALENDAR_LOCK;
- erase_window_part(cwin->p, 1, 3, cwin->w - 2, cwin->h - 2);
- mvwhline(cwin->p, 2, 1, ACS_HLINE, cwin->w - 2);
+ erase_window_part(cwin->p, 1, conf.compact_panels ? 1 : 3, cwin->w - 2,
+ cwin->h - 2);
+ if (!conf.compact_panels)
+ mvwhline(cwin->p, 2, 1, ACS_HLINE, cwin->w - 2);
WINS_CALENDAR_UNLOCK;
sunday_first = calendar_week_begins_on_monday()? 0 : 1;