From patchwork Wed Jun 15 13:50:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 1928 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 12EBF24B34 for ; Wed, 15 Jun 2011 13:52:42 +0000 (UTC) Received: from mail-vx0-f180.google.com (mail-vx0-f180.google.com [209.85.220.180]) by fiordland.canonical.com (Postfix) with ESMTP id D59D6A18976 for ; Wed, 15 Jun 2011 13:52:41 +0000 (UTC) Received: by mail-vx0-f180.google.com with SMTP id 12so410110vxk.11 for ; Wed, 15 Jun 2011 06:52:41 -0700 (PDT) Received: by 10.52.95.194 with SMTP id dm2mr535724vdb.47.1308145961492; Wed, 15 Jun 2011 06:52:41 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs126632vdc; Wed, 15 Jun 2011 06:52:41 -0700 (PDT) Received: by 10.14.127.200 with SMTP id d48mr279392eei.158.1308145958450; Wed, 15 Jun 2011 06:52:38 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp05.smtpout.orange.fr [80.12.242.127]) by mx.google.com with ESMTP id b19si1380810wed.118.2011.06.15.06.52.37; Wed, 15 Jun 2011 06:52:38 -0700 (PDT) Received-SPF: neutral (google.com: 80.12.242.127 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=80.12.242.127; Authentication-Results: mx.google.com; spf=neutral (google.com: 80.12.242.127 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: from monster.dhcp.lxc ([92.134.76.78]) by mwinf5d28 with ME id wDsa1g00D1hMfSL03DsdBW; Wed, 15 Jun 2011 15:52:37 +0200 From: Daniel Lezcano To: daniel.lezcano@linaro.org Cc: linaro-dev@lists.linaro.org, patches@linaro.org Subject: [powerdebug 05/22] assign a pad for each window Date: Wed, 15 Jun 2011 15:50:39 +0200 Message-Id: <1308145856-6112-5-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1308145856-6112-1-git-send-email-daniel.lezcano@linaro.org> References: <1308145856-6112-1-git-send-email-daniel.lezcano@linaro.org> 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 --- display.c | 141 ++++++++++++++++++------------------------------------------- 1 files changed, 41 insertions(+), 100 deletions(-) diff --git a/display.c b/display.c index 3795547..b417459 100644 --- a/display.c +++ b/display.c @@ -31,10 +31,6 @@ enum { PT_COLOR_DEFAULT = 1, }; 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 rowdata { }; struct windata { + WINDOW *win; + WINDOW *pad; struct rowdata *rowdata; char *name; int nrdata; @@ -70,6 +68,9 @@ static void display_fini(void) int display_init(void) { + int i; + size_t array_size = sizeof(windata) / sizeof(windata[0]); + if (!initscr()) return -1; @@ -97,21 +98,17 @@ int display_init(void) 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_windows(int selectedwindow) } -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 show_header(int selectedwindow) 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_regulator_header(void) 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 @@ void print_sensor_header(void) 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 @@ static int inline display_clock_un_select(int win, int line, 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 @@ int display_set_row_data(int win, int line, void *data, int attr) 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 @@ int display_print_line(int win, int line, char *str, int bold, void *data) 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; }