From 9fea2b316110f47a0e561bb1ba498e9d5c9e43a3 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 5 Oct 2016 14:36:12 +0200 Subject: allow to scale artwork images --- README.md | 1 + 1 file changed, 1 insertion(+) (limited to 'README.md') diff --git a/README.md b/README.md index 4f2bd8e..dd876ec 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ or `systemctl --user enable mpd-notification`. * *-o*: Notification text is one line (no line breaks) * *-p PORT*: connect to *PORT* * *-t TIMEOUT*: notification timeout, *TIMEOUT* in seconds +* *-s PIXELS*: scale image to *PIXELS* x *PIXELS* pixels * *-v*: verbose output * *-V*: print version information -- cgit v1.2.3-54-g00ecf From 81300293395926cf1b7633db4679f3e5ab6beca0 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 5 Oct 2016 15:56:28 +0200 Subject: keep aspect ratio when scaling --- README.md | 3 ++- mpd-notification.c | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index dd876ec..f834801 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,9 @@ or `systemctl --user enable mpd-notification`. * *-m MUSIC-DIR*: use *MUSIC-DIR* for artwork lookup * *-o*: Notification text is one line (no line breaks) * *-p PORT*: connect to *PORT* +* *-s PIXELS*: scale image to a maximum size *PIXELS* x *PIXELS* pixels, keeping + ratio * *-t TIMEOUT*: notification timeout, *TIMEOUT* in seconds -* *-s PIXELS*: scale image to *PIXELS* x *PIXELS* pixels * *-v*: verbose output * *-V*: print version information diff --git a/mpd-notification.c b/mpd-notification.c index c271131..8713947 100644 --- a/mpd-notification.c +++ b/mpd-notification.c @@ -345,7 +345,15 @@ int main(int argc, char ** argv) { printf("%s: found artwork in or near media file: %s/%s\n", program, music_dir, uri); if (scale > 0) { - if ((copy = gdk_pixbuf_scale_simple (pixbuf, scale, scale, GDK_INTERP_BILINEAR)) != NULL) { + int x, y; + + x = gdk_pixbuf_get_width(pixbuf); + y = gdk_pixbuf_get_height(pixbuf); + + if ((copy = gdk_pixbuf_scale_simple (pixbuf, + (x > y ? scale : scale * x / y), + (y > x ? scale : scale * y / x), + GDK_INTERP_BILINEAR)) != NULL) { g_object_unref(pixbuf); pixbuf = copy; } -- cgit v1.2.3-54-g00ecf From 9c5d990ff88ac3055623f7b9b3429bce52a0e11d Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 5 Oct 2016 22:09:18 +0200 Subject: add notification file workaround --- README.md | 2 ++ mpd-notification.c | 17 ++++++++++++++--- mpd-notification.h | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index f834801..6025af8 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ or `systemctl --user enable mpd-notification`. * *-h*: show help * *-H HOST*: connect to *HOST* * *-m MUSIC-DIR*: use *MUSIC-DIR* for artwork lookup +* *--notification-file-workaround*: write artwork to file for notification + daemons that do required it * *-o*: Notification text is one line (no line breaks) * *-p PORT*: connect to *PORT* * *-s PIXELS*: scale image to a maximum size *PIXELS* x *PIXELS* pixels, keeping diff --git a/mpd-notification.c b/mpd-notification.c index 8713947..840d4ab 100644 --- a/mpd-notification.c +++ b/mpd-notification.c @@ -19,6 +19,8 @@ const static struct option options_long[] = { { "timeout", required_argument, NULL, 't' }, { "verbose", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'V' }, + { "notification-file-workaround", + no_argument, NULL, OPT_FILE_WORKAROUND }, { 0, 0, 0, 0 } }; @@ -182,7 +184,7 @@ int main(int argc, char ** argv) { const char * mpd_host, * mpd_port_str, * music_dir, * uri = NULL; unsigned mpd_port = MPD_PORT, mpd_timeout = MPD_TIMEOUT, notification_timeout = NOTIFICATION_TIMEOUT; struct mpd_song * song = NULL; - unsigned int i, version = 0, help = 0, scale = 0; + unsigned int i, version = 0, help = 0, scale = 0, file_workaround = 0; program = argv[0]; @@ -254,6 +256,9 @@ int main(int argc, char ** argv) { if (verbose > 0) printf("%s: using notification-timeout %d\n", program, notification_timeout); break; + case OPT_FILE_WORKAROUND: + file_workaround++; + break; } } @@ -373,8 +378,14 @@ int main(int argc, char ** argv) { if (verbose > 0) printf("%s: %s\n", program, notifystr); - notify_notification_update(notification, TEXT_TOPIC, notifystr, - ICON_AUDIO_X_GENERIC); + /* Some notification daemons do not support handing pixbuf data. Write a PNG + * file and give the path. */ + if (file_workaround > 0 && pixbuf != NULL) { + gdk_pixbuf_save(pixbuf, "/tmp/.mpd-notification-artwork.png", "png", NULL, NULL); + + notify_notification_update(notification, TEXT_TOPIC, notifystr, "/tmp/.mpd-notification-artwork.png"); + } else + notify_notification_update(notification, TEXT_TOPIC, notifystr, ICON_AUDIO_X_GENERIC); /* Call this unconditionally! When pixbuf is NULL this clears old image. */ notify_notification_set_image_from_pixbuf(notification, pixbuf); diff --git a/mpd-notification.h b/mpd-notification.h index e11c359..0cbd370 100644 --- a/mpd-notification.h +++ b/mpd-notification.h @@ -31,6 +31,8 @@ #define PROGNAME "mpd-notification" +#define OPT_FILE_WORKAROUND UCHAR_MAX + 1 + /*** received_signal ***/ void received_signal(int signal); -- cgit v1.2.3-54-g00ecf