diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 20 | ||||
-rw-r--r-- | src/common-defs.h | 1 | ||||
-rw-r--r-- | src/dbus-menu-manager.c | 22 | ||||
-rw-r--r-- | src/indicator-sound.c | 440 | ||||
-rw-r--r-- | src/pulse-manager.c | 17 | ||||
-rw-r--r-- | src/slider-menu-item.c | 1 | ||||
-rw-r--r-- | src/sound-service-dbus.c | 52 | ||||
-rw-r--r-- | src/sound-service-dbus.h | 5 | ||||
-rw-r--r-- | src/sound-service.c | 7 | ||||
-rw-r--r-- | src/sound-service.xml | 10 |
10 files changed, 382 insertions, 193 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 8ddcff5..d9fd14c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,9 +11,7 @@ libsoundmenu_la_SOURCES = \ indicator-sound.h \ indicator-sound.c \ dbus-shared-names.h \ - sound-service-client.h \ - sound-service-marshal.c \ - sound-service-marshal.h + sound-service-client.h libsoundmenu_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Werror libsoundmenu_la_LIBADD = $(APPLET_LIBS) @@ -30,16 +28,6 @@ sound-service-client.h: $(srcdir)/sound-service.xml --output=sound-service-client.h \ $(srcdir)/sound-service.xml -sound-service-marshal.h: $(srcdir)/sound-service.list - glib-genmarshal --header \ - --prefix=_sound_service_marshal $(srcdir)/sound-service.list \ - > sound-service-marshal.h - -sound-service-marshal.c: $(srcdir)/sound-service.list - glib-genmarshal --body \ - --prefix=_sound_service_marshal $(srcdir)/sound-service.list \ - > sound-service-marshal.c - ################# # Session Stuff @@ -55,8 +43,6 @@ indicator_sound_service_SOURCES = \ sound-service-dbus.h \ sound-service-dbus.c \ sound-service-server.h \ - sound-service-marshal.c \ - sound-service-marshal.h \ slider-menu-item.h \ slider-menu-item.c indicator_sound_service_CFLAGS = $(PULSEAUDIO_CFLAGS) $(SOUNDSERVICE_CFLAGS) $(GCONF_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" -Wall -Werror @@ -74,9 +60,7 @@ sound-service-server.h: $(srcdir)/sound-service.xml ############### BUILT_SOURCES = \ sound-service-client.h \ - sound-service-server.h \ - sound-service-marshal.h \ - sound-service-marshal.c + sound-service-server.h EXTRA_DIST = \ sound-service.xml \ diff --git a/src/common-defs.h b/src/common-defs.h index 942e269..9be1da5 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -22,6 +22,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #define SIGNAL_SINK_INPUT_WHILE_MUTED "SinkInputWhileMuted" #define SIGNAL_SINK_VOLUME_UPDATE "SinkVolumeUpdate" #define SIGNAL_SINK_MUTE_UPDATE "SinkMuteUpdate" +#define SIGNAL_SINK_AVAILABLE_UPDATE "SinkAvailableUpdate" // DBUS items #define DBUSMENU_SLIDER_MENUITEM_TYPE "x-canonical-ido-slider-item" diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index 652e6b2..1628a59 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -18,6 +18,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <unistd.h> +#include <glib/gi18n.h> + #include <dbus/dbus-glib.h> #include <dbus/dbus-glib-bindings.h> @@ -98,6 +101,8 @@ void dbus_menu_manager_update_pa_state(gboolean pa_state, gboolean sink_availabl refresh_menu(); } // Emit the signals after the menus are setup/torn down + // preserve ordering ! + sound_service_dbus_update_sink_availability(dbus_interface, sink_available); sound_service_dbus_update_sink_volume(dbus_interface, percent); sound_service_dbus_update_sink_mute(dbus_interface, sink_muted); dbus_menu_manager_update_mute_ui(b_all_muted); @@ -112,8 +117,7 @@ void dbus_menu_manager_update_mute_ui(gboolean incoming_mute_value) b_all_muted = incoming_mute_value; dbusmenu_menuitem_property_set(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, - (b_all_muted == FALSE ? "Mute All" : "Unmute")); - //dbusmenu_menuitem_property_set(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, (b_all_muted == FALSE ? _("Mute All") : _("Unmute"))); + b_all_muted == FALSE ? _("Mute All") : _("Unmute")); } @@ -155,7 +159,8 @@ static void refresh_menu() /** - +idle_routine: +Something for glip mainloop to do when idle **/ static gboolean idle_routine (gpointer data) { @@ -186,7 +191,7 @@ static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service { // Mute button mute_all_menuitem = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, (b_all_muted == FALSE ? "Mute All" : "Unmute")); + dbusmenu_menuitem_property_set(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, b_all_muted == FALSE ? _("Mute All") : _("Unmute")); g_signal_connect(G_OBJECT(mute_all_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(set_global_mute_from_ui), NULL); dbusmenu_menuitem_property_set_bool(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, b_sink_available); @@ -196,7 +201,8 @@ static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service dbusmenu_menuitem_child_append(root, DBUSMENU_MENUITEM(volume_slider_menuitem)); dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem), DBUSMENU_MENUITEM_PROP_ENABLED, - b_sink_available); + b_sink_available && !b_all_muted); + g_debug("!!!!!!**in the rebuild sound menu - slider active = %i", b_sink_available && !b_all_muted); dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem), DBUSMENU_MENUITEM_PROP_VISIBLE, b_sink_available); @@ -207,8 +213,8 @@ static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service // Sound preferences dialog DbusmenuMenuitem *settings_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(settings_mi, DBUSMENU_MENUITEM_PROP_LABEL, - ("Sound Preferences...")); + dbusmenu_menuitem_property_set(settings_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Sound Preferences...")); +//_("Sound Preferences...")); dbusmenu_menuitem_child_append(root, settings_mi); g_signal_connect(G_OBJECT(settings_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_sound_settings_dialog), NULL); @@ -224,7 +230,7 @@ static void set_global_mute_from_ui() toggle_global_mute(b_all_muted); dbusmenu_menuitem_property_set(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, - (b_all_muted == FALSE ? "Mute All" : "Unmute")); + b_all_muted == FALSE ? _("Mute All") : _("Unmute")); } diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 3aca517..3bb5416 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -5,19 +5,20 @@ into the gnome-panel using it's applet interface. Copyright 2010 Canonical Ltd. Authors: - Conor Curran <conor.curra@canonical.com> + Conor Curran <conor.curran@canonical.com> Ted Gould <ted@canonical.com> + Cody Russell <cody.russell@canonical.com> -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published by the Free Software Foundation. -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along +You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <math.h> @@ -34,12 +35,12 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <libindicator/indicator.h> #include <libindicator/indicator-object.h> #include <libindicator/indicator-service-manager.h> +#include <libindicator/indicator-image-helper.h> #include "indicator-sound.h" #include "dbus-shared-names.h" #include "sound-service-client.h" #include "common-defs.h" -#include "sound-service-marshal.h" // GObject Boiler plate #define INDICATOR_SOUND_TYPE (indicator_sound_get_type ()) @@ -60,6 +61,7 @@ struct _IndicatorSoundClass { //GObject instance struct struct _IndicatorSound { IndicatorObject parent; + GtkWidget *slider; IndicatorServiceManager *service; }; // GObject Boiler plate @@ -77,24 +79,29 @@ G_DEFINE_TYPE (IndicatorSound, indicator_sound, INDICATOR_OBJECT_TYPE); //GTK+ items static GtkLabel * get_label (IndicatorObject * io); static GtkImage * get_icon (IndicatorObject * io); -static GtkMenu * get_menu (IndicatorObject * io); +static GtkMenu * get_menu (IndicatorObject * io); +static void scroll (IndicatorObject*io, gint delta, IndicatorScrollDirection direction); + //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); -// Alternative callback mechanism, may use this again once ido is updated. -/*static gboolean user_change_value_event_cb(GtkRange *range, GtkScrollType scroll_type, gdouble input_value, gpointer user_data);*/ +/*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); // DBUS communication static DBusGProxy *sound_dbus_proxy = NULL; static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata); -/*static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean value, gpointer userdata);*/ -static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_percent, gpointer userdata); +static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean value, gpointer userdata); +static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_percent, gpointer userdata); static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer userdata); +static void catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean available_value, gpointer userdata); static void fetch_volume_percent_from_dbus(); static void fetch_mute_value_from_dbus(); +static void fetch_sink_availability_from_dbus(); /****Volume States 'members' ***/ static void update_state(const gint state); @@ -109,11 +116,20 @@ static const gint STATE_SINKS_NONE = 6; static GHashTable *volume_states = NULL; static GtkImage *speaker_image = NULL; -static GtkWidget* primary_image = NULL; static gint current_state = 0; static gint previous_state = 0; + static gdouble initial_volume_percent = 0; -static gboolean initial_mute = FALSE; +static gboolean initial_mute ; +static gboolean device_available; +static gboolean slider_in_direct_use; + +static GtkIconSize design_team_size; +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(); // Construction static void @@ -127,24 +143,26 @@ indicator_sound_class_init (IndicatorSoundClass *klass) IndicatorObjectClass *io_class = INDICATOR_OBJECT_CLASS(klass); io_class->get_label = get_label; io_class->get_image = get_icon; - io_class->get_menu = get_menu; + io_class->get_menu = get_menu; + io_class->scroll = scroll; + + design_team_size = gtk_icon_size_register("design-team-size", 22, 22); -/* dbus_g_object_register_marshaller (_sound_service_marshal_VOID__INT_BOOLEAN,*/ -/* G_TYPE_NONE,*/ -/* G_TYPE_INT,*/ -/* G_TYPE_BOOLEAN,*/ -/* G_TYPE_INVALID);*/ return; } static void indicator_sound_init (IndicatorSound *self) { - /* Set good defaults */ self->service = NULL; - /* 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_blocked_animation(); + animation_id = 0; + initial_mute = FALSE; + device_available = TRUE; + slider_in_direct_use = FALSE; + + g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self); return; } @@ -158,6 +176,12 @@ indicator_sound_dispose (GObject *object) self->service = NULL; } g_hash_table_destroy(volume_states); + + if(blocked_animation_list != NULL){ + g_list_foreach (blocked_animation_list, (GFunc)g_object_unref, NULL); + g_list_free(blocked_animation_list); + } + G_OBJECT_CLASS (indicator_sound_parent_class)->dispose (object); return; } @@ -179,8 +203,8 @@ static GtkImage * get_icon (IndicatorObject * io) { gchar* current_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); - //g_debug("At start-up attempting to set the image to %s", current_name); - speaker_image = GTK_IMAGE(gtk_image_new_from_icon_name(current_name, GTK_ICON_SIZE_MENU)); + g_debug("At start-up attempting to set the image to %s", current_name); + speaker_image = indicator_image_helper(current_name); gtk_widget_show(GTK_WIDGET(speaker_image)); return speaker_image; } @@ -191,53 +215,82 @@ get_icon (IndicatorObject * io) static GtkMenu * get_menu (IndicatorObject * io) { - DbusmenuGtkMenu *menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT); - DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu); + DbusmenuGtkMenu *menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT); + DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu); + + g_object_set_data (G_OBJECT (client), + "indicator", io); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SLIDER_MENUITEM_TYPE, new_slider_item); // register Key-press listening on the menu widget as the slider does not allow this. - g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), NULL); - + g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), NULL); return GTK_MENU(menu); } +static void +slider_parent_changed (GtkWidget *widget, + gpointer user_data) +{ + gtk_widget_set_size_request (widget, 200, -1); + g_debug("slider parent changed"); + //fetch_volume_percent_from_dbus(); +} + /** new_slider_item: Create a new dBusMenu Slider item. **/ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { - g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); - g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); - + IndicatorObject *io = NULL; + + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); + g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + + io = g_object_get_data (G_OBJECT (client), "indicator"); + volume_slider = ido_scale_menu_item_new_with_range ("Volume", initial_volume_percent, 0, 100, 0.5); - g_object_set(volume_slider, "reverse-scroll-events", TRUE, NULL); + g_object_set(volume_slider, "reverse-scroll-events", TRUE, NULL); + + g_signal_connect (volume_slider, + "notify::parent", G_CALLBACK (slider_parent_changed), + NULL); GtkMenuItem *menu_volume_slider = GTK_MENU_ITEM(volume_slider); - dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_volume_slider, parent); - g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(slider_prop_change_cb), volume_slider); - + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_volume_slider, parent); + // register slider changes listening on the range - GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); - g_signal_connect(slider, "value-changed", G_CALLBACK(value_changed_event_cb), newitem); - // alternative callback mechanism which i could use again at some point. -/* g_signal_connect(slider, "change-value", G_CALLBACK(user_change_value_event_cb), newitem); */ - + GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); + + INDICATOR_SOUND (io)->slider = slider; + + 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 - primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider); - gtk_image_set_from_icon_name(GTK_IMAGE(primary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO)), GTK_ICON_SIZE_MENU); - GtkWidget* secondary_image = ido_scale_menu_item_get_secondary_image((IdoScaleMenuItem*)volume_slider); - gtk_image_set_from_icon_name(GTK_IMAGE(secondary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_HIGH)), GTK_ICON_SIZE_MENU); + GtkWidget* primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider); + GIcon * primary_gicon = g_themed_icon_new_with_default_fallbacks(g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO))); + gtk_image_set_from_gicon(GTK_IMAGE(primary_image), primary_gicon, GTK_ICON_SIZE_MENU); + g_object_unref(primary_gicon); + + GtkWidget* secondary_image = ido_scale_menu_item_get_secondary_image((IdoScaleMenuItem*)volume_slider); + GIcon * secondary_gicon = g_themed_icon_new_with_default_fallbacks(g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_HIGH))); + gtk_image_set_from_gicon(GTK_IMAGE(secondary_image), secondary_gicon, GTK_ICON_SIZE_MENU); + g_object_unref(secondary_gicon); + gtk_widget_set_sensitive(volume_slider, !initial_mute); gtk_widget_show_all(volume_slider); - return TRUE; + return TRUE; } static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata) { + // TODO: This could be safer. if (connected) { if (sound_dbus_proxy == NULL) { GError * error = NULL; @@ -257,16 +310,19 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u g_debug("about to connect to the signals"); dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_TYPE_BOOLEAN, G_TYPE_INVALID); -/* 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_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); + dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_CALLBACK(catch_signal_sink_availability_update), NULL, NULL); // Ensure we are in a coherent state with the service at start up. // Preserve ordering! fetch_volume_percent_from_dbus(); fetch_mute_value_from_dbus(); + fetch_sink_availability_from_dbus(); } } else { @@ -276,15 +332,11 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u return; } - - - /* Prepare states Array. */ void prepare_state_machine() { - // TODO we need three more images 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-panel")); g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), g_strdup("audio-volume-low-zero-panel")); @@ -295,6 +347,41 @@ void prepare_state_machine() g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), g_strdup("audio-output-none-panel")); } +/* +prepare_blocked_animation: +Prepares the array of images to be used in the blocked animation. +Only called at startup. +*/ +static void prepare_blocked_animation() +{ + gchar* blocked_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)); + gchar* muted_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED)); + + GtkImage* temp_image = indicator_image_helper(muted_name); + GdkPixbuf* mute_buf = gtk_image_get_pixbuf(temp_image); + + temp_image = indicator_image_helper(blocked_name); + GdkPixbuf* blocked_buf = gtk_image_get_pixbuf(temp_image); + + int i; + + if(mute_buf == NULL || blocked_buf == NULL){ + g_debug("Don bother with the animation, the theme aint got the goods"); + return; + } + + // sample 22 snapshots - range : 0-256 + for(i = 0; i < 23; 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)); + blocked_animation_list = g_list_append(blocked_animation_list, gdk_pixbuf_copy(blocked_buf)); + } +} + + gint get_state() { return current_state; @@ -326,14 +413,15 @@ static void update_state(const gint state) current_state = state; gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); - gtk_image_set_from_icon_name(speaker_image, image_name, GTK_ICON_SIZE_MENU); + indicator_image_helper_update(speaker_image, image_name); } void determine_state_from_volume(gdouble volume_percent) { /* g_debug("determine_state_from_volume - previous_state = %i", previous_state);*/ - + if (device_available == FALSE) + return; gint state = previous_state; if (volume_percent < 30.0 && volume_percent > 0){ state = STATE_LOW; @@ -346,16 +434,38 @@ void determine_state_from_volume(gdouble volume_percent) } else if(volume_percent == 0.0){ state = STATE_ZERO; - } - update_state(state); + } + update_state(state); } - +static void fetch_sink_availability_from_dbus() +{ + GError * error = NULL; + gboolean * available_input; + available_input = g_new0(gboolean, 1); + org_ayatana_indicator_sound_get_sink_availability(sound_dbus_proxy, available_input, &error); + if (error != NULL) { + g_warning("Unable to fetch AVAILABILITY at indicator start up: %s", error->message); + g_error_free(error); + g_free(available_input); + return; + } + device_available = *available_input; + if (device_available == FALSE) + update_state(STATE_SINKS_NONE); + g_debug("NO DEVICE AVAILABLE"); + + gtk_widget_set_sensitive(volume_slider, device_available); + g_free(available_input); + g_debug("IndicatorSound::fetch_sink_availability_from_dbus -> AVAILABILTY returned from dbus method is %i", device_available); + +} + static void fetch_volume_percent_from_dbus() { GError * error = NULL; - gdouble *volume_percent_input; + 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) { @@ -373,7 +483,7 @@ static void fetch_volume_percent_from_dbus() static void fetch_mute_value_from_dbus() { GError * error = NULL; - gboolean *mute_input; + gboolean *mute_input; mute_input = g_new0(gboolean, 1); org_ayatana_indicator_sound_get_sink_mute(sound_dbus_proxy, mute_input, &error); if (error != NULL) { @@ -389,67 +499,111 @@ static void fetch_mute_value_from_dbus() g_debug("at the indicator start up and the MUTE returned from dbus method is %i", initial_mute); } -/*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);*/ -/*}*/ +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) { + 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); + } +} + +static gboolean fade_back_to_mute_image() +{ + if(blocked_iter != NULL) + { + g_debug("in animation 'loop'\n"); + gtk_image_set_from_pixbuf(speaker_image, blocked_iter->data); + blocked_iter = blocked_iter->next; + return TRUE; + } + else{ + animation_id = 0; + g_debug("exit from animation\n"); + return FALSE; + } +} static void catch_signal_sink_volume_update(DBusGProxy *proxy, gdouble volume_percent, gpointer userdata) { - GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); - GtkRange *range = (GtkRange*)slider; - - // DEBUG - gdouble current_value = gtk_range_get_value(range); - g_debug("SIGNAL- update sink volume - current_value : %f and new value : %f", current_value, volume_percent); - gtk_range_set_value(range, volume_percent); - determine_state_from_volume(volume_percent); + if (slider_in_direct_use == FALSE){ + GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); + GtkRange *range = (GtkRange*)slider; + + // DEBUG + gdouble current_value = gtk_range_get_value(range); + g_debug("SIGNAL- update sink volume - current_value : %f and new value : %f", current_value, volume_percent); + gtk_range_set_value(range, volume_percent); + determine_state_from_volume(volume_percent); + } } static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer userdata) { //We can be sure the service won't send a mute signal unless it has changed ! //UNMUTE's force a volume update therefore icon is updated appropriately => no need for unmute handling here. - if(mute_value == TRUE) + if(mute_value == TRUE && device_available == TRUE) { update_state(STATE_MUTED); } + else{ + if(animation_id != 0){ + g_debug("about to remove the animation_id callback from the mainloop!!**"); + g_source_remove(animation_id); + animation_id = 0; + } + } g_debug("signal caught - sink mute update with mute value: %i", mute_value); gtk_widget_set_sensitive(volume_slider, !mute_value); } -/** -slider_prop_change_cb: -Whenever we have a property change on a DbusmenuMenuitem this will be called. -**/ -static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget) + +static void catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean available_value, gpointer userdata) { - 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; - gtk_range_set_value(range, g_value_get_double(value)); - return; + device_available = available_value; + if (device_available == FALSE){ + update_state(STATE_SINKS_NONE); + } + g_debug("signal caught - sink availability update with value: %i", available_value); } + /** value_changed_event_cb: This callback will get triggered irregardless of whether its a user change or a programmatic change. **/ static gboolean value_changed_event_cb(GtkRange *range, gpointer user_data) { - gdouble current_value = CLAMP(gtk_range_get_value(range), 0, 100); + gdouble current_value = CLAMP(gtk_range_get_value(range), 0, 100); DbusmenuMenuitem *item = (DbusmenuMenuitem*)user_data; GValue value = {0}; g_value_init(&value, G_TYPE_DOUBLE); g_value_set_double(&value, current_value); g_debug("Value changed callback - = %f", current_value); - dbusmenu_menuitem_handle_event (item, "slider_change", &value, 0); + dbusmenu_menuitem_handle_event (item, "slider_change", &value, 0); // This is not ideal in that the icon ui will update on ui actions and not on actual service feedback. // but necessary for now as the server does not send volume update information if the source of change was this ui. determine_state_from_volume(current_value); return FALSE; } + +static void slider_grabbed (GtkWidget *widget, gpointer user_data) +{ + slider_in_direct_use = TRUE; + g_debug ("!!!!!! grabbed\n"); +} + +static void slider_released (GtkWidget *widget, gpointer user_data) +{ + slider_in_direct_use = FALSE; + g_debug ("!!!!!! released\n"); +} + + + /** key_press_cb: **/ @@ -458,72 +612,74 @@ static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer dat gboolean digested = FALSE; GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); - GtkRange* range = (GtkRange*)slider; - gdouble current_value = gtk_range_get_value(range); + GtkRange* range = (GtkRange*)slider; + gdouble current_value = gtk_range_get_value(range); gdouble new_value = current_value; const gdouble five_percent = 5; + GtkWidget *menuitem; - switch(event->keyval) - { - case GDK_Right: - digested = TRUE; - if(event->state & GDK_CONTROL_MASK) - { - new_value = 100; - } - else + menuitem = GTK_MENU_SHELL (widget)->active_menu_item; + if(IDO_IS_SCALE_MENU_ITEM(menuitem) == TRUE) + { + switch(event->keyval) { + case GDK_Right: + digested = TRUE; + if(event->state & GDK_CONTROL_MASK) + { + new_value = 100; + } + else + { + new_value = current_value + five_percent; + } + break; + case GDK_Left: + digested = TRUE; + if(event->state & GDK_CONTROL_MASK) + { + new_value = 0; + } + else + { + new_value = current_value - five_percent; + } + break; + case GDK_plus: + digested = TRUE; new_value = current_value + five_percent; + break; + case GDK_minus: + digested = TRUE; + new_value = current_value - five_percent; + break; + default: + break; } - break; - case GDK_Left: - digested = TRUE; - if(event->state & GDK_CONTROL_MASK) - { - new_value = 0; - } - else + + new_value = CLAMP(new_value, 0, 100); + if(new_value != current_value && current_state != STATE_MUTED) { - new_value = current_value - five_percent; + g_debug("Attempting to set the range from the key listener to %f", new_value); + gtk_range_set_value(range, new_value); } - break; - case GDK_plus: - digested = TRUE; - new_value = current_value + five_percent; - break; - case GDK_minus: - digested = TRUE; - new_value = current_value - five_percent; - break; - default: - break; - } - - new_value = CLAMP(new_value, 0, 100); - if(new_value != current_value && current_state != STATE_MUTED) - { - g_debug("Attempting to set the range from the key listener to %f", new_value); - gtk_range_set_value(range, new_value); - } + } return digested; } -/** -This callback should only be called when the user actually drags the slider. -Turned off for now in favour of the non descriminating value-changed call back. -Once the grabbing listener is implemented on the slider may revert to using this. -Its another tool for filtering unwanted volume change updates. -**/ -/*static gboolean user_change_value_event_cb(GtkRange *range, GtkScrollType scroll_type, gdouble input_value, gpointer user_data)*/ -/*{*/ -/* DbusmenuMenuitem *item = (DbusmenuMenuitem*)user_data;*/ -/* gdouble clamped_input = CLAMP(input_value, 0, 100);*/ -/* GValue value = {0};*/ -/* 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);*/ -/* return FALSE; */ -/*} */ +static void +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)); + + if (direction == INDICATOR_OBJECT_SCROLL_UP) + value += adj->step_increment; + else + value -= adj->step_increment; + gtk_range_set_value (GTK_RANGE (sound->slider), + value); +} diff --git a/src/pulse-manager.c b/src/pulse-manager.c index 04f842a..2f86a90 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -67,9 +67,8 @@ void establish_pulse_activities(SoundServiceDbus *service) // Establish event callback registration pa_context_set_state_callback(pulse_context, context_state_callback, NULL); - // BUILD MENU ANYWHO - it will be updated - dbus_menu_manager_update_pa_state(FALSE, FALSE, FALSE, 0); - + // 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); pa_context_connect(pulse_context, NULL, PA_CONTEXT_NOFAIL, NULL); } @@ -283,7 +282,7 @@ static void pulse_sink_info_callback(pa_context *c, const pa_sink_info *sink, in else{ //Update the indicator to show PA either is not ready or has no available sink g_warning("Cannot find a suitable default sink ..."); - dbus_menu_manager_update_pa_state(FALSE, device_available, TRUE, 0); + dbus_menu_manager_update_pa_state(FALSE, device_available, default_sink_is_muted(), get_default_sink_volume()); } } else{ @@ -399,6 +398,7 @@ 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; @@ -412,7 +412,8 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v 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); + } } @@ -461,7 +462,9 @@ static void subscribed_events_callback(pa_context *c, enum pa_subscription_event g_debug("PA_SUBSCRIPTION_EVENT_SINK event triggered"); if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { - //TODO handle the remove event => if its our default sink - update date pa state + if(index == DEFAULT_SINK_INDEX) + g_debug("PA_SUBSCRIPTION_EVENT_SINK REMOVAL event triggered - default sink has been removed !!"); + sound_service_dbus_update_sink_availability(dbus_service, FALSE); } else { @@ -472,7 +475,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) { - //TODO handle the remove event + //handle the remove event - not relevant for current design } else { diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c index ef3b1fa..a14f4f9 100644 --- a/src/slider-menu-item.c +++ b/src/slider-menu-item.c @@ -92,6 +92,7 @@ SliderMenuItem* slider_menu_item_new(gboolean sinks_available, gdouble start_vol SliderMenuItem *self = g_object_new(SLIDER_MENU_ITEM_TYPE, NULL); dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_SLIDER_MENUITEM_TYPE); dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_ENABLED, sinks_available); + dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_VISIBLE, sinks_available); return self; } diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 99a9d34..260e064 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -26,13 +26,12 @@ #include "dbus-shared-names.h" #include "sound-service-dbus.h" #include "common-defs.h" -#include "sound-service-marshal.h" #include "pulse-manager.h" -// DBUS methods - -// TODO - other should be static and moved from the header to here +// DBUS methods static gboolean sound_service_dbus_get_sink_volume(SoundServiceDbus* service, gdouble* volume_percent_input, GError** gerror); static gboolean sound_service_dbus_get_sink_mute(SoundServiceDbus* service, gboolean* mute_input, GError** gerror); +static gboolean sound_service_dbus_get_sink_availability(SoundServiceDbus* service, gboolean* availability_input, GError** gerror); static void sound_service_dbus_set_sink_volume(SoundServiceDbus* service, const guint volume_percent, GError** gerror); #include "sound-service-server.h" @@ -41,18 +40,19 @@ typedef struct _SoundServiceDbusPrivate SoundServiceDbusPrivate; struct _SoundServiceDbusPrivate { - DBusGConnection *system_bus; DBusGConnection *connection; gdouble volume_percent; gboolean mute; + gboolean sink_availability; }; /* Signals */ enum { - SINK_INPUT_WHILE_MUTED, + SINK_INPUT_WHILE_MUTED, SINK_VOLUME_UPDATE, SINK_MUTE_UPDATE, + SINK_AVAILABLE_UPDATE, LAST_SIGNAL }; @@ -107,6 +107,15 @@ sound_service_dbus_class_init (SoundServiceDbusClass *klass) NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + signals[SINK_AVAILABLE_UPDATE] = g_signal_new("sink-available-update", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + + } @@ -116,25 +125,23 @@ sound_service_dbus_init (SoundServiceDbus *self) GError *error = NULL; SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self); - priv->system_bus = NULL; priv->connection = NULL; priv->volume_percent = 0; + priv->mute = FALSE; + priv->sink_availability = FALSE; - /* Get the system bus */ - priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); - /* Put the object on DBus */ + /* Fetch the session bus */ priv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if (error != NULL) { - g_error("Unable to connect to the session bus when creating application indicator: %s", error->message); + g_error("sound-service-dbus:Unable to connect to the session bus when creating indicator sound service : %s", error->message); g_error_free(error); return; } + /* register the service on it */ dbus_g_connection_register_g_object(priv->connection, "/org/ayatana/indicator/sound/service", G_OBJECT(self)); - - return; } @@ -178,6 +185,14 @@ static gboolean sound_service_dbus_get_sink_mute (SoundServiceDbus *self, gboole return TRUE; } +static gboolean sound_service_dbus_get_sink_availability (SoundServiceDbus *self, gboolean *availability_input, GError** gerror) +{ + SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); + g_debug("Get sink availability - sound service dbus!, about to send over availability_value of %i", priv->sink_availability); + *availability_input = priv->sink_availability; + return TRUE; +} + /** SIGNALS Utility methods to emit signals from the service into the ether. @@ -216,5 +231,18 @@ void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mu priv->mute); } +void sound_service_dbus_update_sink_availability(SoundServiceDbus* obj, gboolean sink_availability) +{ + g_debug("Emitting signal: SINK_AVAILABILITY_UPDATE, with value %i", sink_availability); + + SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (obj); + priv->sink_availability = sink_availability; + + g_signal_emit(obj, + signals[SINK_AVAILABLE_UPDATE], + 0, + priv->sink_availability); +} + diff --git a/src/sound-service-dbus.h b/src/sound-service-dbus.h index ef0d7dd..ae4953e 100644 --- a/src/sound-service-dbus.h +++ b/src/sound-service-dbus.h @@ -49,10 +49,6 @@ struct _SoundServiceDbus { struct _SoundServiceDbusClass { GObjectClass parent_class; - /* Signals -> outward messages to the DBUS and beyond*/ - // TODO - ARE THESE NECESSARY ? - //void (* sink_input_while_muted) (SoundServiceDbus *self, gboolean block_value, gpointer sound_data); - //void (* sink_volume_update) (SoundServiceDbus *self, gdouble sink_volume, gpointer sound_data); }; GType sound_service_dbus_get_type (void) G_GNUC_CONST; @@ -60,6 +56,7 @@ GType sound_service_dbus_get_type (void) G_GNUC_CONST; void sound_service_dbus_sink_input_while_muted (SoundServiceDbus* obj, gboolean block_value); void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume); void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mute); +void sound_service_dbus_update_sink_availability(SoundServiceDbus* obj, gboolean sink_availibity); G_END_DECLS diff --git a/src/sound-service.c b/src/sound-service.c index 815fcdc..403b2b0 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -26,6 +26,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. static GMainLoop *mainloop = NULL; + /**********************************************************************************************************************/ // Init and exit functions /**********************************************************************************************************************/ @@ -35,6 +36,7 @@ service_shutdown: When the service interface starts to shutdown, we should follow it. **/ + void service_shutdown (IndicatorService *service, gpointer user_data) { @@ -42,12 +44,13 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! -/* close_pulse_activites();*/ -/* g_main_loop_quit(mainloop);*/ + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } + /** main: **/ diff --git a/src/sound-service.xml b/src/sound-service.xml index 580f0e1..12ed03e 100644 --- a/src/sound-service.xml +++ b/src/sound-service.xml @@ -5,6 +5,7 @@ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="sound_service_dbus_set_sink_volume"/> <arg type='u' name='volume_percent' direction="in"/> </method> + <method name = "GetSinkVolume"> <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="sound_service_dbus_get_sink_volume"/> <arg type='d' name='volume_percent_input' direction="out"/> @@ -15,6 +16,11 @@ <arg type='b' name='mute_input' direction="out"/> </method> + <method name = "GetSinkAvailability"> + <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="sound_service_dbus_get_sink_availability"/> + <arg type='b' name='availability_input' direction="out"/> + </method> + <!-- Will need to hook up another signal which monitors for volume change Our respective UI element should listen to this and therefore will be updated with accurate setting--> <!-- Triggered when a sink is muted but the input has been sent to that sink --> @@ -30,6 +36,10 @@ Our respective UI element should listen to this and therefore will be updated wi <arg name="mute_value" type="b" direction="out"/> </signal> + <signal name="SinkAvailableUpdate"> + <arg name="available_value" type="b" direction="out"/> + </signal> + </interface> </node> |