aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--notify.h52
-rw-r--r--ponymix.cc14
3 files changed, 71 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 28bdaf3..951debb 100644
--- a/Makefile
+++ b/Makefile
@@ -6,13 +6,19 @@ base_LIBS = -lm
libpulse_CXXFLAGS = $(shell pkg-config --cflags libpulse)
libpulse_LIBS = $(shell pkg-config --libs libpulse)
+libnotify_CXXFLAGS = $(shell pkg-config --cflags libnotify 2>/dev/null && echo "-DHAVE_NOTIFY")
+libnotify_LIBS = $(shell pkg-config --libs libnotify 2>/dev/null)
+
+
CXXFLAGS := \
$(base_CXXFLAGS) \
+ $(libnotify_CXXFLAGS) \
$(libpulse_CXXFLAGS) \
$(CXXFLAGS)
LDLIBS := \
$(base_LIBS) \
+ $(libnotify_LIBS) \
$(libpulse_LIBS)
all: ponymix
diff --git a/notify.h b/notify.h
index 03f6775..4718f20 100644
--- a/notify.h
+++ b/notify.h
@@ -2,6 +2,10 @@
#include <stdio.h>
+#ifdef HAVE_NOTIFY
+#include <libnotify/notify.h>
+#endif
+
enum NotificationType {
NOTIFY_VOLUME,
NOTIFY_BALANCE,
@@ -35,4 +39,52 @@ class CommandLineNotifier : public Notifier {
}
};
+#ifdef HAVE_NOTIFY
+class LibnotifyNotifier : public Notifier {
+ public:
+ LibnotifyNotifier() {
+ notify_init("ponymix");
+ }
+
+ virtual ~LibnotifyNotifier() {
+ notify_uninit();
+ }
+
+ virtual void Notify(enum NotificationType type, long value, bool mute) {
+ switch (type) {
+ case NOTIFY_BALANCE:
+ break;
+ case NOTIFY_VOLUME:
+ case NOTIFY_UNMUTE:
+ case NOTIFY_MUTE:
+ volchange(value, mute);
+ break;
+ }
+ }
+
+ private:
+ void volchange(long vol, bool mute) {
+ const char* icon = "notification-audio-volume-muted";
+
+ if (!mute) {
+ if (vol > 67) {
+ icon = "notification-audio-volume-high";
+ } else if (vol > 33) {
+ icon = "notification-audio-volume-medium";
+ } else if (vol > 0) {
+ icon = "notification-audio-volume-low";
+ }
+ }
+
+ NotifyNotification* notification = notify_notification_new("ponymix", "", icon);
+ notify_notification_set_timeout(notification, 1000);
+ notify_notification_set_urgency(notification, NOTIFY_URGENCY_NORMAL);
+ notify_notification_set_hint_int32(notification, "value", vol);
+ notify_notification_set_hint_string(notification, "synchronous", "volume");
+ notify_notification_show(notification, NULL);
+ g_object_unref(G_OBJECT(notification));
+ }
+};
+#endif
+
// vim: set et ts=2 sw=2:
diff --git a/ponymix.cc b/ponymix.cc
index 2dde405..df8b1c7 100644
--- a/ponymix.cc
+++ b/ponymix.cc
@@ -56,6 +56,7 @@ static bool opt_listrestrict;
static const char* opt_action;
static const char* opt_device;
static const char* opt_card;
+static bool opt_notify;
static Color color;
static const char* type_to_string(enum DeviceType t) {
@@ -534,6 +535,7 @@ bool parse_options(int argc, char** argv) {
{ "card", required_argument, 0, 'c' },
{ "device", required_argument, 0, 'd' },
{ "help", no_argument, 0, 'h' },
+ { "notify", no_argument, 0, 'N' },
{ "type", required_argument, 0, 't' },
{ "sink", no_argument, 0, 0x100 },
{ "output", no_argument, 0, 0x101 },
@@ -545,7 +547,7 @@ bool parse_options(int argc, char** argv) {
};
for (;;) {
- int opt = getopt_long(argc, argv, "c:d:ht:", opts, nullptr);
+ int opt = getopt_long(argc, argv, "c:d:hNt:", opts, nullptr);
if (opt == -1)
break;
@@ -559,6 +561,9 @@ bool parse_options(int argc, char** argv) {
case 'h':
usage();
break;
+ case 'N':
+ opt_notify = true;
+ break;
case 't':
opt_devtype = string_to_devtype_or_die(optarg);
opt_listrestrict = true;
@@ -605,7 +610,14 @@ int main(int argc, char* argv[]) {
argv += optind;
try {
+#ifdef HAVE_NOTIFY
+ if (opt_notify) {
+ ponymix.EnableNotifications(new LibnotifyNotifier);
+ } else
+#endif
+ {
ponymix.EnableNotifications(new CommandLineNotifier);
+ }
} catch (std::exception e) {
fprintf(stderr, "failed to enable notifier\n");
}