From c93e07180c85ff75949238d681caf88c09da3e5e Mon Sep 17 00:00:00 2001 From: Amit Arora Date: Thu, 7 Oct 2010 13:51:53 +0530 Subject: Add Tabs for various features --- display.c | 162 ++++++++++++++++++++++---------------------------------------- 1 file changed, 58 insertions(+), 104 deletions(-) (limited to 'display.c') diff --git a/display.c b/display.c index bb5fb69..11bf45e 100644 --- a/display.c +++ b/display.c @@ -23,6 +23,7 @@ static WINDOW *header_win; static WINDOW *regulator_win; static WINDOW *clock_win; static WINDOW *sensor_win; +static WINDOW *selected_win; static WINDOW *footer_win; int maxx, maxy; @@ -33,9 +34,10 @@ void fini_curses(void) { endwin(); } -void killall_windows(void) +/* "all" : Kill header and footer windows too ? */ +void killall_windows(int all) { - if (header_win) { + if (all && header_win) { delwin(header_win); header_win = NULL; } @@ -51,7 +53,7 @@ void killall_windows(void) delwin(sensor_win); sensor_win = NULL; } - if (footer_win) { + if (all && footer_win) { delwin(footer_win); footer_win = NULL; } @@ -70,7 +72,8 @@ void init_curses(void) init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK); init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED); - init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE); + //init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE); + init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_GREEN); init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW); init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN); init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK); @@ -85,7 +88,7 @@ void create_windows(void) { getmaxyx(stdscr, maxy, maxx); - killall_windows(); + killall_windows(1); header_win = subwin(stdscr, 1, maxx, 0, 0); // regulator_win = subwin(stdscr, maxy/2 - 2, maxx, 1, 0); @@ -101,98 +104,59 @@ void create_windows(void) } -/* - * maxrows is the MAXIMUM number of rows we need for this window - * pshare is the minimum number of rows we should have for this (in %age) - * maxrows prevails in case of an argument ! - */ -int create_regulator_win(int row, int maxrows, int *pshare) +void create_selectedwindow(void) { - int numrows; - int idealrows; // Based on pshare provided to us + WINDOW *win; - if (regulator_win) { - delwin(regulator_win); - regulator_win = NULL; - } + killall_windows(0); getmaxyx(stdscr, maxy, maxx); - idealrows = ((maxy - 2) * (*pshare)) / 100; - if (maxrows < idealrows) { - numrows = maxrows; - *pshare = (numrows * 100) / maxy; - } else - numrows = idealrows; - regulator_win = subwin(stdscr, numrows, maxx, row, 0); - - refresh(); - - return numrows + row; -} - -int create_clock_win(int row, int maxrows, int *pshare) -{ - int numrows; - int idealrows; - - if (clock_win) { - delwin(clock_win); - clock_win = NULL; - } - - getmaxyx(stdscr, maxy, maxx); - idealrows = ((maxy - 2) * (*pshare)) / 100; - - if (maxrows < idealrows) - numrows = maxrows; - else - numrows = idealrows; - clock_win = subwin(stdscr, numrows, maxx, row, 0); - - refresh(); + win = subwin(stdscr, maxy - 2, maxx, 1, 0); - return numrows + row; -} + switch (selectedwindow) { + case REGULATOR: regulator_win = win; + break; -int create_sensor_win(int row, int maxrows, int *pshare) -{ - int numrows; - int idealrows; + case CLOCK: clock_win = win; + break; - if (sensor_win) { - delwin(sensor_win); - sensor_win = NULL; + case SENSOR: sensor_win = win; + break; } - getmaxyx(stdscr, maxy, maxx); - idealrows = ((maxy - 2) * (*pshare)) / 100; - - if (maxrows < idealrows) - numrows = maxrows; - else - numrows = idealrows; - sensor_win = subwin(stdscr, numrows, maxx, row, 0); - + selected_win = win; + refresh(); - - return numrows + row; } void show_header(void) { int i, j = 0; + //char format[64]; wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); werase(header_win); - print(header_win, 0, 0, "PowerDebug version %s (C) Linaro", + print(header_win, 0, 0, "PowerDebug %s", VERSION); - print(header_win, 50, 0, "Refresh Rate %4.2f Secs", - ticktime); + //print(header_win, 50, 0, "Refresh Rate %4.2f Secs", ticktime); + + for (i = 0; i < TOTAL_FEATURE_WINS; i++) { + if (selectedwindow == i) + wattron(header_win, A_REVERSE); + else + wattroff(header_win, A_REVERSE); + + //sprintf(format, " %%-%ds ", sizeof(win_names[i]) + 2); + //sprintf(format, " %%s "); + + print(header_win, i*(maxx / TOTAL_FEATURE_WINS) + 20, 0, + " %s ", win_names[i]); + } + wrefresh(header_win); - wrefresh(header_win); werase(footer_win); @@ -210,21 +174,18 @@ void show_header(void) void show_regulator_info(int verbose) { - int i, count = 2; + int i, count = 1; werase(regulator_win); wattron(regulator_win, A_BOLD); - wattron(regulator_win, A_STANDOUT); - print(regulator_win, 0, 0, "Regulator Information"); - wattroff(regulator_win, A_STANDOUT); - print(regulator_win, 0, 1, "Name"); - print(regulator_win, 12, 1, "Status"); - print(regulator_win, 24, 1, "State"); - print(regulator_win, 36, 1, "Type"); - print(regulator_win, 48, 1, "Users"); - print(regulator_win, 60, 1, "Microvolts"); - print(regulator_win, 72, 1, "Min u-volts"); - print(regulator_win, 84, 1, "Max u-volts"); + print(regulator_win, 0, 0, "Name"); + print(regulator_win, 12, 0, "Status"); + print(regulator_win, 24, 0, "State"); + print(regulator_win, 36, 0, "Type"); + print(regulator_win, 48, 0, "Users"); + print(regulator_win, 60, 0, "Microvolts"); + print(regulator_win, 72, 0, "Min u-volts"); + print(regulator_win, 84, 0, "Max u-volts"); wattroff(regulator_win, A_BOLD); for (i=0; i