assign a pad for each window

Create a pad for each pm blocks, so we can use the same code
to scroll the values on the display.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
diff --git a/display.c b/display.c
index 3795547..b417459 100644
--- a/display.c
+++ b/display.c
@@ -31,10 +31,6 @@
 };
 
 static WINDOW *header_win;
-static WINDOW *regulator_win;
-static WINDOW *clock_pad;
-static WINDOW *clock_labels;
-static WINDOW *sensor_win;
 static WINDOW *footer_win;
 
 int maxx, maxy;
@@ -50,6 +46,8 @@
 };
 
 struct windata {
+	WINDOW *win;
+	WINDOW *pad;
 	struct rowdata *rowdata;
 	char *name;
 	int nrdata;
@@ -70,6 +68,9 @@
 
 int display_init(void)
 {
+	int i;
+	size_t array_size = sizeof(windata) / sizeof(windata[0]);
+
 	if (!initscr())
 		return -1;
 
@@ -97,21 +98,17 @@
 
 	getmaxyx(stdscr, maxy, maxx);
 
-	regulator_win = subwin(stdscr, maxy - 2, maxx, 1, 0);
-	if (!regulator_win)
-		return -1;
+	for (i = 0; i < array_size; i++) {
 
-	clock_labels = subwin(stdscr, maxy - 2, maxx, 1, 0);
-	if (!clock_labels)
-		return -1;
+		windata[i].win = subwin(stdscr, maxy - 2, maxx, 1, 0);
+		if (!windata[i].win)
+			return -1;
 
-	clock_pad = newpad(maxrows, maxx);
-	if (!clock_pad)
-		return -1;
+		windata[i].pad = newpad(maxrows, maxx);
+		if (!windata[i].pad)
+			return -1;
 
-	sensor_win = subwin(stdscr, maxy - 2, maxx, 1, 0);
-	if (!sensor_win)
-		return -1;
+	}
 
 	header_win = subwin(stdscr, 1, maxx, 0, 0);
 	if (!header_win)
@@ -142,17 +139,9 @@
 
 }
 
-void create_selectedwindow(int selectedwindow)
+void create_selectedwindow(int win)
 {
-	switch (selectedwindow) {
-	case REGULATOR:
-		wrefresh(regulator_win);
-		break;
-
-	case SENSOR:
-		wrefresh(sensor_win);
-		break;
-	}
+	wrefresh(windata[win].win);
 }
 
 void show_header(int selectedwindow)
@@ -192,6 +181,8 @@
 
 void print_regulator_header(void)
 {
+	WINDOW *regulator_win = windata[REGULATOR].win;
+
 	werase(regulator_win);
 	wattron(regulator_win, A_BOLD);
 	print(regulator_win, 0, 0, "Name");
@@ -208,73 +199,23 @@
 
 void print_clock_header(void)
 {
-	werase(clock_labels);
-	wattron(clock_labels, A_BOLD);
-	print(clock_labels, 0, 0, "Name");
-	print(clock_labels, 56, 0, "Flags");
-	print(clock_labels, 75, 0, "Rate");
-	print(clock_labels, 88, 0, "Usecount");
-	print(clock_labels, 98, 0, "Children");
-	wattroff(clock_labels, A_BOLD);
-	wrefresh(clock_labels);
+	WINDOW *clock_win = windata[CLOCK].win;
+
+	werase(clock_win);
+	wattron(clock_win, A_BOLD);
+	print(clock_win, 0, 0, "Name");
+	print(clock_win, 56, 0, "Flags");
+	print(clock_win, 75, 0, "Rate");
+	print(clock_win, 88, 0, "Usecount");
+	print(clock_win, 98, 0, "Children");
+	wattroff(clock_win, A_BOLD);
+	wrefresh(clock_win);
 }
 
-#if 0
-void show_regulator_info(struct regulator_info *reg_info, int nr_reg, int verbose)
-{
-	int i, count = 1;
-
-	print_regulator_header();
-
-	wrefresh(regulator_win);
-
-	return;
-
-	(void)verbose;
-
-	for (i = 0; i < nr_reg; i++) {
-		int col = 0;
-
-		if ((i + 2) > (maxy-2))
-			break;
-
-		if (reg_info[i].num_users > 0)
-			wattron(regulator_win, WA_BOLD);
-		else
-			wattroff(regulator_win, WA_BOLD);
-
-		print(regulator_win, col, count, "%s",
-			reg_info[i].name);
-		col += 12;
-		print(regulator_win, col, count, "%s",
-			reg_info[i].status);
-		col += 12;
-		print(regulator_win, col, count, "%s",
-			reg_info[i].state);
-		col += 12;
-		print(regulator_win, col, count, "%s",
-			reg_info[i].type);
-		col += 12;
-		print(regulator_win, col, count, "%d",
-			reg_info[i].num_users);
-		col += 12;
-		print(regulator_win, col, count, "%d",
-			reg_info[i].microvolts);
-		col += 12;
-		print(regulator_win, col, count, "%d",
-			reg_info[i].min_microvolts);
-		col += 12;
-		print(regulator_win, col, count, "%d",
-			reg_info[i].max_microvolts);
-
-		count++;
-	}
-	wrefresh(regulator_win);
-}
-#endif
-
 void print_sensor_header(void)
 {
+	WINDOW *sensor_win = windata[SENSOR].win;
+
 	werase(sensor_win);
 	wattron(sensor_win, A_BOLD);
 	print(sensor_win, 0, 0, "Name");
@@ -289,14 +230,14 @@
 
 int display_refresh_pad(int win)
 {
-	return prefresh(clock_pad, windata[win].scrolling,
+	return prefresh(windata[win].pad, windata[win].scrolling,
 			0, 2, 0, maxy - 2, maxx);
 }
 
-static int inline display_clock_un_select(int win, int line,
+static int inline display_un_select(int win, int line,
 					  bool highlight, bool bold)
 {
-	if (mvwchgat(clock_pad, line, 0, -1,
+	if (mvwchgat(windata[win].pad, line, 0, -1,
 		     highlight ? WA_STANDOUT :
 		     bold ? WA_BOLD: WA_NORMAL, 0, NULL) < 0)
 		return -1;
@@ -306,12 +247,12 @@
 
 int display_select(int win, int line)
 {
-	return display_clock_un_select(win, line, true, false);
+	return display_un_select(win, line, true, false);
 }
 
 int display_unselect(int win, int line, bool bold)
 {
-	return display_clock_un_select(win, line, false, bold);
+	return display_un_select(win, line, false, bold);
 }
 
 void *display_get_row_data(int win)
@@ -337,11 +278,11 @@
 	return 0;
 }
 
-int display_reset_cursor(win)
+int display_reset_cursor(int win)
 {
 	windata[win].nrdata = 0;
-	werase(clock_pad);
-	return wmove(clock_pad, 0, 0);
+	werase(windata[win].pad);
+	return wmove(windata[win].pad, 0, 0);
 }
 
 int display_print_line(int win, int line, char *str, int bold, void *data)
@@ -358,12 +299,12 @@
 		return -1;
 
 	if (attr)
-		wattron(clock_pad, attr);
+		wattron(windata[win].pad, attr);
 
-	wprintw(clock_pad, "%s\n", str);
+	wprintw(windata[win].pad, "%s\n", str);
 
 	if (attr)
-		wattroff(clock_pad, attr);
+		wattroff(windata[win].pad, attr);
 
 	return 0;
 }