aboutsummaryrefslogtreecommitdiff
path: root/src/indicator-sound.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/indicator-sound.c')
-rw-r--r--src/indicator-sound.c102
1 files changed, 46 insertions, 56 deletions
diff --git a/src/indicator-sound.c b/src/indicator-sound.c
index 588b2d6..3103aac 100644
--- a/src/indicator-sound.c
+++ b/src/indicator-sound.c
@@ -78,13 +78,12 @@ static GtkLabel * get_label (IndicatorObject * io);
static GtkImage * get_icon (IndicatorObject * io);
static GtkMenu * get_menu (IndicatorObject * io);
static GtkWidget *volume_slider = NULL;
-static gdouble input_value_from_across_the_dbus = 0.0;
static gboolean new_slider_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client);
static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget);
static gboolean slider_value_changed_event_cb(GtkRange *range, GtkScrollType scroll_type, gdouble input_value, gpointer user_data);
/*static void change_speaker_image(gdouble volume_percent);*/
-/*static void prepare_state_machine();*/
+static void prepare_state_machine();
// DBUS communication
static DBusGProxy *sound_dbus_proxy = NULL;
@@ -102,8 +101,9 @@ static const gint STATE_MUTED_WHILE_INPUT = 5;
static const gint STATE_SINKS_NONE = 5;
static GHashTable *volume_states = NULL;
static GtkImage *speaker_image = NULL;
-/*static gint current_state = 0;*/
-//static gint previous_state = 0;
+static gint current_state = 0;
+static gint previous_state = 0;
+static gdouble initial_volume_percent = 0;
static void
indicator_sound_class_init (IndicatorSoundClass *klass)
@@ -133,43 +133,36 @@ static void indicator_sound_init (IndicatorSound *self)
/* Now let's fire these guys up. */
self->service = indicator_service_manager_new_version(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_VERSION);
g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self);
- //prepare_state_machine();
-
+ prepare_state_machine();
return;
}
-/*static void test_images_hash()*/
-/*{*/
-/* gchar* name;*/
-/* g_debug("about to test the images hash"); */
-/* name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(0));*/
-/* g_debug("image name = %s", name); */
-/*}*/
+static void test_images_hash()
+{
+ g_debug("about to test the images hash");
+ gchar* current_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state));
+ g_debug("start up current image name = %s", current_name);
+ gchar* previous_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(previous_state));
+ g_debug("start up previous image name = %s", previous_name);
+}
+
+/*
+Prepare states Array.
+*/
+static void prepare_state_machine()
+{
+ volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
+ g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED), g_strdup("audio-volume-muted"));
+ g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), g_strdup("audio-volume-zero"));
+ g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_LOW), g_strdup("audio-volume-low"));
+ g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MEDIUM), g_strdup("audio-volume-medium"));
+ g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_HIGH), g_strdup("audio-volume-high"));
+ g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), g_strdup("audio-volume-muted-blocking"));
+ g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), g_strdup("audio-output-none"));
+ test_images_hash();
+}
-/*/***/
-/*Prepare states Array.*/
-/***/
-/*static void prepare_state_machine()*/
-/*{*/
-/* volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);*/
-/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED), "audio-volume-muted");*/
-/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), "audio-volume-zero");*/
-/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_LOW), "audio-volume-low");*/
-/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MEDIUM), "audio-volume-medium");*/
-/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_HIGH), "audio-volume-high");*/
-/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), "audio-volume-muted-blocking");*/
-/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), "audio-output-none");*/
-/* test_images_hash();*/
-/*}*/
-/*static void destroy_volume_image_info(void *value)*/
-/*{*/
-/* gchar* name = (gchar*)value;*/
-/* g_free(name);*/
-/* g_free(sink->description); */
-/* g_free(sink->icon_name); */
-/* g_free(sink); */
-/*}*/
static void
connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata)
@@ -195,8 +188,17 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u
dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL);
dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_TYPE_DOUBLE, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_CALLBACK(catch_signal_sink_volume_update), NULL, NULL);
-/* dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID);*/
-/* dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_CALLBACK(catch_signal_sink_mute_update), NULL, NULL);*/
+ gdouble *volume_percent_input;
+ volume_percent_input = g_new0(gdouble, 1);
+ org_ayatana_indicator_sound_get_sink_volume(sound_dbus_proxy, volume_percent_input, &error);
+ if (error != NULL) {
+ g_warning("Unable to fetch volume at indicator start up: %s", error->message);
+ g_error_free(error);
+ g_free(volume_percent_input);
+ return;
+ }
+ initial_volume_percent = *volume_percent_input * 100;
+ g_debug("at the indicator start up and the volume percent returned from dbus method is %f", initial_volume_percent);
}
} else {
@@ -219,14 +221,6 @@ static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_p
gtk_range_set_value(range, volume_percent);
}
-/*static void catch_signal_sink_mute_update(DBusGProxy * proxy, gdouble volume_percent, gpointer userdata)*/
-/*{*/
-/* g_debug("signal caught - update sink volume with value : %f", volume_percent);*/
-/* GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider);*/
-/* GtkRange* range = (GtkRange*)slider; */
-/* gtk_range_set_value(range, volume_percent); */
-/*}*/
-
static void
indicator_sound_dispose (GObject *object)
@@ -320,6 +314,9 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p
GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider);
g_signal_connect(slider, "change-value", G_CALLBACK(slider_value_changed_event_cb), newitem);
+ GtkRange* range = (GtkRange*)slider;
+ gtk_range_set_value(range, initial_volume_percent);
+
gtk_widget_show_all(volume_slider);
return TRUE;
}
@@ -328,27 +325,20 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p
we need to be responsive to that. */
static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget)
{
- g_debug("slider_prop_change_cb ");
+ g_debug("slider_prop_change_cb - dodgy updater ");
g_debug("about to set the slider to %f", g_value_get_double(value));
GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider);
- GtkRange* range = (GtkRange*)slider;
- gdouble level;
- level = gtk_range_get_fill_level(range);
- input_value_from_across_the_dbus = level;
- g_debug("the current level is %f", level);
-
+ GtkRange* range = (GtkRange*)slider;
gtk_range_set_value(range, g_value_get_double(value));
return;
}
static gboolean slider_value_changed_event_cb(GtkRange *range, GtkScrollType scroll_type, gdouble input_value, gpointer user_data)
{
-/* #if(slider_value != input_value_from_across_the_dbus)*/
-/* #{ */
DbusmenuMenuitem *item = (DbusmenuMenuitem*)user_data;
gdouble clamped_input = CLAMP(input_value, 0, 100);
GValue value = {0};
- g_debug("User input Event listener for the range - input received = %f", clamped_input);
+ g_debug("User input on SLIDER - = %f", clamped_input);
g_value_init(&value, G_TYPE_DOUBLE);
g_value_set_double(&value, clamped_input);
dbusmenu_menuitem_handle_event (item, "slider_change", &value, 0);