diff options
Diffstat (limited to 'plugins/notification/notification.c')
-rw-r--r-- | plugins/notification/notification.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/plugins/notification/notification.c b/plugins/notification/notification.c index 28df06fc..91028350 100644 --- a/plugins/notification/notification.c +++ b/plugins/notification/notification.c @@ -5,6 +5,15 @@ static DB_misc_t plugin; static DB_functions_t *deadbeef; +static NotifyNotification *ntf; + +static void +show_notification (const char *summary, const char *body) +{ + notify_notification_close (ntf, NULL); + notify_notification_update (ntf, summary, body, NULL); + notify_notification_show (ntf, NULL); +} static int songchanged (DB_event_trackchange_t *ev, uintptr_t data) { @@ -13,16 +22,14 @@ songchanged (DB_event_trackchange_t *ev, uintptr_t data) { const char *album = deadbeef->pl_find_meta (track, "album"); const char *title = deadbeef->pl_find_meta (track, "title"); char body [1024]; - GError *err; snprintf (body, sizeof (body), "%s - %s", artist, album); - NotifyNotification *ntf = notify_notification_new (title, body, NULL, NULL); - notify_notification_set_timeout (ntf, NOTIFY_EXPIRES_DEFAULT); - notify_notification_show (ntf, NULL); + show_notification (title, body); return 0; } static int notification_stop (void) { + notify_notification_close (ntf, NULL); deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_SONGCHANGED, DB_CALLBACK (songchanged), 0); } @@ -30,6 +37,9 @@ static int notification_start (void) { notify_init ("deadbeef"); + ntf = notify_notification_new (NULL, NULL, NULL, NULL); + notify_notification_set_timeout (ntf, NOTIFY_EXPIRES_DEFAULT); + deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_SONGCHANGED, DB_CALLBACK (songchanged), 0); return 1; } |