Author: jannis
Date: 2008-06-22 14:14:39 +0000 (Sun, 22 Jun 2008)
New Revision: 27135

Modified:
   xfce4-mixer/trunk/panel-plugin/xfce-mixer-plugin.c
   xfce4-mixer/trunk/panel-plugin/xfce-volume-button.c
Log:
Add some debug messages for Jens.


Modified: xfce4-mixer/trunk/panel-plugin/xfce-mixer-plugin.c
===================================================================
--- xfce4-mixer/trunk/panel-plugin/xfce-mixer-plugin.c  2008-06-22 13:35:51 UTC 
(rev 27134)
+++ xfce4-mixer/trunk/panel-plugin/xfce-mixer-plugin.c  2008-06-22 14:14:39 UTC 
(rev 27135)
@@ -48,17 +48,26 @@
 {
   XfcePanelPlugin *plugin;
 
+  /* Currently used sound card name */
   gchar           *card_name;
+
+  /* Currently used mixer track name */
   gchar           *track_name;
 
+  /* Tooltips structure */
   GtkTooltips     *tooltips;
 
+  /* Sound card being used */
   XfceMixerCard   *card;
+
+  /* Mixer track being used */
   GstMixerTrack   *track;
 
+  /* Widgets */
   GtkWidget       *hvbox;
   GtkWidget       *button;
 
+  /* Flag for ignoring messages from the GstBus */
   gboolean         ignore_bus_messages;
 };
 
@@ -108,26 +117,32 @@
   /* Store pointer to the panel plugin */
   mixer_plugin->plugin = plugin;
 
+  /* Initialize some of the plugin variables */
   mixer_plugin->card = NULL;
   mixer_plugin->track = NULL;
   mixer_plugin->ignore_bus_messages = FALSE;
 
+  /* Allocate a tooltips structure */
   mixer_plugin->tooltips = gtk_tooltips_new ();
   gtk_tooltips_set_delay (mixer_plugin->tooltips, 10);
 
+  /* Create container for the plugin */
   mixer_plugin->hvbox = GTK_WIDGET (xfce_hvbox_new 
(GTK_ORIENTATION_HORIZONTAL, FALSE, 0));
   xfce_panel_plugin_add_action_widget (plugin, mixer_plugin->hvbox);
   gtk_container_add (GTK_CONTAINER (plugin), mixer_plugin->hvbox);
   gtk_widget_show (mixer_plugin->hvbox);
 
+  /* Create volume button for the plugin */
   mixer_plugin->button = xfce_volume_button_new ();
-  xfce_panel_plugin_add_action_widget (plugin, mixer_plugin->button);
   g_signal_connect_swapped (G_OBJECT (mixer_plugin->button), "volume-changed", 
G_CALLBACK (xfce_mixer_plugin_volume_changed), mixer_plugin);
   g_signal_connect_swapped (G_OBJECT (mixer_plugin->button), "mute-toggled", 
G_CALLBACK (xfce_mixer_plugin_mute_toggled), mixer_plugin);
   g_signal_connect_swapped (G_OBJECT (mixer_plugin->button), "clicked", 
G_CALLBACK (xfce_mixer_plugin_clicked), mixer_plugin);
   gtk_container_add (GTK_CONTAINER (mixer_plugin->hvbox), 
mixer_plugin->button);
   gtk_widget_show (mixer_plugin->button);
 
+  /* Let the volume button receive mouse events */
+  xfce_panel_plugin_add_action_widget (plugin, mixer_plugin->button);
+
   return mixer_plugin;
 }
 
@@ -137,9 +152,11 @@
 xfce_mixer_plugin_free (XfcePanelPlugin *plugin,
                         XfceMixerPlugin *mixer_plugin)
 {
+  /* Free card and track names */
   g_free (mixer_plugin->card_name);
   g_free (mixer_plugin->track_name);
 
+  /* Free memory of the mixer plugin */
   panel_slice_free (XfceMixerPlugin, mixer_plugin);
 }
 
@@ -153,6 +170,7 @@
   /* Set up translation domain */
   xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
 
+  /* Initialize the thread system */
   if (!g_thread_supported ())
     g_thread_init (NULL);
 
@@ -232,6 +250,10 @@
   volume_range = mixer_plugin->track->max_volume - 
mixer_plugin->track->min_volume;
   new_volume = mixer_plugin->track->min_volume + (volume * volume_range);
 
+  g_message ("Volume changed for %s (%s):", xfce_mixer_card_get_display_name 
(mixer_plugin->card), GST_MIXER_TRACK (mixer_plugin->track)->label);
+  g_message ("  min_volume = %i, max_volume = %i, volume_range = %i, 
new_volume = %i", 
+             mixer_plugin->track->min_volume, mixer_plugin->track->max_volume, 
volume_range, new_volume);
+
   for (i = 0; i < mixer_plugin->track->num_channels; ++i)
     volumes[i] = new_volume;
 
