[Xfce4-commits] [panel-plugins/xfce4-pulseaudio-plugin] 01/01: Added OSD notifications

noreply at xfce.org noreply at xfce.org
Sun Apr 19 02:34:09 CEST 2015


This is an automated email from the git hooks/post-receive script.

andrzejr pushed a commit to branch master
in repository panel-plugins/xfce4-pulseaudio-plugin.

commit f4b6b6c752a3c3147a080bd7ff18c330576b6151
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Sun Apr 19 01:34:00 2015 +0100

    Added OSD notifications
    
    Currently hardcoded, can be disabled at compile time.
---
 configure.ac.in                  |    7 ++
 panel-plugin/Makefile.am         |    4 +
 panel-plugin/pulseaudio-button.c |    2 +
 panel-plugin/pulseaudio-notify.c |  217 ++++++++++++++++++++++++++++++++++++++
 panel-plugin/pulseaudio-notify.h |   49 +++++++++
 panel-plugin/pulseaudio-plugin.c |   25 +++++
 panel-plugin/pulseaudio-plugin.h |    2 +
 7 files changed, 306 insertions(+)

diff --git a/configure.ac.in b/configure.ac.in
index 6ace2c4..4740f25 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -90,6 +90,12 @@ dnl **********************************
 XDT_CHECK_OPTIONAL_PACKAGE([KEYBINDER], [keybinder-3.0], [0.2.2], [keybinder],
                            [keybinder Support])
 
+dnl **********************************
+dnl *** Optional libnotify Support ***
+dnl **********************************
+XDT_CHECK_OPTIONAL_PACKAGE([LIBNOTIFY], [libnotify], [0.7.0], [libnotify],
+                           [libnotify library])
+
 AC_CHECK_LIBM
 AC_SUBST(LIBM)
 
@@ -140,5 +146,6 @@ echo "Build Configuration:"
 echo
 echo "* Debug Support:          $enable_debug"
 echo "* Use keybinder:          ${KEYBINDER_FOUND:-no}"
+echo "* Use libnotify:          ${LIBNOTIFY_FOUND:-no}"
 echo "* Default Mixer command:  $DEFAULT_MIXER_COMMAND"
 echo
diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index 1de8e11..360f4d3 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -35,6 +35,8 @@ libpulseaudio_plugin_la_SOURCES = \
 	pulseaudio-dialog.h \
 	pulseaudio-menu.c \
 	pulseaudio-menu.h \
+	pulseaudio-notify.c \
+	pulseaudio-notify.h \
 	scalemenuitem.c \
 	scalemenuitem.h
 
@@ -48,6 +50,7 @@ libpulseaudio_plugin_la_CFLAGS = \
 	$(LIBXFCE4PANEL_CFLAGS) \
 	$(XFCONF_CFLAGS) \
 	$(KEYBINDER_CFLAGS) \
+	$(LIBNOTIFY_CFLAGS) \
 	$(PLATFORM_CFLAGS)
 
 libpulseaudio_plugin_la_LDFLAGS = \
@@ -66,6 +69,7 @@ libpulseaudio_plugin_la_LIBADD = \
 	$(LIBXFCE4PANEL_LIBS) \
 	$(XFCONF_LIBS) \
 	$(KEYBINDER_LIBS) \
+	$(LIBNOTIFY_LIBS) \
 	$(LIBM)
 
 #
diff --git a/panel-plugin/pulseaudio-button.c b/panel-plugin/pulseaudio-button.c
index 032b128..9ccd1bd 100644
--- a/panel-plugin/pulseaudio-button.c
+++ b/panel-plugin/pulseaudio-button.c
@@ -239,6 +239,8 @@ pulseaudio_button_scroll_event (GtkWidget *widget, GdkEventScroll *event)
   pulseaudio_volume_set_volume (button->volume, new_volume);
   //g_debug ("dir: %d %f -> %f", event->direction, volume, new_volume);
 
+  pulseaudio_notify (button->plugin);
+
   return TRUE;
 }
 
