aboutsummaryrefslogtreecommitdiff
path: root/src/slider-menu-item.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/slider-menu-item.c')
-rw-r--r--src/slider-menu-item.c119
1 files changed, 104 insertions, 15 deletions
diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c
index 1c88f01..fb66563 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;
+ Device* 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,33 +111,108 @@ 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);
- active_sink_ensure_sink_is_unmuted (priv->a_sink);
+ slider_menu_item_update_volume (SLIDER_MENU_ITEM (mi), volume_input);
+ device_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*
-slider_menu_item_new (ActiveSink* sink)
+slider_menu_item_new (Device* sink)
{
SliderMenuItem *self = g_object_new(SLIDER_MENU_ITEM_TYPE, NULL);
SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (self);