diff src/aosd/aosd_trigger.c @ 637:a1687bd302ce trunk

[svn] - aosd: completed volume change trigger, works now
author giacomo
date Mon, 12 Feb 2007 07:20:56 -0800
parents 443de962d0a0
children 40fb4189fa88
line wrap: on
line diff
--- a/src/aosd/aosd_trigger.c	Mon Feb 12 01:39:53 2007 -0800
+++ b/src/aosd/aosd_trigger.c	Mon Feb 12 07:20:56 2007 -0800
@@ -67,14 +67,14 @@
                               aosd_trigger_func_pb_start_cb },
 
   [AOSD_TRIGGER_PB_TITLECHANGE] = { N_("Title Change") ,
-                                    N_("Trigger OSD when, during playback, the song title changes "
+                                    N_("Triggers OSD when, during playback, the song title changes "
                                        "but the filename is the same. This is mostly useful to display "
                                        "title changes in internet streams.") ,
                                     aosd_trigger_func_pb_titlechange_onoff ,
                                     aosd_trigger_func_pb_titlechange_cb },
 
   [AOSD_TRIGGER_VOL_CHANGE] = { N_("Volume Change") ,
-                                N_("Volume blah blah.") ,
+                                N_("Triggers OSD when volume is changed.") ,
                                 aosd_trigger_func_vol_change_onoff ,
                                 aosd_trigger_func_vol_change_cb }
 };
@@ -263,11 +263,55 @@
 static void
 aosd_trigger_func_vol_change_onoff ( gboolean turn_on )
 {
+  if ( turn_on == TRUE )
+    hook_associate( "volume set" , aosd_trigger_func_vol_change_cb , NULL );
+  else
+    hook_dissociate( "volume set" , aosd_trigger_func_vol_change_cb );
   return;
 }
 
+typedef struct
+{
+  gint h_vol[2];
+  gint sid;
+}
+aosd_vol_change_bucket_t;
+
+static gboolean
+aosd_trigger_func_vol_change_timeout ( gpointer bucket_gp )
+{
+  aosd_vol_change_bucket_t *bucket = bucket_gp;
+  gchar *utf8_title_markup = g_markup_printf_escaped(
+    "<span font_desc='%s'>Volume Change - L: %i , R: %i</span>" ,
+    global_config->osd->text.fonts_name[0] , bucket->h_vol[0] , bucket->h_vol[1] );
+  aosd_display( utf8_title_markup , global_config->osd , FALSE );
+  g_free( utf8_title_markup );
+  bucket->sid = 0; /* reset source id value */
+  return FALSE;
+}
+
 static void
-aosd_trigger_func_vol_change_cb ( gpointer plentry_gp , gpointer prevs_gp )
+aosd_trigger_func_vol_change_cb ( gpointer h_vol_gp , gpointer unused )
 {
+  gint *h_vol = h_vol_gp;
+  static aosd_vol_change_bucket_t bucket = { { 0 , 0 } , 0 };
+  
+  bucket.h_vol[0] = h_vol[0];
+  bucket.h_vol[1] = h_vol[1];
+  
+  /* in order to avoid repeated display of osd for each volume variation, use a
+     timer to prevent it from appearing more than once when multiple volume
+     changes are performed in a short time interval (500 msec) */
+  if ( bucket.sid == 0 )
+  {
+    /* first call in the time interval */
+    bucket.sid = g_timeout_add( 500 , aosd_trigger_func_vol_change_timeout , &bucket );
+  }
+  else
+  {
+    /* another call in the same interval, reset the interval */
+    g_source_remove( bucket.sid );
+    bucket.sid = g_timeout_add( 500 , aosd_trigger_func_vol_change_timeout , &bucket );
+  }
   return;
 }