@@ -459,13 +481,15 @@
   if (G_UNLIKELY (!xfce_mixer_card_get_message_owner (mixer_plugin->card, 
message)))
     return TRUE;
 
-  g_debug ("Message from card received: %s", GST_MESSAGE_TYPE_NAME (message));
+  g_message ("Message from card received: %s", GST_MESSAGE_TYPE_NAME 
(message));
 
   switch (gst_mixer_message_get_type (message))
     {
       case GST_MIXER_MESSAGE_VOLUME_CHANGED:
         gst_mixer_message_parse_volume_changed (message, &track, &volumes, 
&num_channels);
 
+        g_message ("  volume of %s changed to: %i", track->label, volumes[0]);
+
         if (G_UNLIKELY (g_utf8_collate (track->label, 
mixer_plugin->track->label) == 0))
           {
             volume = ((gdouble) volumes[0]) / mixer_plugin->track->max_volume;

Modified: xfce4-mixer/trunk/panel-plugin/xfce-volume-button.c
===================================================================
--- xfce4-mixer/trunk/panel-plugin/xfce-volume-button.c 2008-06-22 13:35:51 UTC 
(rev 27134)
+++ xfce4-mixer/trunk/panel-plugin/xfce-volume-button.c 2008-06-22 14:14:39 UTC 
(rev 27135)
@@ -29,6 +29,8 @@
 
 #include <libxfcegui4/libxfcegui4.h>
 
+#include "libxfce4mixer/xfce-mixer-stock.h"
+
 #include "xfce-volume-button.h"
 
 
@@ -43,15 +45,19 @@
 
 
 
+/* Signals */
 static guint button_signals[LAST_SIGNAL];
 
+
+
+/* Icons for different volume levels */
 static const char *icons[] = {
-  "audio-volume-00",
-  "audio-volume-01",
-  "audio-volume-02",
-  "audio-volume-03",
-  "audio-volume-04",
-  "audio-volume-05",
+  AUDIO_VOLUME_00,
+  AUDIO_VOLUME_01,
+  AUDIO_VOLUME_02,
+  AUDIO_VOLUME_03,
+  AUDIO_VOLUME_04,
+  AUDIO_VOLUME_05,
   NULL
 };
 
@@ -90,7 +96,6 @@
   /* Signals */
   void (*volume_changed) (XfceVolumeButton *button,
                           gdouble           volume);
-
   void (*mute_toggled)   (XfceVolumeButton *button,
                           gboolean          mute);
 };
@@ -99,14 +104,19 @@
 {
   GtkButton __parent__;
 
+  /* Image widget for the volume icon */
   GtkWidget  *image;
 
+  /* Adjustment for the volume range and current value */
   GtkObject  *adjustment;
 
+  /* Icon size currently used */
   gint        icon_size;
 
+  /* Array of preloaded icons */
   GdkPixbuf **pixbufs;
 
+  /* Mute state of the button */
   gboolean    is_muted;
 };
 
@@ -188,20 +198,26 @@
 static void
 xfce_volume_button_init (XfceVolumeButton *button)
 {
+  /* By default we expect the button not to be muted */
   button->is_muted = FALSE;
 
+  /* Allocate array for preloaded icons */
   button->pixbufs = g_new0 (GdkPixbuf*, G_N_ELEMENTS (icons)-1);
 
+  /* Create adjustment for the button (from 0.0 to 1.0 in 5% steps) */
   button->adjustment = gtk_adjustment_new (0.0, 0.0, 1.0, 0.05, 0.05, 0.2);
+
+  /* Create a new scaled image for the button icon */
   button->image = xfce_scaled_image_new ();
-
   gtk_container_add (GTK_CONTAINER (button), button->image);
   gtk_widget_show (button->image);
 
+  /* Make the button look flat and make it never grab the focus */
   gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
   gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
   GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (button), GTK_CAN_DEFAULT|GTK_CAN_FOCUS);
 
+  /* Connect to button signals */
 #if 0
   /* UNSED FOR NOW DUE TO TOO MUCH PROBLEMS WITH KEYBOARD FOCUS GRABBING */
   g_signal_connect (G_OBJECT (button), "key-press-event", G_CALLBACK 
(xfce_volume_button_key_pressed), button);
@@ -209,6 +225,7 @@
   g_signal_connect (G_OBJECT (button), "button-press-event", G_CALLBACK 
(xfce_volume_button_button_pressed), button);
   g_signal_connect (G_OBJECT (button), "scroll-event", G_CALLBACK 
(xfce_volume_button_scrolled), button);
 
+  /* Update the state of the button */
   xfce_volume_button_update (button);
 }
 
@@ -229,10 +246,10 @@
 
   XfceVolumeButton *button = XFCE_VOLUME_BUTTON (object);
 
+  /* Free pre-allocated icon pixbufs */
   for (i = 0; i < G_N_ELEMENTS (icons)-1; ++i)
     if (GDK_IS_PIXBUF (button->pixbufs[i]))
       g_object_unref (G_OBJECT (button->pixbufs[i]));
