Introduce support for on-demand window refresh (tab).
    Extended tab_window class now defines virtual window_refresh() function,
    which should be implemented in derived classes according to refresh
    logic.
    
    Add support for window refresh to tuninig tab. For example, this
    allows to update list with plugged-in/unplagged USB devices, etc., w/o
    the need of powertop restart.

Signed-off-by: Sergey Senozhatsky <sergey.senozhat...@gmail.com>

---
 display.cpp       |   15 +++++++++++++++
 display.h         |    2 ++
 main.cpp          |    3 ++-
 tuning/tuning.cpp |   28 ++++++++++++++++++++--------
 4 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/display.cpp b/display.cpp
index 150834a..8979c98 100644
--- a/display.cpp
+++ b/display.cpp
@@ -259,6 +259,7 @@ void cursor_up(void)
 
        show_cur_tab();
 }
+
 void cursor_enter(void)
 {
        class tab_window *w;
@@ -272,6 +273,20 @@ void cursor_enter(void)
        show_cur_tab();
 }
 
+void window_refresh()
+{
+       class tab_window *w;
+       
+       w = tab_windows[tab_names[current_tab]];
+
+       if (w) {
+               w->window_refresh();
+               w->repaint();
+       }
+
+       show_cur_tab();
+}
+
 int ncurses_initialized(void)
 {
        if (display)
diff --git a/display.h b/display.h
index c4f946c..78d1735 100644
--- a/display.h
+++ b/display.h
@@ -42,6 +42,7 @@ extern void show_cur_tab(void);
 extern void cursor_up(void);
 extern void cursor_down(void);
 extern void cursor_enter(void);
+extern void window_refresh(void);
 
 #ifndef DISABLE_NCURSES
 class tab_window {
@@ -54,6 +55,7 @@ public:
        virtual void cursor_up(void) { if (cursor_pos > 0) cursor_pos--; 
repaint(); };
 
        virtual void cursor_enter(void) { };
+       virtual void window_refresh() { };
 
        virtual void repaint(void) { };
        virtual void expose(void) { cursor_pos = 0; repaint();};
diff --git a/main.cpp b/main.cpp
index 67db2eb..afc124b 100644
--- a/main.cpp
+++ b/main.cpp
@@ -136,7 +136,8 @@ static void do_sleep(int seconds)
                case 10:
                        cursor_enter();
                        break;
-               case 'i':
+               case 'r':
+                       window_refresh();
                        return;
                case KEY_EXIT:
                case 'q':
diff --git a/tuning/tuning.cpp b/tuning/tuning.cpp
index 8930365..1ca33d7 100644
--- a/tuning/tuning.cpp
+++ b/tuning/tuning.cpp
@@ -50,17 +50,12 @@ public:
        virtual void repaint(void);
        virtual void cursor_enter(void);
        virtual void expose(void);
+       virtual void window_refresh(void);
 };
 #endif // DISABLE_NCURSES
-void initialize_tuning(void)
-{
-#ifndef DISABLE_NCURSES
-       class tuning_window *w;
-
-       w = new tuning_window();
-       create_tab("Tunables", _("Tunables"), w, _(" <ESC> Exit | <Enter> 
Toggle tunable"));
-#endif // DISABLE_NCURSES
 
+static void init_tuning(void)
+{
        add_sysfs_tunable(_("Enable Audio codec power management"), 
"/sys/module/snd_hda_intel/parameters/power_save", "1");
        add_sysfs_tunable(_("Enable SATA link power management for /dev/sda"), 
"/sys/class/scsi_host/host0/link_power_management_policy", "min_power");
        add_sysfs_tunable(_("NMI watchdog should be turned off"), 
"/proc/sys/kernel/nmi_watchdog", "0");
@@ -75,6 +70,18 @@ void initialize_tuning(void)
        add_cpufreq_tunable();
 
        sort_tunables();
+}
+
+void initialize_tuning(void)
+{
+#ifndef DISABLE_NCURSES
+       class tuning_window *w;
+
+       w = new tuning_window();
+       create_tab("Tunables", _("Tunables"), w, _(" <ESC> Exit | <Enter> 
Toggle tunable | <r> Window refresh"));
+#endif // DISABLE_NCURSES
+
+       init_tuning();
 
 #ifndef DISABLE_NCURSES
        w->cursor_max = all_tunables.size() - 1;
@@ -172,6 +179,11 @@ static bool tunables_sort(class tunable * i, class tunable 
* j)
        return false;
 }
 
+void tuning_window::window_refresh()
+{
+       clear_tuning();
+       init_tuning();
+}
 
 static void sort_tunables(void)
 {

_______________________________________________
Power mailing list
Power@bughost.org
https://bughost.org/mailman/listinfo/power

Reply via email to