Blob Blame History Raw
diff -up gnome-applets-2.19.1/mixer/applet.c.wakeups gnome-applets-2.19.1/mixer/applet.c
--- gnome-applets-2.19.1/mixer/applet.c.wakeups	2007-08-12 23:00:22.000000000 -0400
+++ gnome-applets-2.19.1/mixer/applet.c	2007-08-12 23:00:29.000000000 -0400
@@ -80,6 +80,11 @@ static void	gnome_volume_applet_orientat
 
 static void	gnome_volume_applet_refresh	(GnomeVolumeApplet *applet,
 						 gboolean           force_refresh);
+
+#ifdef HAVE_GST_MIXER_NOTIFIES
+static void     cb_notify_message (GstBus *bus, GstMessage *message, gpointer data);
+#endif
+
 static gboolean	cb_check			(gpointer   data);
 
 static void	cb_volume			(GtkAdjustment *adj,
@@ -242,6 +247,14 @@ gnome_volume_applet_init (GnomeVolumeApp
   /* i18n */
   ao = gtk_widget_get_accessible (GTK_WIDGET (applet));
   atk_object_set_name (ao, _("Volume Control"));
+
+  /* Bus for notifications */
+#ifdef HAVE_GST_MIXER_NOTIFIES
+  applet->bus = gst_bus_new ();
+  gst_bus_add_signal_watch (applet->bus);
+  g_signal_connect (G_OBJECT (applet->bus), "message::element", 
+       (GCallback) cb_notify_message, applet);
+#endif
 }
 
 /* Parse the list of tracks that are stored in GConf */
@@ -368,12 +381,37 @@ select_element_and_track (GnomeVolumeApp
     return FALSE;
 
   applet->mixer = g_object_ref (active_element);
+#ifdef HAVE_GST_MIXER_NOTIFIES
+  gst_element_set_bus (GST_ELEMENT (applet->mixer), applet->bus);
+#endif
   applet->tracks = active_tracks;
   g_list_foreach (applet->tracks, (GFunc) g_object_ref, NULL);
 
   return TRUE;
 }
 
+static void
+gnome_volume_applet_setup_timeout (GnomeVolumeApplet *applet)
+{
+  gboolean need_timeout = TRUE;
+#ifdef HAVE_GST_MIXER_NOTIFIES
+  need_timeout = ((gst_mixer_get_mixer_flags (GST_MIXER (applet->mixer)) &
+      GST_MIXER_FLAG_AUTO_NOTIFICATIONS) == 0);
+#endif
+
+  if (need_timeout) {
+    if (applet->timeout == 0) {
+      applet->timeout = g_timeout_add (100, cb_check, applet);
+    }
+  }
+  else {
+    if (applet->timeout != 0) {
+      g_source_remove (applet->timeout);
+      applet->timeout = 0;
+    }
+  }
+}
+
 gboolean
 gnome_volume_applet_setup (GnomeVolumeApplet *applet,
 			   GList *elements)
@@ -436,9 +474,8 @@ gnome_volume_applet_setup (GnomeVolumeAp
   g_signal_connect (component, "ui-event", G_CALLBACK (cb_ui_event), applet);
 
   gnome_volume_applet_refresh (applet, TRUE);
-  if (res) {
-    applet->timeout = g_timeout_add (100, cb_check, applet);
-  }
+  if (res)
+    gnome_volume_applet_setup_timeout (applet);
 
   if (res) {
     /* gconf */
@@ -479,6 +516,13 @@ gnome_volume_applet_dispose (GObject *ob
     g_list_free (applet->elements);
     applet->elements = NULL;
   }
+#ifdef HAVE_GST_MIXER_NOTIFIES
+  gst_bus_remove_signal_watch (applet->bus);
+  if (applet->bus) {
+    gst_object_unref (applet->bus);
+    applet->bus = NULL;
+  }
+#endif
 
   if (applet->tracks) {
     g_list_foreach (applet->tracks, (GFunc) g_object_unref, NULL);
@@ -1152,6 +1196,38 @@ gnome_volume_applet_refresh (GnomeVolume
 				"state", mute ? "1" : "0", NULL);
 }
 
+#ifdef HAVE_GST_MIXER_NOTIFIES
+static void
+cb_notify_message (GstBus *bus, GstMessage *message, gpointer data)
+{
+  GnomeVolumeApplet *applet = GNOME_VOLUME_APPLET (data);
+  GstMixerMessageType type;
+  GstMixerTrack *first_track;
+  GstMixerTrack *track = NULL;
+
+  if (applet->tracks == NULL || 
+      GST_MESSAGE_SRC (message) != GST_OBJECT (applet->mixer)) {
+    /* No tracks, or not from our mixer - can't update anything anyway */
+    return; 
+  }
+
+  first_track = g_list_first (applet->tracks)->data;
+
+  /* This code only calls refresh if the first_track changes, because the
+   * refresh code only retrieves the current value from that track anyway */
+  type = gst_mixer_message_get_type (message);
+  if (type == GST_MIXER_MESSAGE_MUTE_TOGGLED) {
+    gst_mixer_message_parse_mute_toggled (message, &track, NULL);
+  }
+  else { 
+    gst_mixer_message_parse_volume_changed (message, &track, NULL, NULL);
+  }
+
+  if (first_track == track)
+    gnome_volume_applet_refresh (GNOME_VOLUME_APPLET (data), FALSE);
+}
+#endif
+
 static gboolean
 cb_check (gpointer data)
 {
@@ -1214,6 +1290,8 @@ cb_gconf (GConfClient *client,
             /* save */
             gst_object_replace ((GstObject **) &applet->mixer, item->data);
             gst_element_set_state (old_element, GST_STATE_NULL);
+
+            gnome_volume_applet_setup_timeout (applet);
             newdevice = TRUE;
           }
           break;
diff -up gnome-applets-2.19.1/mixer/applet.h.wakeups gnome-applets-2.19.1/mixer/applet.h
--- gnome-applets-2.19.1/mixer/applet.h.wakeups	2007-08-12 23:00:17.000000000 -0400
+++ gnome-applets-2.19.1/mixer/applet.h	2007-08-12 23:00:29.000000000 -0400
@@ -71,6 +71,7 @@ typedef struct _GnomeVolumeApplet {
 
   /* element */
   GstMixer *mixer;
+  GstBus *bus;
   gboolean lock;
   gint state;
   GList *tracks;
diff -up gnome-applets-2.19.1/configure.in.wakeups gnome-applets-2.19.1/configure.in
--- gnome-applets-2.19.1/configure.in.wakeups	2007-08-12 23:03:29.000000000 -0400
+++ gnome-applets-2.19.1/configure.in	2007-08-12 23:03:55.000000000 -0400
@@ -479,11 +479,22 @@ esac
 
 AM_CONDITIONAL(APPLET_MIXER, test "x$HAVE_GST" = "xyes")
 AM_CONDITIONAL(HAVE_GST10, test "x$HAVE_GST_VER" = "x0.10")
+
+HAVE_GST_MIXER_NOTIFIES=no
 if test "x$HAVE_GST_VER" = "x0.10" ; then
 	AC_DEFINE(HAVE_GST10, 1, [Using Gstreamer 0.10])
 	# these don't seem to come from any pkg-config file
 	MIXER_LIBS="$MIXER_LIBS -lgstinterfaces-0.10 -lgstaudio-0.10"
+
+        PKG_CHECK_MODULES(GST_MIXER_NOTIFICATIONS,
+            gstreamer-plugins-base-0.10 >= 0.10.13.1, 
+            HAVE_GST_MIXER_NOTIFIES=yes, HAVE_GST_MIXER_NOTIFIES=no)
+        if test "x$HAVE_GST_MIXER_NOTIFIES" = "xyes"; then
+          AC_DEFINE(HAVE_GST_MIXER_NOTIFIES, 1, 
+              [Have GStreamer mixer notification API])
+        fi
 fi
+AM_CONDITIONAL(HAVE_GST_MIXER_NOTIFIES, test "x$HAVE_GST_MIXER_NOTIFIES" = "xyes")
 
 AC_SUBST(MIXER_CFLAGS)
 AC_SUBST(MIXER_LIBS)
@@ -766,6 +777,7 @@ gnome-applets-$VERSION configure summary
 	 - invest-applet		$BUILD_INVEST_APPLET
 	 - mini-commander		$enable_mini_commander
 	 - mixer			$HAVE_GST
+	        - mixer	notifications	$HAVE_GST_MIXER_NOTIFIES
 	 - modemlights			$BUILD_MODEM_LIGHTS
 	 - multiload			$build_gtop_applets
 	 - stickynotes			$enable_stickynotes