diff --git a/panel-plugin/pulseaudio-notify.c b/panel-plugin/pulseaudio-notify.c
new file mode 100644
index 0000000..62c9fe0
--- /dev/null
+++ b/panel-plugin/pulseaudio-notify.c
@@ -0,0 +1,217 @@
+/*  Copyright (c) 2015 Andrzej <ndrwrdck at gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; either version 2
+ *  of the License, or (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY 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 with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+
+
+/*
+ *  This file implements a wrapper for libnotify
+ *
+ */
+
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_MATH_H
+#include <math.h>
+#endif
+
+#ifdef HAVE_LIBNOTIFY
+#include <libnotify/notify.h>
+#include <libxfce4util/libxfce4util.h>
+
+
+#define SYNCHRONOUS      "x-canonical-private-synchronous"
+#define LAYOUT_ICON_ONLY "x-canonical-private-icon-only"
+
+#include "pulseaudio-notify.h"
+
+#define V_MUTED  0
+#define V_LOW    1
+#define V_MEDIUM 2
+#define V_HIGH   3
+
+
+/* Icons for different volume levels */
+static const char *icons[] = {
+  "audio-volume-muted-symbolic",
+  "audio-volume-low-symbolic",
+  "audio-volume-medium-symbolic",
+  "audio-volume-high-symbolic",
+  NULL
+};
+
+
+static void                 pulseaudio_notify_finalize        (GObject            *object);
+
+
+struct _PulseaudioNotify
+{
+  GObject               __parent__;
+
+  PulseaudioConfig     *config;
+  PulseaudioVolume     *volume;
+
+  gboolean              gauge_notifications;
+  NotifyNotification   *notification;
+};
+
+struct _PulseaudioNotifyClass
+{
+  GObjectClass          __parent__;
+};
+
+
+
+
+G_DEFINE_TYPE (PulseaudioNotify, pulseaudio_notify, G_TYPE_OBJECT)
+
+static void
+pulseaudio_notify_class_init (PulseaudioNotifyClass *klass)
+{
+  GObjectClass      *gobject_class;
+
+  gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->finalize = pulseaudio_notify_finalize;
+}
+
+
+
+static void
+pulseaudio_notify_init (PulseaudioNotify *notify)
+{
+  GList *caps_list;
+  GList *node;
+
+  notify->gauge_notifications = TRUE;
+  notify->notification = NULL;
+
+  //g_set_application_name ("Xfce volume control");
+  notify_init ("Xfce volume control");
+
+  caps_list = notify_get_server_caps ();
+
+  if (caps_list)
+    {
+      node = g_list_find_custom (caps_list, LAYOUT_ICON_ONLY, (GCompareFunc) g_strcmp0);
+      if (!node)
+        notify->gauge_notifications = FALSE;
+      /*		node = g_list_find_custom (caps_list, SYNCHRONOUS, (GCompareFunc) g_strcmp0);*/
+      /*		if (!node)*/
+      /*			Inst->gauge_notifications = FALSE;*/
+      g_list_free (caps_list);
+    }
+  notify->notification = notify_notification_new ("xfce4-pulseaudio-plugin", NULL, NULL);
+}
+
+
+
+static void
+pulseaudio_notify_finalize (GObject *object)
+{
+  PulseaudioNotify *notify = PULSEAUDIO_NOTIFY (object);
+
+  notify->config = NULL;
+
+  g_object_unref (G_OBJECT (notify->notification));
+  notify->notification = NULL;
+  notify_uninit ();
+
+  (*G_OBJECT_CLASS (pulseaudio_notify_parent_class)->finalize) (object);
+}
+
+
+
+void
+pulseaudio_notify_notify (PulseaudioNotify *notify)
+{
+  GError      *error = NULL;
+  gdouble      volume;
+  gint         volume_i;
+  gboolean     muted;
+  gchar       *title = NULL;
+  const gchar *icon = NULL;
+
+  g_return_if_fail (IS_PULSEAUDIO_NOTIFY (notify));
+  g_return_if_fail (IS_PULSEAUDIO_VOLUME (notify->volume));
+
+  volume = pulseaudio_volume_get_volume (notify->volume);
+  muted = pulseaudio_volume_get_muted (notify->volume);
+  volume_i = (gint) round (volume * 100);
+
+  if (muted)
+    title = g_strdup_printf ( _("Volume %d%c (muted)"), volume_i, '%');
+  else
+    title = g_strdup_printf ( _("Volume %d%c"), volume_i, '%');
+
+  if (muted)
+    icon = icons[V_MUTED];
+  else if (volume <= 0.0)
+    icon = icons[V_MUTED];
+  else if (volume <= 0.3)
+    icon = icons[V_LOW];
+  else if (volume <= 0.7)
+    icon = icons[V_MEDIUM];
+  else
+    icon = icons[V_HIGH];
+
+
+  notify_notification_update (notify->notification,
+                              title,
+                              NULL,
+                              icon);
+  g_free (title);
+
+  if (notify->gauge_notifications) {
+    notify_notification_set_hint_int32 (notify->notification,
+                                        "value",
+                                        volume_i);
+    notify_notification_set_hint_string (notify->notification,
+                                         "x-canonical-private-synchronous",
+                                         "");
+  }
+
+  if (!notify_notification_show (notify->notification, &error))
+    {
+      g_warning ("Error while sending notification : %s\n", error->message);
+      g_error_free (error);
+    }
+}
+
+
+
+PulseaudioNotify *
+pulseaudio_notify_new (PulseaudioConfig *config,
+                       PulseaudioVolume *volume)
+{
+  PulseaudioNotify *notify;
+
+  g_return_val_if_fail (IS_PULSEAUDIO_CONFIG (config), NULL);
+  g_return_val_if_fail (IS_PULSEAUDIO_VOLUME (volume), NULL);
+
+  notify = g_object_new (TYPE_PULSEAUDIO_NOTIFY, NULL);
+
+  notify->config = config;
+  notify->volume = volume;
+
+  return notify;
+}
+
+
+#endif /* HAVE_LIBNOTIFY */
diff --git a/panel-plugin/pulseaudio-notify.h b/panel-plugin/pulseaudio-notify.h
new file mode 100644
index 0000000..0922ee5
--- /dev/null
+++ b/panel-plugin/pulseaudio-notify.h
@@ -0,0 +1,49 @@
+/*  Copyright (c) 2015 Andrzej <ndrwrdck at gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; either version 2
+ *  of the License, or (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY 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 with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __PULSEAUDIO_NOTIFY_H__
+#define __PULSEAUDIO_NOTIFY_H__
+
+#ifdef HAVE_LIBNOTIFY
+
+#include <glib-object.h>
+#include "pulseaudio-config.h"
+#include "pulseaudio-volume.h"
+
+G_BEGIN_DECLS
+
+#define TYPE_PULSEAUDIO_NOTIFY             (pulseaudio_notify_get_type ())
+#define PULSEAUDIO_NOTIFY(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PULSEAUDIO_NOTIFY, PulseaudioNotify))
+#define PULSEAUDIO_NOTIFY_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass),  TYPE_PULSEAUDIO_NOTIFY, PulseaudioNotifyClass))
+#define IS_PULSEAUDIO_NOTIFY(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PULSEAUDIO_NOTIFY))
+#define IS_PULSEAUDIO_NOTIFY_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass),  TYPE_PULSEAUDIO_NOTIFY))
+#define PULSEAUDIO_NOTIFY_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj),  TYPE_PULSEAUDIO_NOTIFY, PulseaudioNotifyClass))
+
+typedef struct          _PulseaudioNotify                 PulseaudioNotify;
+typedef struct          _PulseaudioNotifyClass            PulseaudioNotifyClass;
+
+GType                   pulseaudio_notify_get_type        (void) G_GNUC_CONST;
+
+PulseaudioNotify       *pulseaudio_notify_new             (PulseaudioConfig *config,
+                                                           PulseaudioVolume *volume);
+
+void                    pulseaudio_notify_notify          (PulseaudioNotify *notify);
+
+G_END_DECLS
+
+#endif /* HAVE_LIBNOTIFY */
+#endif /* !__PULSEAUDIO_NOTIFY_H__ */
diff --git a/panel-plugin/pulseaudio-plugin.c b/panel-plugin/pulseaudio-plugin.c
index b357aa9..76f360c 100644
--- a/panel-plugin/pulseaudio-plugin.c
+++ b/panel-plugin/pulseaudio-plugin.c
@@ -41,6 +41,7 @@
 #include "pulseaudio-volume.h"
 #include "pulseaudio-button.h"
 #include "pulseaudio-dialog.h"
