diff options
-rw-r--r-- | src/active-sink.c | 86 | ||||
-rw-r--r-- | src/active-sink.h | 1 | ||||
-rw-r--r-- | src/slider-menu-item.c | 115 | ||||
-rw-r--r-- | src/slider-menu-item.h | 8 | ||||
-rw-r--r-- | src/sound-service.c | 2 |
5 files changed, 125 insertions, 87 deletions
diff --git a/src/active-sink.c b/src/active-sink.c index a78d33e..9d6e223 100644 --- a/src/active-sink.c +++ b/src/active-sink.c @@ -33,11 +33,6 @@ struct _ActiveSinkPrivate VoipInputMenuItem* voip_input_menu_item; SoundState current_sound_state; SoundServiceDbus* service; - gint index; - gchar* name; - pa_cvolume volume; - pa_channel_map channel_map; - pa_volume_t base_volume; }; #define ACTIVE_SINK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ACTIVE_SINK_TYPE, ActiveSinkPrivate)) @@ -49,7 +44,6 @@ static void active_sink_dispose (GObject *object); static void active_sink_finalize (GObject *object); static SoundState active_sink_get_state_from_volume (ActiveSink* self); -static pa_cvolume active_sink_construct_mono_volume (const pa_cvolume* vol); static void active_sink_volume_update (ActiveSink* self, gdouble percent); static void active_sink_mute_update (ActiveSink* self, gboolean muted); @@ -74,8 +68,6 @@ active_sink_init (ActiveSink *self) priv->volume_slider_menuitem = NULL; priv->voip_input_menu_item = NULL; priv->current_sound_state = UNAVAILABLE; - priv->index = -1; - priv->name = NULL; priv->service = NULL; // Init our menu items. @@ -103,23 +95,16 @@ active_sink_populate (ActiveSink* sink, const pa_sink_info* update) { ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE(sink); - - priv->name = g_strdup (update->name); - priv->index = update->index; - 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_volume_update (sink, volume_percent); active_sink_mute_update (sink, update->mute); mute_menu_item_enable (priv->mute_menuitem, TRUE); - slider_menu_item_enable (priv->volume_slider_menuitem, TRUE); + slider_menu_item_populate (priv->volume_slider_menuitem, update); + SoundState state = active_sink_get_state_from_volume (sink); + if (priv->current_sound_state != state){ + priv->current_sound_state = state; + sound_service_dbus_update_sound_state (priv->service, + priv->current_sound_state); + } - g_debug ("Active sink has been populated - volume %f", volume_percent); } void @@ -153,49 +138,18 @@ active_sink_update (ActiveSink* sink, const pa_sink_info* update) { ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (sink); - 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; + slider_menu_item_update (priv->volume_slider_menuitem, update); - pa_volume_t vol = pa_cvolume_max (&update->volume); - gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM; - - active_sink_volume_update (sink, volume_percent); - active_sink_mute_update (sink, update->mute); -} - -// To the UI -static 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); - SoundState state = active_sink_get_state_from_volume (self); + SoundState state = active_sink_get_state_from_volume (sink); if (priv->current_sound_state != state){ priv->current_sound_state = state; sound_service_dbus_update_sound_state (priv->service, priv->current_sound_state); } -} - -// From the UI -void -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); - - pa_cvolume_set(&priv->volume, priv->channel_map.channels, new_volume_value); - pm_update_volume (priv->index, new_volume); + active_sink_mute_update (sink, update->mute); } - gint active_sink_get_current_sink_input_index (ActiveSink* sink) { @@ -213,6 +167,7 @@ active_sink_mute_update (ActiveSink* self, gboolean muted) if (muted == TRUE){ state = MUTED; } + // Only send signals if something has changed if (priv->current_sound_state != state){ priv->current_sound_state = state; sound_service_dbus_update_sound_state (priv->service, state); @@ -254,17 +209,6 @@ active_sink_get_state_from_volume (ActiveSink* self) return state; } -pa_cvolume -active_sink_construct_mono_volume (const pa_cvolume* vol) -{ - pa_cvolume new_volume; - pa_cvolume_init(&new_volume); - new_volume.channels = 1; - pa_volume_t max_vol = pa_cvolume_max(vol); - pa_cvolume_set(&new_volume, 1, max_vol); - return new_volume; -} - void active_sink_determine_blocking_state (ActiveSink* self) { @@ -283,14 +227,15 @@ gint active_sink_get_index (ActiveSink* self) { ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self); - return priv->index; + return slider_menu_item_get_sink_index (priv->volume_slider_menuitem); } gboolean active_sink_is_populated (ActiveSink* sink) { ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (sink); - return (priv->index != -1); + return dbusmenu_menuitem_property_get_bool (DBUSMENU_MENUITEM (priv->volume_slider_menuitem), + DBUSMENU_MENUITEM_PROP_ENABLED); } void @@ -302,9 +247,6 @@ active_sink_deactivate (ActiveSink* self) priv->current_sound_state); mute_menu_item_enable (priv->mute_menuitem, FALSE); slider_menu_item_enable (priv->volume_slider_menuitem, FALSE); - priv->index = -1; - g_free(priv->name); - priv->name = NULL; } SoundState diff --git a/src/active-sink.h b/src/active-sink.h index 57b3079..7215648 100644 --- a/src/active-sink.h +++ b/src/active-sink.h @@ -64,7 +64,6 @@ gboolean active_sink_is_populated (ActiveSink* sink); gint active_sink_get_index (ActiveSink* self); void active_sink_deactivate (ActiveSink* self); void active_sink_update_mute (ActiveSink* self, gboolean mute_update); -void active_sink_update_volume (ActiveSink* self, gdouble percent); void active_sink_ensure_sink_is_unmuted (ActiveSink* self); // source and sinkinput/client related for VOIP functionality diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c index 1c88f01..270b996 100644 --- a/src/slider-menu-item.c +++ b/src/slider-menu-item.c @@ -23,11 +23,17 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <glib/gi18n.h> #include "slider-menu-item.h" #include "common-defs.h" +#include "pulseaudio-mgr.h" typedef struct _SliderMenuItemPrivate SliderMenuItemPrivate; struct _SliderMenuItemPrivate { - ActiveSink* a_sink; + ActiveSink* a_sink; + gint index; + gchar* name; + pa_cvolume volume; + pa_channel_map channel_map; + pa_volume_t base_volume; }; #define SLIDER_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SLIDER_MENU_ITEM_TYPE, SliderMenuItemPrivate)) @@ -39,6 +45,8 @@ static void slider_menu_item_dispose (GObject *object); static void slider_menu_item_finalize (GObject *object); static void handle_event (DbusmenuMenuitem * mi, const gchar * name, GVariant * value, guint timestamp); +static pa_cvolume slider_menu_item_construct_mono_volume (const pa_cvolume* vol); +static void slider_menu_item_update_volume (SliderMenuItem* self, gdouble percent); G_DEFINE_TYPE (SliderMenuItem, slider_menu_item, DBUSMENU_TYPE_MENUITEM); @@ -63,7 +71,13 @@ slider_menu_item_init (SliderMenuItem *self) g_debug("Building new Slider Menu Item"); dbusmenu_menuitem_property_set( DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_TYPE, - DBUSMENU_VOLUME_MENUITEM_TYPE ); + DBUSMENU_VOLUME_MENUITEM_TYPE ); + + SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self); + + priv->index = -1; + priv->name = NULL; + return; } @@ -97,29 +111,104 @@ handle_event (DbusmenuMenuitem * mi, SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (SLIDER_MENU_ITEM (mi)); gdouble volume_input = g_variant_get_double(input); //g_debug ("slider menu item about to update volume %f", volume_input); - active_sink_update_volume (priv->a_sink, volume_input); + slider_menu_item_update_volume (SLIDER_MENU_ITEM (mi), volume_input); active_sink_ensure_sink_is_unmuted (priv->a_sink); } } } + +void +slider_menu_item_populate (SliderMenuItem* self, const pa_sink_info* update) +{ + SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self); + priv->name = g_strdup (update->name); + priv->index = update->index; + priv->volume = slider_menu_item_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; + GVariant* new_volume = g_variant_new_double (volume_percent); + dbusmenu_menuitem_property_set_variant (DBUSMENU_MENUITEM(self), + DBUSMENU_VOLUME_MENUITEM_LEVEL, + new_volume); + slider_menu_item_enable (self, TRUE); +} + +// From the UI +static void +slider_menu_item_update_volume (SliderMenuItem* 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); + + SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self); + + pa_cvolume_set(&priv->volume, priv->channel_map.channels, new_volume_value); + pm_update_volume (priv->index, new_volume); +} + +// To the UI void -slider_menu_item_update (SliderMenuItem* item, - gdouble update) +slider_menu_item_update (SliderMenuItem* self, const pa_sink_info* update) { - GVariant* new_volume = g_variant_new_double(update); - dbusmenu_menuitem_property_set_variant(DBUSMENU_MENUITEM(item), - DBUSMENU_VOLUME_MENUITEM_LEVEL, - new_volume); + SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self); + + priv->volume = slider_menu_item_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; + + GVariant* new_volume = g_variant_new_double (volume_percent); + dbusmenu_menuitem_property_set_variant (DBUSMENU_MENUITEM(self), + DBUSMENU_VOLUME_MENUITEM_LEVEL, + new_volume); } +/* + * Enable/Disabled can be considered the equivalent of whether we have an active + * sink or not, let the widget have inherent state. + */ void -slider_menu_item_enable (SliderMenuItem* item, - gboolean active) +slider_menu_item_enable (SliderMenuItem* self, gboolean active) { - dbusmenu_menuitem_property_set_bool( DBUSMENU_MENUITEM(item), + SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self); + + dbusmenu_menuitem_property_set_bool (DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_ENABLED, - active ); + active); + if(active == FALSE){ + priv->index = -1; + if(priv->name != NULL){ + g_free(priv->name); + priv->name = NULL; + } + } +} + +gint +slider_menu_item_get_sink_index (SliderMenuItem* self) +{ + SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self); + return priv->index; +} + +static pa_cvolume +slider_menu_item_construct_mono_volume (const pa_cvolume* vol) +{ + pa_cvolume new_volume; + pa_cvolume_init(&new_volume); + new_volume.channels = 1; + pa_volume_t max_vol = pa_cvolume_max(vol); + pa_cvolume_set(&new_volume, 1, max_vol); + return new_volume; } SliderMenuItem* diff --git a/src/slider-menu-item.h b/src/slider-menu-item.h index f094c71..b489032 100644 --- a/src/slider-menu-item.h +++ b/src/slider-menu-item.h @@ -47,8 +47,14 @@ struct _SliderMenuItem { GType slider_menu_item_get_type (void); -void slider_menu_item_update(SliderMenuItem* item, gdouble update); +void slider_menu_item_update(SliderMenuItem* item, const pa_sink_info* update); void slider_menu_item_enable(SliderMenuItem* item, gboolean active); +void slider_menu_item_populate (SliderMenuItem* self, const pa_sink_info* update); +//void +//active_sink_update (ActiveSink* sink, +// const pa_sink_info* update) + +gint slider_menu_item_get_sink_index (SliderMenuItem* self); SliderMenuItem* slider_menu_item_new (ActiveSink* sink); diff --git a/src/sound-service.c b/src/sound-service.c index cfc0b7e..9f44624 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -39,8 +39,10 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { g_debug("Service shutdown !"); +/* close_pulse_activites(); g_main_loop_quit(mainloop); +*/ } return; } |