From 463c714aac4835bcdfda3c523122c13fac1586f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sun, 23 Jan 2011 17:01:01 +0100 Subject: Show a value notify-osd notification (if supported) when scrolling To improve the indicator usability, show a notify-osd bubble with the volume value when changing the value level using the scrolling-wheel over the indicator icon. --- src/indicator-sound.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/indicator-sound.h | 2 ++ 2 files changed, 81 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index d1bcc33..aa7c43e 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -30,6 +30,8 @@ with this program. If not, see . #include +#include + #include "indicator-sound.h" #include "transport-widget.h" #include "metadata-widget.h" @@ -47,7 +49,8 @@ struct _IndicatorSoundPrivate { GtkWidget* volume_widget; GList* transport_widgets_list; - GDBusProxy *dbus_proxy; + GDBusProxy *dbus_proxy; + NotifyNotification* notification; }; #define INDICATOR_SOUND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_SOUND_TYPE, IndicatorSoundPrivate)) @@ -69,6 +72,10 @@ static GtkImage * get_icon (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); static void indicator_sound_scroll (IndicatorObject* io, gint delta, IndicatorScrollDirection direction); +//Notification +static void indicator_sound_notification_init (IndicatorSound *self); +static void indicator_sound_notification_show (IndicatorSound *self, double value); + //Slider related static gboolean new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data); @@ -183,6 +190,10 @@ indicator_sound_init (IndicatorSound *self) priv->dbus_proxy = NULL; GList* t_list = NULL; priv->transport_widgets_list = t_list; + priv->notification = NULL; + + priv->notification = NULL; + indicator_sound_notification_init (self); g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, @@ -206,6 +217,10 @@ indicator_sound_dispose (GObject *object) g_list_free ( priv->transport_widgets_list ); + if (priv->notification) { + notify_uninit(); + } + G_OBJECT_CLASS (indicator_sound_parent_class)->dispose (object); return; } @@ -349,6 +364,9 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); priv->volume_widget = volume_widget; + if (priv->notification) + notify_notification_attach_to_widget(priv->notification, volume_widget); + GtkWidget* ido_slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); g_signal_connect(ido_slider_widget, "style-set", G_CALLBACK(style_changed_cb), NULL); @@ -366,6 +384,28 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, return TRUE; } +static void indicator_sound_notification_init (IndicatorSound *self) +{ + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); + + if (notify_init(PACKAGE_NAME)) { + GList* caps = notify_get_server_caps(); + gboolean has_notify_osd = FALSE; + + if (caps) { + if (g_list_find_custom(caps, "x-canonical-private-synchronous", (GCompareFunc) g_strcmp0)) { + has_notify_osd = TRUE; + } + g_list_foreach(caps, (GFunc) g_free, NULL); + g_list_free(caps); + } + + if (has_notify_osd) { + priv->notification = notify_notification_new(PACKAGE_NAME, NULL, NULL, NULL); + notify_notification_set_hint_string(priv->notification, "x-canonical-private-synchronous", ""); + } + } +} static void connection_changed (IndicatorServiceManager * sm, @@ -950,6 +990,41 @@ style_changed_cb(GtkWidget *widget, gpointer user_data) prepare_blocked_animation(); } +static void +indicator_sound_notification_show(IndicatorSound *self, double value) +{ + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); + + if (priv->notification == NULL) + return; + + char *icon; + const int notify_value = CLAMP((int)value, -1, 101); + gint state = determine_state_from_volume (CLAMP(value, 0, 100)); + + if (state == STATE_ZERO) { + GtkIconTheme *theme = gtk_icon_theme_get_default(); + if (gtk_icon_theme_has_icon(theme, "audio-volume-off")) { + // Not available in all the themes + icon = "audio-volume-off"; + } else { + icon = "audio-volume-muted"; + } + } else if (state == STATE_LOW) { + icon = "audio-volume-low"; + } else if (state == STATE_MEDIUM) { + icon = "audio-volume-medium"; + } else if (state == STATE_HIGH) { + icon = "audio-volume-high"; + } else { + icon = "audio-volume-muted"; + } + + notify_notification_update(priv->notification, PACKAGE_NAME, NULL, icon); + notify_notification_set_hint_int32(priv->notification, "value", notify_value); + notify_notification_show(priv->notification, NULL); +} + static void indicator_sound_scroll (IndicatorObject *io, gint delta, IndicatorScrollDirection direction) { @@ -973,5 +1048,7 @@ indicator_sound_scroll (IndicatorObject *io, gint delta, IndicatorScrollDirectio value -= adj->step_increment; } //g_debug("indicator-sound-scroll - update slider with value %f", value); - volume_widget_update(VOLUME_WIDGET(priv->volume_widget), value); + volume_widget_update(VOLUME_WIDGET(priv->volume_widget), value); + + indicator_sound_notification_show(INDICATOR_SOUND (io), value); } diff --git a/src/indicator-sound.h b/src/indicator-sound.h index 7bf69b6..276136d 100644 --- a/src/indicator-sound.h +++ b/src/indicator-sound.h @@ -23,6 +23,8 @@ PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include "config.h" + #include #include #include -- cgit v1.2.3