188765
From f10ab9b513241a08af69f50f985b972715e27f07 Mon Sep 17 00:00:00 2001
188765
From: Hans de Goede <hdegoede@redhat.com>
188765
Date: Thu, 4 Jul 2019 11:45:09 +0200
188765
Subject: [PATCH] clients/lcdproc: MemTop: be smarter about how much processes
188765
 to show
188765
188765
Instead of hardcoding the number of processes to 5, which only works
188765
well for LCDs with 4 lines or less, do the following:
188765
188765
On LCDs with 4 lines or less show 5 processes (no change)
188765
188765
On LCDs with 5 lines we have 4 free lines, showing 5 processes with
188765
scrolling here makes things look like we scroll 1 line down and then 1
188765
line back up again, which looks wrong (*). So show 4 processes here.
188765
188765
On LCDs with 6 lines or more, show as many processes as will fit so that
188765
we use the entire screen.
188765
188765
Note that the last 2 cases both come down to showing as many lines as
188765
will fit.
188765
188765
*) This happens e.g. on the LCD panel in various Logitech keyboards, which
188765
fits 5 lines.
188765
188765
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
188765
---
188765
 clients/lcdproc/mem.c | 27 ++++++++++++++++++++++-----
188765
 1 file changed, 22 insertions(+), 5 deletions(-)
188765
188765
diff --git a/clients/lcdproc/mem.c b/clients/lcdproc/mem.c
188765
index 187d421..ddec98c 100644
188765
--- a/clients/lcdproc/mem.c
188765
+++ b/clients/lcdproc/mem.c
188765
@@ -224,7 +224,7 @@ sort_procs(void *a, void *b)
188765
 
188765
 
188765
 /**
188765
- * Mem Top Screen displays info about top 5 memory hogs...
188765
+ * Mem Top Screen displays info about top memory hogs...
188765
  *
188765
  *\verbatim
188765
  *
188765
@@ -246,8 +246,25 @@ int
188765
 mem_top_screen(int rep, int display, int *flags_ptr)
188765
 {
188765
 	LinkedList *procs;
188765
+	int lines;
188765
 	int i;
188765
 
188765
+	/* On screen <= 4 lines show info for 5 processes and use scrolling */
188765
+	if (lcd_hgt <= 4)
188765
+		lines = 5;
188765
+	/*
188765
+	 * On 5 lines displays we have 4 free lines, using 5 lines with
188765
+	 * scrolling here makes things look like we scroll 1 line down and
188765
+	 * then 1 line back up again, which looks wrong. So we use as many
188765
+	 * lines as fit (4) instead of 5 on a 5 lines display, so that we do
188765
+	 * not get the weird scrolling.
188765
+	 *
188765
+	 * Likewise for > 5 lines we also want to show as many lines as fit
188765
+	 * so that we use the entire screen.
188765
+	 */
188765
+	else
188765
+		lines = lcd_hgt - 1;
188765
+
188765
 	if ((*flags_ptr & INITIALIZED) == 0) {
188765
 		*flags_ptr |= INITIALIZED;
188765
 
188765
@@ -260,12 +277,12 @@ mem_top_screen(int rep, int display, int *flags_ptr)
188765
 		sock_send_string(sock, "widget_add S f frame\n");
188765
 
188765
 		/* scroll rate: 1 line every X ticks (= 1/8 sec) */
188765
-		sock_printf(sock, "widget_set S f 1 2 %i %i %i 5 v %i\n",
188765
-			    lcd_wid, lcd_hgt, lcd_wid,
188765
+		sock_printf(sock, "widget_set S f 1 2 %i %i %i %i v %i\n",
188765
+			    lcd_wid, lcd_hgt, lcd_wid, lines,
188765
 			    ((lcd_hgt >= 4) ? 8 : 12));
188765
 
188765
 		/* frame contents */
188765
-		for (i = 1; i <= 5; i++) {
188765
+		for (i = 1; i <= lines; i++) {
188765
 			sock_printf(sock, "widget_add S %i string -in f\n", i);
188765
 		}
188765
 		sock_send_string(sock, "widget_set S 1 1 1 Checking...\n");
188765
@@ -291,7 +308,7 @@ mem_top_screen(int rep, int display, int *flags_ptr)
188765
 	LL_Rewind(procs);
188765
 	LL_Sort(procs, sort_procs);
188765
 	LL_Rewind(procs);
188765
-	for (i = 1; i <= 5; i++) {
188765
+	for (i = 1; i <= lines; i++) {
188765
 		procinfo_type *p = LL_Get(procs);
188765
 
188765
 		if (p != NULL) {
188765
-- 
188765
2.21.0
188765