* src/tuner.c (main, window_is_active_notify):
authorjait <jari.tenhunen@iki.fi>
Wed, 6 Aug 2008 16:13:18 +0000 (16:13 +0000)
committerjait <jari.tenhunen@iki.fi>
Wed, 6 Aug 2008 16:13:18 +0000 (16:13 +0000)
pause pipelines when the application window is inactive,
should reduce energy consumption

git-svn-id: file:///svnroot/tunertool/trunk@13 4bb5ff34-d565-4b58-9699-12000fa1827a

ChangeLog
src/tuner.c

index 5784ae5..57997f9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-08-06  Jari Tenhunen  <jari.tenhunen@iki.fi>
+       * src/tuner.c (main, window_is_active_notify):
+       pause pipelines when the application window is inactive,
+       should reduce energy consumption
+
 2008-08-03  Jari Tenhunen  <jari.tenhunen@iki.fi>
        * src/tuner.c (key_press_event, key_release_event):
        renamed to button_*_event
index 5875b0b..7518356 100644 (file)
@@ -195,6 +195,9 @@ static GtkWidget *currentFrequency;
 static GtkWidget *drawingarea1;
 static GtkWidget *drawingarea2;
 
+static GstElement *bin1 = NULL;
+static GstElement *bin2 = NULL;
+
 static void
 recalculate_scale (double a4)
 {
@@ -454,6 +457,25 @@ button_release_event (GtkWidget * widget, GdkEventButton * event,
   return TRUE;
 }
 
+static gboolean
+window_is_active_notify (GObject * object, GParamSpec * pspec, gpointer user_data)
+{
+  if (gtk_window_is_active (GTK_WINDOW (object))) {
+    if (bin1)
+      gst_element_set_state(bin1, GST_STATE_PLAYING);
+    if (bin2)
+      gst_element_set_state(bin2, GST_STATE_PLAYING);
+  }
+  else {
+    if (bin1)
+      gst_element_set_state(bin1, GST_STATE_PAUSED);
+    if (bin2)
+      gst_element_set_state(bin2, GST_STATE_PAUSED);
+  }
+
+  return FALSE;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -468,7 +490,6 @@ main (int argc, char *argv[])
   osso_context_t *osso_context = NULL;  /* handle to osso */
 #endif
 
-  GstElement *bin1, *bin2;
   GstElement *src1, *pitch, *sink1;
   GstElement *src2, *sink2;
   GstBus *bus;
@@ -540,6 +561,9 @@ main (int argc, char *argv[])
   gtk_container_set_border_width (GTK_CONTAINER (mainBox), 0);
 #endif
 
+  if (GTK_IS_WINDOW (mainWin))
+    g_signal_connect (G_OBJECT (mainWin), "notify::is-active", G_CALLBACK (window_is_active_notify), NULL);
+
   /* Bin for tuner functionality */
   bin1 = gst_pipeline_new ("bin1");