[gnome-system-monitor: 2/4] Stop background updates if window is not shown (bgo#309839)



commit 73b22d6fb5e23a308fcc4012564bdf4bc5d9120b
Author: Robert Roth <robert roth off gmail com>
Date:   Thu Feb 6 01:47:16 2014 +0200

    Stop background updates if window is not shown (bgo#309839)
    
    If the window is minimized, stop background data collection
    to minimize wakeups. On window restore/focus, start it again.
    https://bugzilla.gnome.org/show_bug.cgi?id=309839

 src/interface.cpp |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/src/interface.cpp b/src/interface.cpp
index f47b030..5551339 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -568,6 +568,42 @@ cb_main_window_delete (GtkWidget *window, GdkEvent *event, gpointer data)
     return TRUE;
 }
 
+static gboolean
+cb_main_window_state_changed (GtkWidget *window, GdkEventWindowState *event, gpointer data)
+{
+    GsmApplication *app = (GsmApplication *) data;
+    gchar * current_page = g_settings_get_string (app->settings, GSM_SETTING_CURRENT_TAB);
+    if (event->new_window_state & GDK_WINDOW_STATE_BELOW ||
+        event->new_window_state & GDK_WINDOW_STATE_ICONIFIED ||
+        event->new_window_state & GDK_WINDOW_STATE_WITHDRAWN)
+    {
+        printf ("Obscured\n");
+        if (strcmp (current_page, "processes") == 0) {
+            proctable_freeze (app);
+        } else if (strcmp (current_page, "resources") == 0) {
+            load_graph_stop (app->cpu_graph);
+            load_graph_stop (app->mem_graph);
+            load_graph_stop (app->net_graph);
+        } else if (strcmp (current_page, "disks") == 0) {
+            disks_freeze (app);
+        }
+    } else  {
+        printf ("Visible\n");
+        if (strcmp (current_page, "processes") == 0) {
+            proctable_update (app);
+            proctable_thaw (app);
+        } else if (strcmp (current_page, "resources") == 0) {
+            load_graph_start (app->cpu_graph);
+            load_graph_start (app->mem_graph);
+            load_graph_start (app->net_graph);
+        } else if (strcmp (current_page, "disks") == 0) {
+            disks_update (app);
+            disks_thaw (app);
+        }
+    }
+    return FALSE;
+}
+
 void
 create_main_window (GsmApplication *app)
 {
@@ -651,6 +687,9 @@ create_main_window (GsmApplication *app)
     g_signal_connect (G_OBJECT (main_window), "delete_event",
                       G_CALLBACK (cb_main_window_delete),
                       app);
+    g_signal_connect (G_OBJECT (main_window), "window-state-event",
+                      G_CALLBACK (cb_main_window_state_changed),
+                      app);
 
     GAction *action;
     action = g_action_map_lookup_action (G_ACTION_MAP (main_window),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]