+#include "pulseaudio-notify.h"
 
 #ifdef HAVE_IDO
 #include <libido/libido.h>
@@ -89,6 +90,9 @@ struct _PulseaudioPlugin
 
   PulseaudioConfig    *config;
   PulseaudioVolume    *volume;
+#ifdef HAVE_LIBNOTIFY
+  PulseaudioNotify    *notify;
+#endif
 
   /* panel widgets */
   GtkWidget           *button;
@@ -130,6 +134,9 @@ pulseaudio_plugin_init (PulseaudioPlugin *pulseaudio_plugin)
 
   pulseaudio_plugin->volume            = NULL;
   pulseaudio_plugin->button            = NULL;
+#ifdef HAVE_LIBNOTIFY
+  pulseaudio_plugin->notify            = NULL;
+#endif
 }
 
 
@@ -297,6 +304,7 @@ pulseaudio_plugin_volume_key_pressed (const char            *keystring,
     pulseaudio_volume_set_volume (pulseaudio_plugin->volume, MIN (volume + volume_step, MAX (volume, 1.0)));
   else if (strcmp (keystring, PULSEAUDIO_PLUGIN_LOWER_VOLUME_KEY) == 0)
     pulseaudio_volume_set_volume (pulseaudio_plugin->volume, volume - volume_step);
+  pulseaudio_notify (pulseaudio_plugin);
 }
 
 
