Commit ad398400 authored by Iain Lane's avatar Iain Lane Committed by Georges Basile Stavracas Neto
Browse files

sound: Pass a GvcMixerControl to the stream volume sliders

Since 9d612ff1 this is required,
otherwise we never set up the GtkAdjustment and so the scales don't
display any values or widget to make adjustments, meaning they can't be
used.

Also call `notify_volume_cb()` from `update_ranges()` to initialise the
adjustment, since when we set the mixer control we now might not have
set the value.

Closes #652
parent d5ddbc06
Pipeline #113184 passed with stages
in 5 minutes and 1 second
......@@ -99,7 +99,7 @@ stream_added_cb (CcStreamListBox *self,
return;
}
row = cc_stream_row_new (self->label_size_group, stream, id, self->stream_type);
row = cc_stream_row_new (self->label_size_group, stream, id, self->stream_type, self->mixer_control);
gtk_widget_show (GTK_WIDGET (row));
gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (row));
......
......@@ -73,10 +73,11 @@ cc_stream_row_init (CcStreamRow *self)
}
CcStreamRow *
cc_stream_row_new (GtkSizeGroup *size_group,
GvcMixerStream *stream,
guint id,
CcStreamType stream_type)
cc_stream_row_new (GtkSizeGroup *size_group,
GvcMixerStream *stream,
guint id,
CcStreamType stream_type,
GvcMixerControl *mixer_control)
{
CcStreamRow *self;
g_autoptr(GtkIconInfo) icon_info = NULL;
......@@ -110,6 +111,7 @@ cc_stream_row_new (GtkSizeGroup *size_group,
gtk_label_set_label (self->name_label, gvc_mixer_stream_get_name (stream));
cc_volume_slider_set_stream (self->volume_slider, stream, stream_type);
cc_volume_slider_set_mixer_control (self->volume_slider, mixer_control);
gtk_size_group_add_widget (size_group, GTK_WIDGET (self->label_box));
......
......@@ -20,6 +20,7 @@
#include <gtk/gtk.h>
#include <pulse/pulseaudio.h>
#include <gvc-mixer-control.h>
#include <gvc-mixer-stream.h>
#include "cc-sound-enums.h"
......@@ -29,10 +30,11 @@ G_BEGIN_DECLS
#define CC_TYPE_STREAM_ROW (cc_stream_row_get_type ())
G_DECLARE_FINAL_TYPE (CcStreamRow, cc_stream_row, CC, STREAM_ROW, GtkListBoxRow)
CcStreamRow *cc_stream_row_new (GtkSizeGroup *size_group,
GvcMixerStream *stream,
guint id,
CcStreamType stream_type);
CcStreamRow *cc_stream_row_new (GtkSizeGroup *size_group,
GvcMixerStream *stream,
guint id,
CcStreamType stream_type,
GvcMixerControl *mixer_control);
GvcMixerStream *cc_stream_row_get_stream (CcStreamRow *row);
......
......@@ -43,6 +43,36 @@ struct _CcVolumeSlider
G_DEFINE_TYPE (CcVolumeSlider, cc_volume_slider, GTK_TYPE_BOX)
static void
volume_changed_cb (CcVolumeSlider *self)
{
gdouble volume, rounded;
if (self->stream == NULL)
return;
volume = gtk_adjustment_get_value (self->volume_adjustment);
rounded = round (volume);
gtk_toggle_button_set_active (self->mute_button, volume == 0.0);
if (gvc_mixer_stream_set_volume (self->stream, (pa_volume_t) rounded))
gvc_mixer_stream_push_volume (self->stream);
}
static void
notify_volume_cb (CcVolumeSlider *self)
{
g_signal_handlers_block_by_func (self->volume_adjustment, volume_changed_cb, self);
if (gtk_toggle_button_get_active (self->mute_button))
gtk_adjustment_set_value (self->volume_adjustment, 0.0);
else
gtk_adjustment_set_value (self->volume_adjustment, gvc_mixer_stream_get_volume (self->stream));
g_signal_handlers_unblock_by_func (self->volume_adjustment, volume_changed_cb, self);
}
static void
update_ranges (CcVolumeSlider *self)
{
......@@ -67,25 +97,9 @@ update_ranges (CcVolumeSlider *self)
gtk_adjustment_set_upper (self->volume_adjustment, vol_max_norm);
}
gtk_adjustment_set_page_increment (self->volume_adjustment, vol_max_norm / 100.0);
}
static void
volume_changed_cb (CcVolumeSlider *self)
{
gdouble volume, rounded;
if (self->stream == NULL)
return;
volume = gtk_adjustment_get_value (self->volume_adjustment);
rounded = round (volume);
gtk_toggle_button_set_active (self->mute_button, volume == 0.0);
if (gvc_mixer_stream_set_volume (self->stream,
(pa_volume_t) rounded))
{
gvc_mixer_stream_push_volume (self->stream);
}
if (self->stream)
notify_volume_cb (self);
}
static void
......@@ -97,17 +111,6 @@ mute_button_toggled_cb (CcVolumeSlider *self)
gvc_mixer_stream_change_is_muted (self->stream, gtk_toggle_button_get_active (self->mute_button));
}
static void
notify_volume_cb (CcVolumeSlider *self)
{
g_signal_handlers_block_by_func (self->volume_adjustment, volume_changed_cb, self);
if (gtk_toggle_button_get_active (self->mute_button))
gtk_adjustment_set_value (self->volume_adjustment, 0.0);
else
gtk_adjustment_set_value (self->volume_adjustment, gvc_mixer_stream_get_volume (self->stream));
g_signal_handlers_unblock_by_func (self->volume_adjustment, volume_changed_cb, self);
}
static void
notify_is_muted_cb (CcVolumeSlider *self)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment