diff mbox

[05/28] compute next and previous window with modulo arithmetic

Message ID 1308256197-29155-5-git-send-email-daniel.lezcano@linaro.org
State Accepted
Headers show

Commit Message

Daniel Lezcano June 16, 2011, 8:29 p.m. UTC
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 powerdebug.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
diff mbox

Patch

diff --git a/powerdebug.c b/powerdebug.c
index dd4fe91..5fe07de 100644
--- a/powerdebug.c
+++ b/powerdebug.c
@@ -15,6 +15,7 @@ 
 
 #include <getopt.h>
 #include <stdbool.h>
+#include <math.h>
 #include "regulator.h"
 #include "display.h"
 #include "clocks.h"
@@ -164,17 +165,16 @@  int keystroke_callback(bool *enter_hit, bool *findparent_ncurses,
 	if (keystroke == EOF)
 		exit(0);
 
-	if (keystroke == KEY_RIGHT || keystroke == '\t')
+	if (keystroke == KEY_RIGHT || keystroke == '\t') {
 		options->selectedwindow++;
+		options->selectedwindow %= TOTAL_FEATURE_WINS;
+	}
 
-	if (keystroke == KEY_LEFT || keystroke == KEY_BTAB)
+	if (keystroke == KEY_LEFT || keystroke == KEY_BTAB) {
 		options->selectedwindow--;
-
-	if (options->selectedwindow >= TOTAL_FEATURE_WINS)
-		options->selectedwindow = 0;
-
-	if (options->selectedwindow < 0)
-		options->selectedwindow = TOTAL_FEATURE_WINS - 1;
+		if (options->selectedwindow < 0)
+			options->selectedwindow = TOTAL_FEATURE_WINS - 1;
+	}
 
 	if (options->selectedwindow == CLOCK) {
 		if (keystroke == KEY_DOWN)