@@ -309,10 +317,21 @@ pulseaudio_plugin_mute_pressed (const char            *keystring,
   pulseaudio_debug ("%s pressed", keystring);
 
   pulseaudio_volume_toggle_muted (pulseaudio_plugin->volume);
+  pulseaudio_notify (pulseaudio_plugin);
 }
 #endif
 
 
+void
+pulseaudio_notify (PulseaudioPlugin *pulseaudio_plugin)
+{
+#ifdef HAVE_LIBNOTIFY
+  pulseaudio_notify_notify (pulseaudio_plugin->notify);
+#endif
+}
+
+
+
 static void
 pulseaudio_plugin_construct (XfcePanelPlugin *plugin)
 {
@@ -350,6 +369,12 @@ pulseaudio_plugin_construct (XfcePanelPlugin *plugin)
   /* volume controller */
   pulseaudio_plugin->volume = pulseaudio_volume_new (pulseaudio_plugin->config);
 
+  /* initialize notify wrapper */
+#ifdef HAVE_LIBNOTIFY
+  pulseaudio_plugin->notify = pulseaudio_notify_new (pulseaudio_plugin->config,
+                                                     pulseaudio_plugin->volume);
+#endif
+
   /* instantiate a button box */
   pulseaudio_plugin->button = pulseaudio_button_new (pulseaudio_plugin,
                                                      pulseaudio_plugin->config,
diff --git a/panel-plugin/pulseaudio-plugin.h b/panel-plugin/pulseaudio-plugin.h
index d90205b..8802bf3 100644
--- a/panel-plugin/pulseaudio-plugin.h
+++ b/panel-plugin/pulseaudio-plugin.h
@@ -37,6 +37,8 @@ GType pulseaudio_plugin_get_type      (void) G_GNUC_CONST;
 
 void  pulseaudio_plugin_register_type (XfcePanelTypeModule *type_module);
 
+void  pulseaudio_notify               (PulseaudioPlugin    *pulseaudio_plugin);
+
 G_END_DECLS
 
 #endif /* !__PULSEAUDIO_PLUGIN_H__ */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list