Commit 3bbcc529ee7f1d5807f3fe84cfdbdd1599530ad0

Authored by Brian Norris
Committed by Zhang Rui
1 parent 0e7b766dc0

tools/thermal: tmon: fixup tui windowing calculations

The number of rows in the dialog vary according to the number of cooling
devices. However, some of the windowing computations were assuming a
fixed number of rows. This computation is OK when we have between 4 and
9 cooling devices (and they wrap to the next column), but with fewer
devices, we end up printing off the end of the window.

This unifies the row computation into a single function and uses that
throughout the TUI code. This also accounts for increasing the number of
rows when there are more than 9 total cooling devices.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Acked-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>

Showing 1 changed file with 16 additions and 5 deletions Side-by-side Diff

tools/thermal/tmon/tui.c
... ... @@ -110,6 +110,18 @@
110 110 wrefresh(status_bar_window);
111 111 }
112 112  
  113 +/* wrap at 5 */
  114 +#define DIAG_DEV_ROWS 5
  115 +/*
  116 + * list cooling devices + "set temp" entry; wraps after 5 rows, if they fit
  117 + */
  118 +static int diag_dev_rows(void)
  119 +{
  120 + int entries = ptdata.nr_cooling_dev + 1;
  121 + int rows = max(DIAG_DEV_ROWS, (entries + 1) / 2);
  122 + return min(rows, entries);
  123 +}
  124 +
113 125 void setup_windows(void)
114 126 {
115 127 int y_begin = 1;
... ... @@ -134,7 +146,7 @@
134 146 * dialogue window is a pop-up, when needed it lays on top of cdev win
135 147 */
136 148  
137   - dialogue_window = subwin(stdscr, ptdata.nr_cooling_dev+5, maxx-50,
  149 + dialogue_window = subwin(stdscr, diag_dev_rows() + 5, maxx-50,
138 150 DIAG_Y, DIAG_X);
139 151  
140 152 thermal_data_window = subwin(stdscr, ptdata.nr_tz_sensor *
... ... @@ -270,7 +282,6 @@
270 282 }
271 283  
272 284 const char DIAG_TITLE[] = "[ TUNABLES ]";
273   -#define DIAG_DEV_ROWS 5
274 285 void show_dialogue(void)
275 286 {
276 287 int j, x = 0, y = 0;
... ... @@ -287,7 +298,7 @@
287 298 mvwprintw(w, 0, maxx/4, DIAG_TITLE);
288 299 /* list all the available tunables */
289 300 for (j = 0; j <= ptdata.nr_cooling_dev; j++) {
290   - y = j % DIAG_DEV_ROWS;
  301 + y = j % diag_dev_rows();
291 302 if (y == 0 && j != 0)
292 303 x += 20;
293 304 if (j == ptdata.nr_cooling_dev)
... ... @@ -298,7 +309,7 @@
298 309 ptdata.cdi[j].type, ptdata.cdi[j].instance);
299 310 }
300 311 wattron(w, A_BOLD);
301   - mvwprintw(w, DIAG_DEV_ROWS+1, 1, "Enter Choice [A-Z]?");
  312 + mvwprintw(w, diag_dev_rows()+1, 1, "Enter Choice [A-Z]?");
302 313 wattroff(w, A_BOLD);
303 314 /* print legend at the bottom line */
304 315 mvwprintw(w, rows - 2, 1,
... ... @@ -450,7 +461,7 @@
450 461 snprintf(buf, sizeof(buf), "New Value for %.10s-%2d: ",
451 462 ptdata.cdi[cdev_id].type,
452 463 ptdata.cdi[cdev_id].instance);
453   - write_dialogue_win(buf, DIAG_DEV_ROWS+2, 2);
  464 + write_dialogue_win(buf, diag_dev_rows() + 2, 2);
454 465 handle_input_val(cdev_id);
455 466 } else {
456 467 snprintf(buf, sizeof(buf), "Invalid selection %d", ch);