[PATCH] xfce-mixer-applet: disable volume button when no device/track
Mark Pustjens
pustjens at dds.nl
Mon Aug 9 14:15:51 CEST 2010
Hi list,
When the mixer applet is not configured with any device or mixer track,
the volume button is still usable. For example, scrolling still works and
gives the impression the volume does change, while it does not.
The attached patch fixes this behaviour. When no device or track is
available the volume button shows the muted icon.
Please let me know what you think.
Greetings/Groetjes
Mark Pustjens
--
diff --git a/panel-plugin/xfce-mixer-plugin.c b/panel-plugin/xfce-mixer-plugin.c
index af26ba2..ffb9f57 100644
--- a/panel-plugin/xfce-mixer-plugin.c
+++ b/panel-plugin/xfce-mixer-plugin.c
@@ -660,6 +660,8 @@ xfce_mixer_plugin_set_track (XfceMixerPlugin *mixer_plugin,
mixer_plugin->track = track;
+ xfce_volume_button_set_has_track (mixer_plugin->button, track != NULL);
+
/* Replace the track label */
g_free (mixer_plugin->track_label);
mixer_plugin->track_label = NULL;
diff --git a/panel-plugin/xfce-volume-button.c b/panel-plugin/xfce-volume-button.c
index 67dc781..fae6436 100644
--- a/panel-plugin/xfce-volume-button.c
+++ b/panel-plugin/xfce-volume-button.c
@@ -103,6 +103,9 @@ struct _XfceVolumeButton
{
GtkButton __parent__;
+ /* If the button controls a track */
+ gboolean *has_track;
+
/* Image widget for the volume icon */
GtkWidget *image;
@@ -197,6 +200,9 @@ xfce_volume_button_class_init (XfceVolumeButtonClass *klass)
static void
xfce_volume_button_init (XfceVolumeButton *button)
{
+ /* Initially we assume the button has no associated mixer track */
+ button->has_track = FALSE;
+
/* By default we expect the button not to be muted */
button->is_muted = FALSE;
@@ -336,6 +342,10 @@ xfce_volume_button_button_pressed (GtkWidget *widget,
/* Check if the middle mouse button was pressed */
if (event->button == 2)
{
+ /* If we do not have a track, we dont need to do anything here */
+ if (!button->has_track)
+ return TRUE;
+
/* Determine the new mute state by negating the current state */
mute = !button->is_muted;
@@ -366,6 +376,10 @@ xfce_volume_button_scrolled (GtkWidget *widget,
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
g_return_val_if_fail (IS_XFCE_VOLUME_BUTTON (button), FALSE);
+ /* If we do not have a track, we dont need to do anything here either */
+ if (!button->has_track)
+ return TRUE;
+
/* Get current adjustment value and the step increment size */
g_object_get (G_OBJECT (button->adjustment), "value", &value, "step-increment", &step_increment, NULL);
@@ -414,9 +428,10 @@ xfce_volume_button_update (XfceVolumeButton *button)
/* Determine the difference between upper and lower bound (= volume range) */
range = (upper - lower) / (G_N_ELEMENTS (icons) - 2);
- if (G_UNLIKELY (button->is_muted))
+ if (G_UNLIKELY (button->is_muted || !button->has_track))
{
- /* By definition, use the first icon if the button is muted */
+ /* By definition, use the first icon if the button is muted or
+ * has no associated mixer track */
pixbuf = button->pixbufs[0];
}
else
@@ -475,6 +490,22 @@ xfce_volume_button_set_volume (XfceVolumeButton *button,
}
+
+void
+xfce_volume_button_set_has_track (XfceVolumeButton *button,
+ gboolean has_track)
+{
+ g_return_if_fail (IS_XFCE_VOLUME_BUTTON (button));
+
+ /* Change has_track value */
+ button->has_track = has_track;
+
+ /* Update the state of the button */
+ xfce_volume_button_update (button);
+}
+
+
+
void
xfce_volume_button_set_icon_size (XfceVolumeButton *button,
gint size)
diff --git a/panel-plugin/xfce-volume-button.h b/panel-plugin/xfce-volume-button.h
index acdefa3..3340e82 100644
--- a/panel-plugin/xfce-volume-button.h
+++ b/panel-plugin/xfce-volume-button.h
@@ -41,6 +41,8 @@ GtkWidget *xfce_volume_button_new (void);
void xfce_volume_button_set_muted (XfceVolumeButton *button,
gboolean muted);
+void xfce_volume_button_set_has_track (XfceVolumeButton *button,
+ gboolean has_track);
void xfce_volume_button_set_volume (XfceVolumeButton *button,
gdouble volume);
void xfce_volume_button_update (XfceVolumeButton *button);
-------------- next part --------------
diff --git a/panel-plugin/xfce-mixer-plugin.c b/panel-plugin/xfce-mixer-plugin.c
index af26ba2..ffb9f57 100644
--- a/panel-plugin/xfce-mixer-plugin.c
+++ b/panel-plugin/xfce-mixer-plugin.c
@@ -660,6 +660,8 @@ xfce_mixer_plugin_set_track (XfceMixerPlugin *mixer_plugin,
mixer_plugin->track = track;
+ xfce_volume_button_set_has_track (mixer_plugin->button, track != NULL);
+
/* Replace the track label */
g_free (mixer_plugin->track_label);
mixer_plugin->track_label = NULL;
diff --git a/panel-plugin/xfce-volume-button.c b/panel-plugin/xfce-volume-button.c
index 67dc781..fae6436 100644
--- a/panel-plugin/xfce-volume-button.c
+++ b/panel-plugin/xfce-volume-button.c
@@ -103,6 +103,9 @@ struct _XfceVolumeButton
{
GtkButton __parent__;
+ /* If the button controls a track */
+ gboolean *has_track;
+
/* Image widget for the volume icon */
GtkWidget *image;
@@ -197,6 +200,9 @@ xfce_volume_button_class_init (XfceVolumeButtonClass *klass)
static void
xfce_volume_button_init (XfceVolumeButton *button)
{
+ /* Initially we assume the button has no associated mixer track */
+ button->has_track = FALSE;
+
/* By default we expect the button not to be muted */
button->is_muted = FALSE;
@@ -336,6 +342,10 @@ xfce_volume_button_button_pressed (GtkWidget *widget,
/* Check if the middle mouse button was pressed */
if (event->button == 2)
{
+ /* If we do not have a track, we dont need to do anything here */
+ if (!button->has_track)
+ return TRUE;
+
/* Determine the new mute state by negating the current state */
mute = !button->is_muted;
@@ -366,6 +376,10 @@ xfce_volume_button_scrolled (GtkWidget *widget,
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
g_return_val_if_fail (IS_XFCE_VOLUME_BUTTON (button), FALSE);
+ /* If we do not have a track, we dont need to do anything here either */
+ if (!button->has_track)
+ return TRUE;
+
/* Get current adjustment value and the step increment size */
g_object_get (G_OBJECT (button->adjustment), "value", &value, "step-increment", &step_increment, NULL);
@@ -414,9 +428,10 @@ xfce_volume_button_update (XfceVolumeButton *button)
/* Determine the difference between upper and lower bound (= volume range) */
range = (upper - lower) / (G_N_ELEMENTS (icons) - 2);
- if (G_UNLIKELY (button->is_muted))
+ if (G_UNLIKELY (button->is_muted || !button->has_track))
{
- /* By definition, use the first icon if the button is muted */
+ /* By definition, use the first icon if the button is muted or
+ * has no associated mixer track */
pixbuf = button->pixbufs[0];
}
else
@@ -475,6 +490,22 @@ xfce_volume_button_set_volume (XfceVolumeButton *button,
}
+
+void
+xfce_volume_button_set_has_track (XfceVolumeButton *button,
+ gboolean has_track)
+{
+ g_return_if_fail (IS_XFCE_VOLUME_BUTTON (button));
+
+ /* Change has_track value */
+ button->has_track = has_track;
+
+ /* Update the state of the button */
+ xfce_volume_button_update (button);
+}
+
+
+
void
xfce_volume_button_set_icon_size (XfceVolumeButton *button,
gint size)
diff --git a/panel-plugin/xfce-volume-button.h b/panel-plugin/xfce-volume-button.h
index acdefa3..3340e82 100644
--- a/panel-plugin/xfce-volume-button.h
+++ b/panel-plugin/xfce-volume-button.h
@@ -41,6 +41,8 @@ GtkWidget *xfce_volume_button_new (void);
void xfce_volume_button_set_muted (XfceVolumeButton *button,
gboolean muted);
+void xfce_volume_button_set_has_track (XfceVolumeButton *button,
+ gboolean has_track);
void xfce_volume_button_set_volume (XfceVolumeButton *button,
gdouble volume);
void xfce_volume_button_update (XfceVolumeButton *button);
More information about the Xfce4-dev
mailing list