diff options
author | Dave Reisner <dreisner@archlinux.org> | 2013-01-21 16:09:02 -0500 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2013-01-22 21:05:39 -0500 |
commit | 0027e9422fa7205d0a50b995fbe172c35c9ce379 (patch) | |
tree | 6ace11eb26204dffe902bc722ee604ab94d7a67e | |
parent | 4aa7581f9dc97e3c8b01a9411cf665158895f4c0 (diff) | |
download | mirror-ponymix-0027e9422fa7205d0a50b995fbe172c35c9ce379.tar.gz mirror-ponymix-0027e9422fa7205d0a50b995fbe172c35c9ce379.tar.bz2 mirror-ponymix-0027e9422fa7205d0a50b995fbe172c35c9ce379.zip |
add support for libnotify based notifier
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | notify.h | 52 | ||||
-rw-r--r-- | ponymix.cc | 14 |
3 files changed, 71 insertions, 1 deletions
@@ -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 @@ -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: @@ -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"); } |