aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/active-sink.c56
-rw-r--r--src/active-sink.h6
-rw-r--r--src/pulseaudio-mgr.c6
-rw-r--r--src/pulseaudio-mgr.h1
-rw-r--r--src/slider-menu-item.c32
-rw-r--r--src/slider-menu-item.h4
6 files changed, 67 insertions, 38 deletions
diff --git a/src/active-sink.c b/src/active-sink.c
index 37cdf51..16ab784 100644
--- a/src/active-sink.c
+++ b/src/active-sink.c
@@ -77,7 +77,7 @@ active_sink_init(ActiveSink *self)
// Init our menu items.
priv->mute_menuitem = g_object_new (MUTE_MENU_ITEM_TYPE, NULL);
- priv->volume_slider_menuitem = g_object_new (SLIDER_MENU_ITEM_TYPE, NULL);
+ priv->volume_slider_menuitem = slider_menu_item_new (self);
}
static void
@@ -101,14 +101,14 @@ active_sink_populate (ActiveSink* sink,
priv->name = g_strdup (update->name);
priv->index = update->index;
// Why the double negative !?
- active_sink_update_mute (sink, !!update->mute);
+ active_sink_mute_update (sink, !!update->mute);
priv->volume = active_sink_construct_mono_volume (&update->volume);
priv->base_volume = update->base_volume;
priv->channel_map = update->channel_map;
pa_volume_t vol = pa_cvolume_max (&update->volume);
gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM;
- active_sink_update_volume (sink, volume_percent);
+ active_sink_volume_update (sink, volume_percent);
g_debug ("Active sink has been populated - volume %f", volume_percent);
}
@@ -141,7 +141,27 @@ active_sink_get_index (ActiveSink* self)
}
void
-active_sink_update_volume (ActiveSink* self, gdouble percent)
+active_sink_deactivate (ActiveSink* self)
+{
+ ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);
+ priv->current_sound_state = UNAVAILABLE;
+ sound_service_dbus_update_sound_state (priv->service,
+ priv->current_sound_state);
+ priv->index = -1;
+ g_free(priv->name);
+ priv->name = NULL;
+}
+
+SoundState
+active_sink_get_state (ActiveSink* self)
+{
+ ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);
+ return priv->current_sound_state;
+}
+
+// To the UI
+void
+active_sink_volume_update (ActiveSink* self, gdouble percent)
{
ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);
slider_menu_item_update (priv->volume_slider_menuitem, percent);
@@ -152,20 +172,25 @@ active_sink_update_volume (ActiveSink* self, gdouble percent)
priv->current_sound_state);
}
+// From the UI
void
-active_sink_deactivate (ActiveSink* self)
+active_sink_update_volume (ActiveSink* self, gdouble percent)
{
+ pa_cvolume new_volume;
+ pa_cvolume_init(&new_volume);
+ new_volume.channels = 1;
+ pa_volume_t new_volume_value = (pa_volume_t) ((percent * PA_VOLUME_NORM) / 100);
+ pa_cvolume_set(&new_volume, 1, new_volume_value);
+
ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);
- priv->current_sound_state = UNAVAILABLE;
- sound_service_dbus_update_sound_state (priv->service,
- priv->current_sound_state);
- priv->index = -1;
- g_free(priv->name);
- priv->name = NULL;
+
+ pa_cvolume_set(&priv->volume, priv->channel_map.channels, new_volume_value);
+
}
+
void
-active_sink_update_mute (ActiveSink* self, gboolean muted)
+active_sink_mute_update (ActiveSink* self, gboolean muted)
{
ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);
mute_menu_item_update (priv->mute_menuitem, muted);
@@ -178,13 +203,6 @@ active_sink_update_mute (ActiveSink* self, gboolean muted)
sound_service_dbus_update_sound_state (priv->service, state);
}
-SoundState
-active_sink_get_state (ActiveSink* self)
-{
- ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self);
- return priv->current_sound_state;
-}
-
static SoundState
active_sink_get_state_from_volume (ActiveSink* self)
diff --git a/src/active-sink.h b/src/active-sink.h
index 5fdcba9..40dd84e 100644
--- a/src/active-sink.h
+++ b/src/active-sink.h
@@ -60,8 +60,10 @@ SoundState active_sink_get_state (ActiveSink* self);
void active_sink_deactivate (ActiveSink* self);
-void active_sink_update_volume (ActiveSink* self, gdouble vol_percent);
-void active_sink_update_mute (ActiveSink* self, gboolean muted);
+void active_sink_volume_update (ActiveSink* self, gdouble vol_percent);
+void active_sink_update_volume (ActiveSink* self, gdouble percent);
+
+void active_sink_mute_update (ActiveSink* self, gboolean muted);
ActiveSink* active_sink_new (SoundServiceDbus* service);
diff --git a/src/pulseaudio-mgr.c b/src/pulseaudio-mgr.c
index cb786de..c8439e8 100644
--- a/src/pulseaudio-mgr.c
+++ b/src/pulseaudio-mgr.c
@@ -55,13 +55,11 @@ static void pm_sink_input_info_callback (pa_context *c,
const pa_sink_input_info *info,
int eol,
void *userdata);
-
static void pm_update_active_sink (pa_context *c,
const pa_sink_info *info,
int eol,
void *userdata);
-
static gboolean reconnect_to_pulse (gpointer user_data);
static gint connection_attempts = 0;
@@ -370,8 +368,8 @@ pm_update_active_sink (pa_context *c,
}
pa_volume_t vol = pa_cvolume_max (&info->volume);
gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM;
- active_sink_update_volume (ACTIVE_SINK(userdata), volume_percent);
- active_sink_update_mute (ACTIVE_SINK(userdata), info->mute);
+ active_sink_volume_update (ACTIVE_SINK(userdata), volume_percent);
+ active_sink_mute_update (ACTIVE_SINK(userdata), info->mute);
}
}
diff --git a/src/pulseaudio-mgr.h b/src/pulseaudio-mgr.h
index af4f29c..524b323 100644
--- a/src/pulseaudio-mgr.h
+++ b/src/pulseaudio-mgr.h
@@ -21,6 +21,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
void pm_establish_pulse_connection (ActiveSink* active_sink);
void close_pulse_activites();
+//void pm_update_volume (gint sink_index);
diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c
index 6fd4dbc..31d4774 100644
--- a/src/slider-menu-item.c
+++ b/src/slider-menu-item.c
@@ -25,10 +25,10 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "pulse-manager.h"
#include "common-defs.h"
-
typedef struct _SliderMenuItemPrivate SliderMenuItemPrivate;
struct _SliderMenuItemPrivate {
+ ActiveSink* a_sink;
};
#define SLIDER_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SLIDER_MENU_ITEM_TYPE, SliderMenuItemPrivate))
@@ -43,7 +43,8 @@ static void handle_event (DbusmenuMenuitem * mi, const gchar * name,
G_DEFINE_TYPE (SliderMenuItem, slider_menu_item, DBUSMENU_TYPE_MENUITEM);
-static void slider_menu_item_class_init (SliderMenuItemClass *klass)
+static void
+slider_menu_item_class_init (SliderMenuItemClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -57,7 +58,8 @@ static void slider_menu_item_class_init (SliderMenuItemClass *klass)
return;
}
-static void slider_menu_item_init (SliderMenuItem *self)
+static void
+slider_menu_item_init (SliderMenuItem *self)
{
g_debug("Building new Slider Menu Item");
dbusmenu_menuitem_property_set( DBUSMENU_MENUITEM(self),
@@ -66,7 +68,8 @@ static void slider_menu_item_init (SliderMenuItem *self)
return;
}
-static void slider_menu_item_dispose (GObject *object)
+static void
+slider_menu_item_dispose (GObject *object)
{
G_OBJECT_CLASS (slider_menu_item_parent_class)->dispose (object);
return;
@@ -92,6 +95,12 @@ handle_event (DbusmenuMenuitem * mi,
gboolean volume_input = g_variant_get_double(input);
if (value != NULL){
+ if (IS_SLIDER_MENU_ITEM (mi)) {
+ SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (SLIDER_MENU_ITEM (mi));
+ active_sink_update_volume (priv->a_sink, volume_input);
+ }
+
+ //active_sink_update_volume (
// TODO - when the ACTIVESINK instance exists this will be handled nicely
// PA MANAGER will be refactored first.
@@ -102,7 +111,8 @@ handle_event (DbusmenuMenuitem * mi,
}
}
-void slider_menu_item_update (SliderMenuItem* item,
+void
+slider_menu_item_update (SliderMenuItem* item,
gdouble update)
{
GVariant* new_volume = g_variant_new_double(update);
@@ -111,7 +121,8 @@ void slider_menu_item_update (SliderMenuItem* item,
new_volume);
}
-void slider_menu_item_enable (SliderMenuItem* item,
+void
+slider_menu_item_enable (SliderMenuItem* item,
gboolean active)
{
dbusmenu_menuitem_property_set_bool( DBUSMENU_MENUITEM(item),
@@ -119,12 +130,11 @@ void slider_menu_item_enable (SliderMenuItem* item,
active );
}
-SliderMenuItem* slider_menu_item_new (gboolean sinks_available,
- gdouble start_volume)
+SliderMenuItem*
+slider_menu_item_new (ActiveSink* sink)
{
SliderMenuItem *self = g_object_new(SLIDER_MENU_ITEM_TYPE, NULL);
- slider_menu_item_update (self, start_volume);
- slider_menu_item_enable (self, sinks_available);
-
+ SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self);
+ priv->a_sink = sink;
return self;
} \ No newline at end of file
diff --git a/src/slider-menu-item.h b/src/slider-menu-item.h
index 51336ae..f094c71 100644
--- a/src/slider-menu-item.h
+++ b/src/slider-menu-item.h
@@ -23,6 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <glib-object.h>
#include <libdbusmenu-glib/menuitem.h>
+#include "active-sink.h"
G_BEGIN_DECLS
@@ -49,8 +50,7 @@ GType slider_menu_item_get_type (void);
void slider_menu_item_update(SliderMenuItem* item, gdouble update);
void slider_menu_item_enable(SliderMenuItem* item, gboolean active);
-SliderMenuItem* slider_menu_item_new (gboolean sinks_available,
- gdouble current_vol);
+SliderMenuItem* slider_menu_item_new (ActiveSink* sink);
G_END_DECLS