aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Bacher <seb128@ubuntu.com>2010-03-31 17:49:12 +0200
committerSebastien Bacher <seb128@ubuntu.com>2010-03-31 17:49:12 +0200
commitaf4e502ea8bb14cf13561feb8f8687cd144b5399 (patch)
tree0cb45faabc050b9403733b36a430729efdce2e94 /src
parentd51bf7d31390a50eb79beaf20a10bdcfed28f67b (diff)
parentc82de623381c8e578acff7f9a7074aabbb8258aa (diff)
downloadayatana-indicator-sound-af4e502ea8bb14cf13561feb8f8687cd144b5399.tar.gz
ayatana-indicator-sound-af4e502ea8bb14cf13561feb8f8687cd144b5399.tar.bz2
ayatana-indicator-sound-af4e502ea8bb14cf13561feb8f8687cd144b5399.zip
Import upstream version 0.2.2
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/Makefile.in8
-rw-r--r--src/dbus-menu-manager.c1
-rw-r--r--src/indicator-sound.c58
-rw-r--r--src/pulse-manager.c75
-rw-r--r--src/pulse-manager.h4
-rw-r--r--src/slider-menu-item.c6
-rw-r--r--src/sound-service-dbus.c2
-rw-r--r--src/sound-service.c2
9 files changed, 94 insertions, 66 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 062d993..f472662 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -45,8 +45,8 @@ indicator_sound_service_SOURCES = \
sound-service-server.h \
slider-menu-item.h \
slider-menu-item.c
-indicator_sound_service_CFLAGS = $(SOUNDSERVICE_CFLAGS) $(GCONF_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" -Wall -Werror
-indicator_sound_service_LDADD = $(SOUNDSERVICE_LIBS) $(GCONF_LIBS)
+indicator_sound_service_CFLAGS = $(PULSEAUDIO_CFLAGS) $(SOUNDSERVICE_CFLAGS) $(GCONF_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" -Wall -Werror
+indicator_sound_service_LDADD = $(PULSEAUDIO_LIBS) $(SOUNDSERVICE_LIBS) $(GCONF_LIBS)
sound-service-server.h: $(srcdir)/sound-service.xml
dbus-binding-tool \
diff --git a/src/Makefile.in b/src/Makefile.in
index d4506f7..7970677 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -94,7 +94,7 @@ am_indicator_sound_service_OBJECTS = \
indicator_sound_service_OBJECTS = \
$(am_indicator_sound_service_OBJECTS)
indicator_sound_service_DEPENDENCIES = $(am__DEPENDENCIES_1) \
- $(am__DEPENDENCIES_1)
+ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
indicator_sound_service_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
$(indicator_sound_service_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
@@ -220,6 +220,8 @@ POFILES = @POFILES@
POSUB = @POSUB@
PO_IN_DATADIR_FALSE = @PO_IN_DATADIR_FALSE@
PO_IN_DATADIR_TRUE = @PO_IN_DATADIR_TRUE@
+PULSEAUDIO_CFLAGS = @PULSEAUDIO_CFLAGS@
+PULSEAUDIO_LIBS = @PULSEAUDIO_LIBS@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
@@ -317,8 +319,8 @@ indicator_sound_service_SOURCES = \
slider-menu-item.h \
slider-menu-item.c
-indicator_sound_service_CFLAGS = $(SOUNDSERVICE_CFLAGS) $(GCONF_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" -Wall -Werror
-indicator_sound_service_LDADD = $(SOUNDSERVICE_LIBS) $(GCONF_LIBS)
+indicator_sound_service_CFLAGS = $(PULSEAUDIO_CFLAGS) $(SOUNDSERVICE_CFLAGS) $(GCONF_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" -Wall -Werror
+indicator_sound_service_LDADD = $(PULSEAUDIO_LIBS) $(SOUNDSERVICE_LIBS) $(GCONF_LIBS)
###############
# Other Stuff
diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c
index 1628a59..e084bb1 100644
--- a/src/dbus-menu-manager.c
+++ b/src/dbus-menu-manager.c
@@ -157,7 +157,6 @@ static void refresh_menu()
}
-
/**
idle_routine:
Something for glip mainloop to do when idle
diff --git a/src/indicator-sound.c b/src/indicator-sound.c
index a1a531a..6c8f4e1 100644
--- a/src/indicator-sound.c
+++ b/src/indicator-sound.c
@@ -85,10 +85,8 @@ static void scroll (IndicatorObject*io, gint delta, IndicatorScrollDirec
//Slider related
static GtkWidget *volume_slider = NULL;
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 value_changed_event_cb(GtkRange *range, gpointer user_data);
static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data);
-/*static void slider_size_allocate(GtkWidget *widget, GtkAllocation *allocation, gpointer user_data);*/
static void slider_grabbed(GtkWidget *widget, gpointer user_data);
static void slider_released(GtkWidget *widget, gpointer user_data);
@@ -122,14 +120,17 @@ static gint previous_state = 0;
static gdouble initial_volume_percent = 0;
static gboolean initial_mute ;
static gboolean device_available;
-static gboolean slider_in_direct_use;
+static gboolean slider_in_direct_use = FALSE;
static GtkIconSize design_team_size;
+static gint blocked_id;
static gint animation_id;
+
static GList * blocked_animation_list = NULL;
static GList * blocked_iter = NULL;
static void prepare_blocked_animation();
static gboolean fade_back_to_mute_image();
+static gboolean start_animation();
// Construction
static void
@@ -144,9 +145,9 @@ indicator_sound_class_init (IndicatorSoundClass *klass)
io_class->get_label = get_label;
io_class->get_image = get_icon;
io_class->get_menu = get_menu;
- io_class->scroll = scroll;
+ io_class->scroll = scroll;
- design_team_size = gtk_icon_size_register("design-team-size", 22, 22);
+ design_team_size = gtk_icon_size_register("design-team-size", 22, 22);
return;
}
@@ -158,6 +159,7 @@ static void indicator_sound_init (IndicatorSound *self)
prepare_state_machine();
prepare_blocked_animation();
animation_id = 0;
+ blocked_id = 0;
initial_mute = FALSE;
device_available = TRUE;
slider_in_direct_use = FALSE;
@@ -268,7 +270,6 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p
g_signal_connect(slider, "value-changed", G_CALLBACK(value_changed_event_cb), newitem);
g_signal_connect(volume_slider, "slider-grabbed", G_CALLBACK(slider_grabbed), NULL);
g_signal_connect(volume_slider, "slider-released", G_CALLBACK(slider_released), NULL);
-/* g_signal_connect(slider, "size-allocate", G_CALLBACK(slider_size_allocate), NULL);*/
// Set images on the ido
GtkWidget* primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider);
@@ -282,6 +283,10 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p
g_object_unref(secondary_gicon);
gtk_widget_set_sensitive(volume_slider, !initial_mute);
+
+ GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (slider));
+ gtk_adjustment_set_step_increment(adj, 3);
+
gtk_widget_show_all(volume_slider);
return TRUE;
@@ -370,13 +375,13 @@ static void prepare_blocked_animation()
return;
}
- // sample 22 snapshots - range : 0-256
- for(i = 0; i < 23; i++)
+ // sample 51 snapshots - range : 0-256
+ for(i = 0; i < 51; i++)
{
gdk_pixbuf_composite(mute_buf, blocked_buf, 0, 0,
gdk_pixbuf_get_width(mute_buf),
gdk_pixbuf_get_height(mute_buf),
- 0, 0, 1, 1, GDK_INTERP_BILINEAR, MIN(255, i * 11));
+ 0, 0, 1, 1, GDK_INTERP_BILINEAR, MIN(255, i * 5));
blocked_animation_list = g_list_append(blocked_animation_list, gdk_pixbuf_copy(blocked_buf));
}
}
@@ -502,15 +507,22 @@ static void fetch_mute_value_from_dbus()
static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean block_value, gpointer userdata)
{
g_debug("signal caught - sink input while muted with value %i", block_value);
- if (block_value == 1 && animation_id == 0 && blocked_animation_list != NULL) {
+ if (block_value == 1 && blocked_id == 0 && animation_id == 0 && blocked_animation_list != NULL) {
gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT));
indicator_image_helper_update(speaker_image, image_name);
-
- blocked_iter = blocked_animation_list;
- animation_id = g_timeout_add_seconds(1, fade_back_to_mute_image, NULL);
+ blocked_id = g_timeout_add_seconds(5, start_animation, NULL);
}
}
+static gboolean start_animation()
+{
+ blocked_iter = blocked_animation_list;
+ blocked_id = 0;
+ g_debug("exit from blocked hold start the animation\n");
+ animation_id = g_timeout_add(50, fade_back_to_mute_image, NULL);
+ return FALSE;
+}
+
static gboolean fade_back_to_mute_image()
{
if(blocked_iter != NULL)
@@ -555,6 +567,11 @@ static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value
g_source_remove(animation_id);
animation_id = 0;
}
+ if(blocked_id != 0){
+ g_debug("about to remove the blocked_id callback from the mainloop!!**");
+ g_source_remove(blocked_id);
+ blocked_id = 0;
+ }
}
g_debug("signal caught - sink mute update with mute value: %i", mute_value);
gtk_widget_set_sensitive(volume_slider, !mute_value);
@@ -677,12 +694,15 @@ scroll (IndicatorObject *io, gint delta, IndicatorScrollDirection direction)
IndicatorSound *sound = INDICATOR_SOUND (io);
GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (sound->slider));
gdouble value = gtk_range_get_value (GTK_RANGE (sound->slider));
+
+ //g_debug("the scroll step size = %f", adj->step_increment);
- if (direction == INDICATOR_OBJECT_SCROLL_UP)
- value += adj->step_increment;
- else
- value -= adj->step_increment;
-
+ if (direction == INDICATOR_OBJECT_SCROLL_UP){
+ value += adj->step_increment;
+ }
+ else{
+ value -= adj->step_increment;
+ }
gtk_range_set_value (GTK_RANGE (sound->slider),
- value);
+ value);
}
diff --git a/src/pulse-manager.c b/src/pulse-manager.c
index e1634a9..1ce94d0 100644
--- a/src/pulse-manager.c
+++ b/src/pulse-manager.c
@@ -67,11 +67,15 @@ void establish_pulse_activities(SoundServiceDbus *service)
// Establish event callback registration
pa_context_set_state_callback(pulse_context, context_state_callback, NULL);
- // Broadcast init state (assume we have a device - if not the signals will handle it)
- dbus_menu_manager_update_pa_state(FALSE, TRUE, FALSE, 0);
+ dbus_menu_manager_update_pa_state(FALSE, FALSE, FALSE, 0);
pa_context_connect(pulse_context, NULL, PA_CONTEXT_NOFAIL, NULL);
}
+pa_context* get_context()
+{
+ return pulse_context;
+}
+
void close_pulse_activites()
{
if (pulse_context != NULL){
@@ -98,7 +102,11 @@ static void reconnect_to_pulse()
pa_context_unref(pulse_context);
pulse_context = NULL;
}
- g_hash_table_destroy(sink_hash);
+
+ if(sink_hash != NULL){
+ g_hash_table_destroy(sink_hash);
+ sink_hash = NULL;
+ }
// reconnect
pulse_context = pa_context_new(pa_glib_mainloop_get_api(pa_main_loop), "ayatana.indicator.sound");
@@ -114,18 +122,14 @@ static void destroy_sink_info(void *value)
{
sink_info *sink = (sink_info*)value;
g_free(sink->name);
- g_free(sink->description);
- g_free(sink->icon_name);
g_free(sink);
}
/*
Controllers & Utilities
*/
-
static gboolean determine_sink_availability()
{
-
// Firstly check to see if we have any sinks
// if not get the hell out of here !
if (g_hash_table_size(sink_hash) < 1){
@@ -133,21 +137,24 @@ static gboolean determine_sink_availability()
DEFAULT_SINK_INDEX = -1;
return FALSE;
}
-
// Secondly, make sure the default sink index is set
- // If the default sink index has not been set (via the server) it will attempt to set it to the value of the first
+ // If the default sink index has not been set
+ // (via the server or has been reset because default sink has been removed),
+ // it will attempt to set it to the value of the first
// index in the array of keys from the sink_hash.
- GList *keys = g_hash_table_get_keys(sink_hash);
- DEFAULT_SINK_INDEX = (DEFAULT_SINK_INDEX < 0) ? GPOINTER_TO_INT(g_list_first(keys)) : DEFAULT_SINK_INDEX;
+ GList* keys = g_hash_table_get_keys(sink_hash);
+ GList* key = g_list_first(keys);
+
+ DEFAULT_SINK_INDEX = (DEFAULT_SINK_INDEX < 0) ? GPOINTER_TO_INT(key->data) : DEFAULT_SINK_INDEX;
// Thirdly ensure the default sink index does not have the name "auto_null"
- sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX));
- // Up until now the most rebost method to test this is to manually remove the available sink device
+ sink_info* s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX));
+ // Up until now the most rebust method to test this is to manually remove the available sink device
// kernel module and then reload (rmmod & modprobe).
// TODO: Edge case of dynamic loading and unloading of sinks should be handled also.
g_debug("About to test for to see if the available sink is null - s->name = %s", s->name);
gboolean available = g_ascii_strncasecmp("auto_null", s->name, 9) != 0;
- g_debug("sink_available: %i", available);
+ g_debug("PA_Manager -> determine_sink_availability: %i", available);
return available;
}
@@ -289,11 +296,8 @@ static void pulse_sink_info_callback(pa_context *c, const pa_sink_info *sink, in
g_debug("About to add an item to our hash");
sink_info *value;
value = g_new0(sink_info, 1);
- value->index = value->device_index = sink->index;
+ value->index = sink->index;
value->name = g_strdup(sink->name);
- value->description = g_strdup(sink->description);
- value->icon_name = g_strdup(pa_proplist_gets(sink->proplist, PA_PROP_DEVICE_ICON_NAME));
- value->active_port = (sink->active_port != NULL);
value->mute = !!sink->mute;
value->volume = sink->volume;
value->base_volume = sink->base_volume;
@@ -355,22 +359,23 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v
g_warning("Sink INPUT info callback failure");
return;
}
-
+ gint position = -1;
GList *keys = g_hash_table_get_keys(sink_hash);
- gint position = g_list_index(keys, GINT_TO_POINTER(info->index));
+
+ if(info == NULL)
+ return;
+
+ position = g_list_index(keys, GINT_TO_POINTER(info->index));
+
if(position >= 0) // => index is within the keys of the hash.
{
sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(info->index));
s->name = g_strdup(info->name);
- s->description = g_strdup(info->description);
- s->icon_name = g_strdup(pa_proplist_gets(info->proplist, PA_PROP_DEVICE_ICON_NAME));
- s->active_port = (info->active_port != NULL);
gboolean mute_changed = s->mute != !!info->mute;
s->mute = !!info->mute;
gboolean volume_changed = (pa_cvolume_equal(&info->volume, &s->volume) == 0);
s->volume = info->volume;
s->base_volume = info->base_volume;
- s->channel_map = info->channel_map;
if(DEFAULT_SINK_INDEX == s->index)
{
//update the UI
@@ -398,18 +403,13 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v
}
else
{
-
sink_info *value;
value = g_new0(sink_info, 1);
- value->index = value->device_index = info->index;
+ value->index = info->index;
value->name = g_strdup(info->name);
- value->description = g_strdup(info->description);
- value->icon_name = g_strdup(pa_proplist_gets(info->proplist, PA_PROP_DEVICE_ICON_NAME));
- value->active_port = (info->active_port != NULL);
value->mute = !!info->mute;
value->volume = info->volume;
value->base_volume = info->base_volume;
- value->channel_map = info->channel_map;
g_hash_table_insert(sink_hash, GINT_TO_POINTER(value->index), value);
g_debug("pulse-manager:update_sink_info -> After adding a new sink to our hash");
sound_service_dbus_update_sink_availability(dbus_service, TRUE);
@@ -459,15 +459,24 @@ static void subscribed_events_callback(pa_context *c, enum pa_subscription_event
switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK)
{
case PA_SUBSCRIPTION_EVENT_SINK:
- g_debug("PA_SUBSCRIPTION_EVENT_SINK event triggered");
if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE)
{
if(index == DEFAULT_SINK_INDEX)
- g_debug("PA_SUBSCRIPTION_EVENT_SINK REMOVAL event triggered");
sound_service_dbus_update_sink_availability(dbus_service, FALSE);
+
+ g_debug(" - removing sink of index %i from our sink hash - keep the cache tidy !", index);
+ g_hash_table_remove(sink_hash, GINT_TO_POINTER(index));
+
+ if(index == DEFAULT_SINK_INDEX){
+ g_debug("PA_SUBSCRIPTION_EVENT_SINK REMOVAL: default sink %i has been removed.", DEFAULT_SINK_INDEX);
+ DEFAULT_SINK_INDEX = -1;
+ determine_sink_availability();
+ }
+ g_debug(" - Now what is our default sink : %i", DEFAULT_SINK_INDEX);
}
else
{
+ g_debug("PA_SUBSCRIPTION_EVENT_SINK: a generic sink event - will trigger an update");
pa_operation_unref(pa_context_get_sink_info_by_index(c, index, update_sink_info, userdata));
}
break;
@@ -475,7 +484,7 @@ static void subscribed_events_callback(pa_context *c, enum pa_subscription_event
g_debug("PA_SUBSCRIPTION_EVENT_SINK_INPUT event triggered!!");
if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE)
{
- //handle the remove event - not relevant for current design
+ //handle the sink input remove event - not relevant for current design
}
else
{
diff --git a/src/pulse-manager.h b/src/pulse-manager.h
index e1777fb..54978bb 100644
--- a/src/pulse-manager.h
+++ b/src/pulse-manager.h
@@ -30,14 +30,10 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
typedef struct {
gchar* name;
- gchar* description;
- gchar* icon_name;
gint index;
- gint device_index;
pa_cvolume volume;
pa_channel_map channel_map;
gboolean mute;
- gboolean active_port;
pa_volume_t base_volume;
} sink_info;
diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c
index a14f4f9..cb72524 100644
--- a/src/slider-menu-item.c
+++ b/src/slider-menu-item.c
@@ -77,12 +77,14 @@ slider_menu_item_finalize (GObject *object)
}
-
static void
handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp)
{
g_debug("in the handle event method of slider_menu_item");
- set_sink_volume((gdouble)g_value_get_double(value));
+ gdouble volume_input = 0;
+ volume_input = g_value_get_double(value);
+ if(value != NULL)
+ set_sink_volume(volume_input);
}
diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c
index 260e064..5c6c487 100644
--- a/src/sound-service-dbus.c
+++ b/src/sound-service-dbus.c
@@ -140,7 +140,7 @@ sound_service_dbus_init (SoundServiceDbus *self)
}
/* register the service on it */
dbus_g_connection_register_g_object(priv->connection,
- "/org/ayatana/indicator/sound/service",
+ INDICATOR_SOUND_SERVICE_DBUS_OBJECT,
G_OBJECT(self));
}
diff --git a/src/sound-service.c b/src/sound-service.c
index 403b2b0..d70971e 100644
--- a/src/sound-service.c
+++ b/src/sound-service.c
@@ -44,7 +44,7 @@ service_shutdown (IndicatorService *service, gpointer user_data)
if (mainloop != NULL) {
g_debug("Service shutdown !");
// TODO: uncomment for release !!
- close_pulse_activites();
+ close_pulse_activites();
g_main_loop_quit(mainloop);
}
return;