Apply patch from ID 3103192
authorJulien Lavergne <julien.lavergne@gmail.com>
Tue, 21 Dec 2010 21:41:12 +0000 (22:41 +0100)
committerHenry Gebhardt <hsggebhardt@googlemail.com>
Fri, 23 Dec 2011 23:09:27 +0000 (00:09 +0100)
data/Makefile.am
data/images/volume-high.png [new file with mode: 0644]
data/images/volume-low.png [new file with mode: 0644]
data/images/volume-medium.png [new file with mode: 0644]
src/plugins/volumealsa/volumealsa.c

index ef10cc0..a04933a 100644 (file)
@@ -39,7 +39,9 @@ lxpanel_images_DATA = \
        images/gnome-netstatus-txrx.png \
        images/gnome-netstatus-tx.png \
        images/background.png \
-       images/volume.png \
+       images/volume-low.png \
+       images/volume-medium.png \
+       images/volume-high.png \
        images/mute.png \
        images/ns-bothrs.png \
        images/ns-connected.png \
diff --git a/data/images/volume-high.png b/data/images/volume-high.png
new file mode 100644 (file)
index 0000000..9773611
Binary files /dev/null and b/data/images/volume-high.png differ
diff --git a/data/images/volume-low.png b/data/images/volume-low.png
new file mode 100644 (file)
index 0000000..5fce7b0
Binary files /dev/null and b/data/images/volume-low.png differ
diff --git a/data/images/volume-medium.png b/data/images/volume-medium.png
new file mode 100644 (file)
index 0000000..53ca544
Binary files /dev/null and b/data/images/volume-medium.png differ
index f9489e8..5af5d9a 100644 (file)
 #include "plugin.h"
 #include "dbg.h"
 
-#define ICONS_VOLUME PACKAGE_DATA_DIR "/lxpanel/images/volume.png"
-#define ICONS_MUTE PACKAGE_DATA_DIR "/lxpanel/images/mute.png"
+#define ICONS_VOLUME_HIGH   PACKAGE_DATA_DIR "/lxpanel/images/volume-high.png"
+#define ICONS_VOLUME_MEDIUM PACKAGE_DATA_DIR "/lxpanel/images/volume-medium.png"
+#define ICONS_VOLUME_LOW    PACKAGE_DATA_DIR "/lxpanel/images/volume-low.png"
+#define ICONS_MUTE          PACKAGE_DATA_DIR "/lxpanel/images/mute.png"
 
 typedef struct {
 
@@ -228,10 +230,36 @@ static void volumealsa_update_display(VolumeALSAPlugin * vol)
 {
     /* Mute status. */
     gboolean mute = asound_is_muted(vol);
+    int level = asound_get_volume(vol);
     
-    if ( ! panel_image_set_icon_theme(vol->plugin->panel, vol->tray_icon, ((mute) ? "audio-volume-muted" : "audio-volume-high")))
+    /* Change icon according to mute / volume */
+    const char* icon="audio-volume-muted";
+    const char* icon_fallback=ICONS_MUTE;
+    if (mute)
+    {
+         icon="audio-volume-muted";
+         icon_fallback=ICONS_MUTE;
+    }
+    else if (level >= 75)
     {
-         panel_image_set_from_file(vol->plugin->panel, vol->tray_icon, ((mute) ? ICONS_MUTE : ICONS_VOLUME));
+         icon="audio-volume-high";
+         icon_fallback=ICONS_VOLUME_HIGH;
+    }
+    else if (level >= 50)
+    {
+         icon="audio-volume-medium";
+         icon_fallback=ICONS_VOLUME_MEDIUM;
+    }
+    else if (level > 0)
+    {
+         icon="audio-volume-low";
+         icon_fallback=ICONS_VOLUME_LOW;
+    }
+
+    /* Change icon, fallback to default icon if theme doesn't exsit */
+    if ( ! panel_image_set_icon_theme(vol->plugin->panel, vol->tray_icon, icon))
+    {
+         panel_image_set_from_file(vol->plugin->panel, vol->tray_icon, icon_fallback);
     }
 
     g_signal_handler_block(vol->mute_check, vol->mute_check_handler);
@@ -240,7 +268,6 @@ static void volumealsa_update_display(VolumeALSAPlugin * vol)
     g_signal_handler_unblock(vol->mute_check, vol->mute_check_handler);
 
     /* Volume. */
-    int level = asound_get_volume(vol);
     if (vol->volume_scale != NULL)
     {
         g_signal_handler_block(vol->volume_scale, vol->volume_scale_handler);