summaryrefslogtreecommitdiff
path: root/mate-volume-control/src/gvc-channel-bar.c
diff options
context:
space:
mode:
Diffstat (limited to 'mate-volume-control/src/gvc-channel-bar.c')
-rw-r--r--mate-volume-control/src/gvc-channel-bar.c210
1 files changed, 106 insertions, 104 deletions
diff --git a/mate-volume-control/src/gvc-channel-bar.c b/mate-volume-control/src/gvc-channel-bar.c
index 9a2c765..e431651 100644
--- a/mate-volume-control/src/gvc-channel-bar.c
+++ b/mate-volume-control/src/gvc-channel-bar.c
@@ -36,32 +36,32 @@
struct _GvcChannelBarPrivate
{
- GtkOrientation orientation;
- GtkWidget *scale_box;
- GtkWidget *start_box;
- GtkWidget *end_box;
- GtkWidget *image;
- GtkWidget *label;
- GtkWidget *low_image;
- GtkWidget *scale;
- GtkWidget *high_image;
- GtkWidget *mute_box;
- GtkWidget *mute_button;
- GtkAdjustment *adjustment;
- gboolean show_icons;
- gboolean show_mute;
- gboolean show_marks;
- gboolean extended;
- GtkSizeGroup *size_group;
- gboolean symmetric;
- gboolean click_lock;
- MateMixerStream *stream;
- MateMixerStreamFlags stream_flags;
+ GtkOrientation orientation;
+ GtkWidget *scale_box;
+ GtkWidget *start_box;
+ GtkWidget *end_box;
+ GtkWidget *image;
+ GtkWidget *label;
+ GtkWidget *low_image;
+ GtkWidget *scale;
+ GtkWidget *high_image;
+ GtkWidget *mute_box;
+ GtkWidget *mute_button;
+ GtkAdjustment *adjustment;
+ gboolean show_icons;
+ gboolean show_mute;
+ gboolean show_marks;
+ gboolean extended;
+ GtkSizeGroup *size_group;
+ gboolean symmetric;
+ gboolean click_lock;
+ MateMixerStreamControl *control;
+ MateMixerStreamControlFlags control_flags;
};
enum {
PROP_0,
- PROP_STREAM,
+ PROP_CONTROL,
PROP_ORIENTATION,
PROP_SHOW_ICONS,
PROP_SHOW_MUTE,
@@ -226,17 +226,27 @@ on_adjustment_value_changed (GtkAdjustment *adjustment,
gdouble value;
gdouble lower;
- if (bar->priv->stream == NULL || bar->priv->click_lock == TRUE)
+ if (bar->priv->control == NULL || bar->priv->click_lock == TRUE)
return;
value = gtk_adjustment_get_value (bar->priv->adjustment);
lower = gtk_adjustment_get_lower (bar->priv->adjustment);
- if (bar->priv->stream_flags & MATE_MIXER_STREAM_HAS_MUTE)
- mate_mixer_stream_set_mute (bar->priv->stream, (value <= lower));
+ if (bar->priv->control_flags & MATE_MIXER_STREAM_CONTROL_MUTE_WRITABLE)
+ mate_mixer_stream_control_set_mute (bar->priv->control, (value <= lower));
- if (bar->priv->stream_flags & MATE_MIXER_STREAM_CAN_SET_VOLUME)
- mate_mixer_stream_set_volume (bar->priv->stream, (guint) value);
+ if (bar->priv->control_flags & MATE_MIXER_STREAM_CONTROL_VOLUME_WRITABLE)
+ mate_mixer_stream_control_set_volume (bar->priv->control, (guint) value);
+}
+
+static void
+on_mute_button_toggled (GtkToggleButton *button, GvcChannelBar *bar)
+{
+ gboolean mute;
+
+ mute = gtk_toggle_button_get_active (button);
+
+ mate_mixer_stream_control_set_mute (bar->priv->control, mute);
}
static void
@@ -305,15 +315,13 @@ update_marks (GvcChannelBar *bar)
gtk_scale_clear_marks (GTK_SCALE (bar->priv->scale));
- if (bar->priv->stream == NULL || bar->priv->show_marks == FALSE)
- return;
- if (!(bar->priv->stream_flags & MATE_MIXER_STREAM_HAS_VOLUME))
+ if (bar->priv->control == NULL || bar->priv->show_marks == FALSE)
return;
/* Base volume represents unamplified volume, normal volume is the 100%
* volume, in many cases they are the same as unamplified volume is unknown */
- base = mate_mixer_stream_get_base_volume (bar->priv->stream);
- normal = mate_mixer_stream_get_normal_volume (bar->priv->stream);
+ base = mate_mixer_stream_control_get_base_volume (bar->priv->control);
+ normal = mate_mixer_stream_control_get_normal_volume (bar->priv->control);
if (normal <= gtk_adjustment_get_lower (bar->priv->adjustment))
return;
@@ -363,18 +371,17 @@ update_adjustment_value (GvcChannelBar *bar)
gdouble value;
gboolean set_lower = FALSE;
- /* Move the slider to the minimal value if the stream is muted or
+ /* Move the slider to the minimal value if the stream control is muted or
* volume is unavailable */
- if (!(bar->priv->stream_flags & MATE_MIXER_STREAM_HAS_VOLUME))
+ if (bar->priv->control == NULL)
set_lower = TRUE;
- else if (bar->priv->stream == NULL ||
- bar->priv->stream_flags & MATE_MIXER_STREAM_HAS_MUTE)
- set_lower = mate_mixer_stream_get_mute (bar->priv->stream);
+ else if (bar->priv->control_flags & MATE_MIXER_STREAM_CONTROL_MUTE_READABLE)
+ set_lower = mate_mixer_stream_control_get_mute (bar->priv->control);
- if (set_lower)
+ if (set_lower == TRUE)
value = gtk_adjustment_get_lower (bar->priv->adjustment);
else
- value = mate_mixer_stream_get_volume (bar->priv->stream);
+ value = mate_mixer_stream_control_get_volume (bar->priv->control);
g_signal_handlers_block_by_func (G_OBJECT (bar->priv->adjustment),
on_adjustment_value_changed,
@@ -393,12 +400,12 @@ update_adjustment_limits (GvcChannelBar *bar)
gdouble minimum = 0.0;
gdouble maximum = 0.0;
- if (bar->priv->stream_flags & MATE_MIXER_STREAM_HAS_VOLUME) {
- minimum = mate_mixer_stream_get_min_volume (bar->priv->stream);
+ if (bar->priv->control != NULL) {
+ minimum = mate_mixer_stream_control_get_min_volume (bar->priv->control);
if (bar->priv->extended)
- maximum = mate_mixer_stream_get_max_volume (bar->priv->stream);
+ maximum = mate_mixer_stream_control_get_max_volume (bar->priv->control);
else
- maximum = mate_mixer_stream_get_normal_volume (bar->priv->stream);
+ maximum = mate_mixer_stream_control_get_normal_volume (bar->priv->control);
}
gtk_adjustment_configure (bar->priv->adjustment,
@@ -416,12 +423,12 @@ update_mute_button (GvcChannelBar *bar)
if (bar->priv->show_mute == TRUE) {
gboolean enable = FALSE;
- if (bar->priv->stream != NULL &&
- bar->priv->stream_flags & MATE_MIXER_STREAM_HAS_MUTE)
+ if (bar->priv->control != NULL &&
+ bar->priv->control_flags & MATE_MIXER_STREAM_CONTROL_MUTE_READABLE)
enable = TRUE;
if (enable == TRUE) {
- gboolean mute = mate_mixer_stream_get_mute (bar->priv->stream);
+ gboolean mute = mate_mixer_stream_control_get_mute (bar->priv->control);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bar->priv->mute_button),
mute);
@@ -455,12 +462,12 @@ on_scale_button_press_event (GtkWidget *widget,
/* Muting the stream when volume is non-zero moves the slider to zero,
* but the volume remains the same. In this case delay unmuting and
* changing volume until user releases the mouse button. */
- if (bar->priv->stream_flags & MATE_MIXER_STREAM_HAS_MUTE &&
- bar->priv->stream_flags & MATE_MIXER_STREAM_HAS_VOLUME) {
- if (mate_mixer_stream_get_mute (bar->priv->stream) == TRUE) {
+ if (bar->priv->control_flags & MATE_MIXER_STREAM_CONTROL_MUTE_READABLE &&
+ bar->priv->control_flags & MATE_MIXER_STREAM_CONTROL_VOLUME_READABLE) {
+ if (mate_mixer_stream_control_get_mute (bar->priv->control) == TRUE) {
guint minimum = (guint) gtk_adjustment_get_lower (bar->priv->adjustment);
- if (mate_mixer_stream_get_volume (bar->priv->stream) > minimum)
+ if (mate_mixer_stream_control_get_volume (bar->priv->control) > minimum)
bar->priv->click_lock = TRUE;
}
}
@@ -522,71 +529,79 @@ on_scale_scroll_event (GtkWidget *widget,
}
static void
-on_stream_volume_notify (MateMixerStream *stream,
- GParamSpec *pspec,
- GvcChannelBar *bar)
+on_control_volume_notify (MateMixerStreamControl *control,
+ GParamSpec *pspec,
+ GvcChannelBar *bar)
{
update_adjustment_value (bar);
}
static void
-on_stream_mute_notify (MateMixerStream *stream,
- GParamSpec *pspec,
- GvcChannelBar *bar)
+on_control_mute_notify (MateMixerStreamControl *control,
+ GParamSpec *pspec,
+ GvcChannelBar *bar)
{
if (bar->priv->show_mute == TRUE) {
- gboolean mute = mate_mixer_stream_get_mute (stream);
+ gboolean mute = mate_mixer_stream_control_get_mute (control);
+
+ g_signal_handlers_block_by_func (G_OBJECT (bar->priv->mute_button),
+ on_mute_button_toggled,
+ bar);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bar->priv->mute_button), mute);
+
+ g_signal_handlers_unblock_by_func (G_OBJECT (bar->priv->mute_button),
+ on_mute_button_toggled,
+ bar);
}
update_adjustment_value (bar);
}
-MateMixerStream *
-gvc_channel_bar_get_stream (GvcChannelBar *bar)
+MateMixerStreamControl *
+gvc_channel_bar_get_control (GvcChannelBar *bar)
{
g_return_val_if_fail (GVC_IS_CHANNEL_BAR (bar), NULL);
- return bar->priv->stream;
+ return bar->priv->control;
}
void
-gvc_channel_bar_set_stream (GvcChannelBar *bar, MateMixerStream *stream)
+gvc_channel_bar_set_control (GvcChannelBar *bar, MateMixerStreamControl *control)
{
g_return_if_fail (GVC_IS_CHANNEL_BAR (bar));
- if (bar->priv->stream == stream)
+ if (bar->priv->control == control)
return;
- if (stream != NULL)
- g_object_ref (stream);
+ if (control != NULL)
+ g_object_ref (control);
- if (bar->priv->stream != NULL) {
- g_signal_handlers_disconnect_by_func (G_OBJECT (bar->priv->stream),
- G_CALLBACK (on_stream_volume_notify),
+ if (bar->priv->control != NULL) {
+ g_signal_handlers_disconnect_by_func (G_OBJECT (bar->priv->control),
+ G_CALLBACK (on_control_volume_notify),
bar);
- g_signal_handlers_disconnect_by_func (G_OBJECT (bar->priv->stream),
- G_CALLBACK (on_stream_mute_notify),
+ g_signal_handlers_disconnect_by_func (G_OBJECT (bar->priv->control),
+ G_CALLBACK (on_control_mute_notify),
bar);
- g_object_unref (bar->priv->stream);
+ g_object_unref (bar->priv->control);
}
- bar->priv->stream = stream;
+ bar->priv->control = control;
- if (stream != NULL)
- bar->priv->stream_flags = mate_mixer_stream_get_flags (stream);
+ if (control != NULL)
+ bar->priv->control_flags = mate_mixer_stream_control_get_flags (control);
else
- bar->priv->stream_flags = MATE_MIXER_STREAM_NO_FLAGS;
+ bar->priv->control_flags = MATE_MIXER_STREAM_CONTROL_NO_FLAGS;
- if (bar->priv->stream_flags & MATE_MIXER_STREAM_HAS_VOLUME)
- g_signal_connect (G_OBJECT (stream),
+ if (bar->priv->control_flags & MATE_MIXER_STREAM_CONTROL_VOLUME_READABLE)
+ g_signal_connect (G_OBJECT (control),
"notify::volume",
- G_CALLBACK (on_stream_volume_notify),
+ G_CALLBACK (on_control_volume_notify),
bar);
- if (bar->priv->stream_flags & MATE_MIXER_STREAM_HAS_MUTE)
- g_signal_connect (G_OBJECT (stream),
+ if (bar->priv->control_flags & MATE_MIXER_STREAM_CONTROL_MUTE_READABLE)
+ g_signal_connect (G_OBJECT (control),
"notify::mute",
- G_CALLBACK (on_stream_mute_notify),
+ G_CALLBACK (on_control_mute_notify),
bar);
update_marks (bar);
@@ -899,8 +914,8 @@ gvc_channel_bar_set_property (GObject *object,
GvcChannelBar *self = GVC_CHANNEL_BAR (object);
switch (prop_id) {
- case PROP_STREAM:
- gvc_channel_bar_set_stream (self, g_value_get_object (value));
+ case PROP_CONTROL:
+ gvc_channel_bar_set_control (self, g_value_get_object (value));
break;
case PROP_ORIENTATION:
gvc_channel_bar_set_orientation (self, g_value_get_enum (value));
@@ -944,8 +959,8 @@ gvc_channel_bar_get_property (GObject *object,
GvcChannelBar *self = GVC_CHANNEL_BAR (object);
switch (prop_id) {
- case PROP_STREAM:
- g_value_set_object (value, self->priv->stream);
+ case PROP_CONTROL:
+ g_value_set_object (value, self->priv->control);
break;
case PROP_ORIENTATION:
g_value_set_enum (value, self->priv->orientation);
@@ -979,11 +994,11 @@ gvc_channel_bar_class_init (GvcChannelBarClass *klass)
object_class->set_property = gvc_channel_bar_set_property;
object_class->get_property = gvc_channel_bar_get_property;
- properties[PROP_STREAM] =
- g_param_spec_object ("stream",
- "Stream",
- "MateMixer stream",
- MATE_MIXER_TYPE_STREAM,
+ properties[PROP_CONTROL] =
+ g_param_spec_object ("control",
+ "Control",
+ "MateMixer stream control",
+ MATE_MIXER_TYPE_STREAM_CONTROL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS);
@@ -1074,19 +1089,6 @@ gvc_channel_bar_class_init (GvcChannelBarClass *klass)
}
static void
-on_mute_button_toggled (GtkToggleButton *button, GvcChannelBar *bar)
-{
- gboolean mute;
-
- if (G_UNLIKELY (bar->priv->stream == NULL))
- g_warn_if_reached ();
-
- mute = gtk_toggle_button_get_active (button);
-
- mate_mixer_stream_set_mute (bar->priv->stream, mute);
-}
-
-static void
gvc_channel_bar_init (GvcChannelBar *bar)
{
GtkWidget *frame;
@@ -1145,10 +1147,10 @@ gvc_channel_bar_init (GvcChannelBar *bar)
}
GtkWidget *
-gvc_channel_bar_new (MateMixerStream *stream)
+gvc_channel_bar_new (MateMixerStreamControl *control)
{
return g_object_new (GVC_TYPE_CHANNEL_BAR,
- "stream", stream,
+ "control", control,
#if GTK_CHECK_VERSION (3, 0, 0)
"orientation", GTK_ORIENTATION_HORIZONTAL,
#endif