aboutsummaryrefslogtreecommitdiff
path: root/src/indicator-sound.c
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2011-01-23 17:01:01 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2011-01-23 17:01:01 +0100
commit463c714aac4835bcdfda3c523122c13fac1586f3 (patch)
tree29625a5390e577787b8f8f48e7cd0453f023428f /src/indicator-sound.c
parent411333bed0e020e1725e3dd48afdc57e41fd1b93 (diff)
downloadayatana-indicator-sound-463c714aac4835bcdfda3c523122c13fac1586f3.tar.gz
ayatana-indicator-sound-463c714aac4835bcdfda3c523122c13fac1586f3.tar.bz2
ayatana-indicator-sound-463c714aac4835bcdfda3c523122c13fac1586f3.zip
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.
Diffstat (limited to 'src/indicator-sound.c')
-rw-r--r--src/indicator-sound.c81
1 files changed, 79 insertions, 2 deletions
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 <http://www.gnu.org/licenses/>.
#include <gio/gio.h>
+#include <libnotify/notify.h>
+
#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,
@@ -951,6 +991,41 @@ style_changed_cb(GtkWidget *widget, gpointer user_data)
}
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)
{
//g_debug("indicator-sound-scroll - current slider value");
@@ -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);
}