-  
   g_free (button->pixbufs);
 
   (*G_OBJECT_CLASS (xfce_volume_button_parent_class)->finalize) (object);
@@ -314,19 +331,26 @@
                                    XfceVolumeButton *button)
 {
   gboolean mute;
+
   g_return_if_fail (IS_XFCE_VOLUME_BUTTON (button));
 
+  /* Check if the middle mouse button was pressed */
   if (event->button == 2)
     {
+      /* Determine the new mute state by negating the current state */
       mute = !button->is_muted;
 
+      /* Toggle the button's mute state */
       xfce_volume_button_set_muted (button, mute);
 
+      /* Notify listeners of the mute change */
       g_signal_emit_by_name (button, "mute-toggled", mute);
 
+      /* Middle mouse button was handled, do not propagate the event any 
further */
       return TRUE;
     }
 
+  /* Left and right mouse buttons are ignored, someone else handle it */
   return FALSE;
 }
 
@@ -343,24 +367,31 @@
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (IS_XFCE_VOLUME_BUTTON (button));
 
+  /* Get current adjustment value and the step increment size */
   g_object_get (G_OBJECT (button->adjustment), "value", &value, 
"step-increment", &step_increment, NULL);
 
+  /* Distinguish between scroll directions */
   switch (event->direction)
     {
       case GDK_SCROLL_UP:
       case GDK_SCROLL_RIGHT:
+        /* Increase one step when scrolling up/right */
         gtk_adjustment_set_value (GTK_ADJUSTMENT (button->adjustment), value + 
step_increment);
         break;
       case GDK_SCROLL_DOWN:
       case GDK_SCROLL_LEFT:
+        /* Decrease one step when scrolling down/left */
         gtk_adjustment_set_value (GTK_ADJUSTMENT (button->adjustment), value - 
step_increment);
         break;
     }
 
+  /* Update the state of the button */
   xfce_volume_button_update (button);
 
+  /* Notify listeners of the new volume */
   g_signal_emit_by_name (button, "volume-changed", gtk_adjustment_get_value 
(GTK_ADJUSTMENT (button->adjustment)));
 
+  /* The scroll event has been handled, stop other handlers from being invoked 
*/
   return TRUE;
 }
 
@@ -378,14 +409,21 @@
 
   g_return_if_fail (IS_XFCE_VOLUME_BUTTON (button));
 
+  /* Get upper, lower bounds and current value of the adjustment */
   g_object_get (G_OBJECT (button->adjustment), "upper", &upper, "lower", 
&lower, "value", &value, NULL);
 
+  /* Determine the difference between upper and lower bound (= volume range) */
   range = (upper - lower) / (G_N_ELEMENTS (icons) - 2);
 
-  if (G_UNLIKELY (value == 0 || button->is_muted))
-    pixbuf = button->pixbufs[0];
+  if (G_UNLIKELY (value == lower || button->is_muted))
+    {
+      /* By definition, use the first icon if the volume is set to the minimum 
value
+       * or if the button is muted */
+      pixbuf = button->pixbufs[0];
+    }
   else
     {
+      /* Find the correct icon for the current volume */
       for (i = 1; i < G_N_ELEMENTS (icons) - 1; ++i)
         if (value <= range * i)
           {
@@ -394,6 +432,7 @@
           }
     }
 
+  /* Update the button icon */
   if (G_LIKELY (pixbuf != NULL))
     xfce_scaled_image_set_from_pixbuf (XFCE_SCALED_IMAGE (button->image), 
pixbuf);
 }
@@ -404,6 +443,7 @@
 xfce_volume_button_volume_changed (XfceVolumeButton *button,
                                    gdouble           volume)
 {
+  /* Do nothing */
 }
 
 
@@ -413,7 +453,11 @@
                               gboolean          muted)
 {
   g_return_if_fail (IS_XFCE_VOLUME_BUTTON (button));
+
+  /* Change mute value */
   button->is_muted = muted;
+
+  /* Update the state of the button */
   xfce_volume_button_update (button);
 }
 
@@ -424,7 +468,11 @@
                                gdouble           volume)
 {
   g_return_if_fail (IS_XFCE_VOLUME_BUTTON (button));
+
+  /* Set the value of the adjustment */
   gtk_adjustment_set_value (GTK_ADJUSTMENT (button->adjustment), volume);
+
+  /* Update the state of the button */
   xfce_volume_button_update (button);
 }
 
@@ -438,8 +486,10 @@
   g_return_if_fail (IS_XFCE_VOLUME_BUTTON (button));
   g_return_if_fail (size >= 0);
 
+  /* Remember the icon size */
   button->icon_size = size;
 
+  /* Pre-load all icons */
   for (i = 0; i < G_N_ELEMENTS (icons)-1; ++i)
     {
       if (GDK_IS_PIXBUF (button->pixbufs[i]))
@@ -455,4 +505,5 @@
 xfce_volume_button_mute_toggled (XfceVolumeButton *button,
                                  gboolean          mute)
 {
+  /* Do nothing */
 }

_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to