From 4fd8f0b11e565587f349b910b3abfd16b611e767 Mon Sep 17 00:00:00 2001
From: Lukas Fleischer <calcurse@cryptocrack.de>
Date: Fri, 17 Oct 2014 22:38:59 +0200
Subject: Only werase() calendar if month is changed

Optimize the monthly view by only erasing the window content when a new
month is selected.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
---
 src/ui-calendar.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

(limited to 'src')

diff --git a/src/ui-calendar.c b/src/ui-calendar.c
index bd8d7fe..d72f71a 100644
--- a/src/ui-calendar.c
+++ b/src/ui-calendar.c
@@ -309,6 +309,10 @@ draw_monthly_view(struct scrollwin *sw, struct date *current_day,
 
 	/* Write the current month and year on top of the calendar */
 	WINS_CALENDAR_LOCK;
+	if (yr * YEARINMONTHS + mo != monthly_view_cache_month) {
+		/* erase the window if a new month is selected */
+		werase(sw_cal.inner);
+	}
 	custom_apply_attr(sw->inner, ATTR_HIGHEST);
 	mvwprintw(sw->inner, ofs_y,
 		  (w - (strlen(_(monthnames[mo - 1])) + 5)) / 2,
@@ -491,6 +495,7 @@ draw_weekly_view(struct scrollwin *sw, struct date *current_day,
 	/* Print the week number. */
 	weeknum = ISO8601weeknum(&t);
 	WINS_CALENDAR_LOCK;
+	werase(sw_cal.inner);
 	custom_apply_attr(sw->inner, ATTR_HIGHEST);
 	mvwprintw(sw->win, conf.compact_panels ? 0 : 2, sw->w - 9,
 		  "(# %02d)", weeknum);
@@ -596,15 +601,8 @@ void ui_calendar_update_panel(void)
 	unsigned sunday_first;
 
 	ui_calendar_store_current_date(&current_day);
-
-	WINS_CALENDAR_LOCK;
-	werase(sw_cal.inner);
-	WINS_CALENDAR_UNLOCK;
-
-	sunday_first = ui_calendar_week_begins_on_monday()? 0 : 1;
-
+	sunday_first = !ui_calendar_week_begins_on_monday();
 	draw_calendar[ui_calendar_view] (&sw_cal, &current_day, sunday_first);
-
 	wins_scrollwin_display(&sw_cal);
 }
 
-- 
cgit v1.2.3-70-g09d2