Implement raw icon support for dunstify

Add the ability to send raw icons with dunstify -I <file path>.
This commit is contained in:
Nikos Tsipinakis 2017-01-20 19:26:16 +02:00
parent ec7905f50f
commit 86c917fc95
2 changed files with 15 additions and 3 deletions

View File

@ -37,15 +37,13 @@ dunst: options ${OBJ} main.o
@echo "${CC} ${CFLAGS} -o $@ ${OBJ} ${LDFLAGS}" @echo "${CC} ${CFLAGS} -o $@ ${OBJ} ${LDFLAGS}"
@${CC} ${CFLAGS} -o $@ ${OBJ} main.o ${LDFLAGS} @${CC} ${CFLAGS} -o $@ ${OBJ} main.o ${LDFLAGS}
dunstify:
@${CC} ${CFLAGS} -o $@ dunstify.c -std=c99 $(shell pkg-config --libs --cflags glib-2.0 libnotify)
clean-dunst: clean-dunst:
rm -f dunst ${OBJ} main.o rm -f dunst ${OBJ} main.o
rm -f org.knopwob.dunst.service rm -f org.knopwob.dunst.service
rm -f dunst.systemd.service rm -f dunst.systemd.service
clean-dunstify: clean-dunstify:
rm -f dunstify.o
rm -f dunstify rm -f dunstify
clean-doc: clean-doc:
@ -104,4 +102,7 @@ test/test: ${OBJ} ${TEST_OBJ}
test-clean: test-clean:
rm -f test/test test/*.o rm -f test/test test/*.o
dunstify: dunstify.o
${CC} ${CFLAGS} -o $@ dunstify.o $(shell pkg-config --libs --cflags glib-2.0 libnotify gdk-2.0)
.PHONY: all options clean dist install uninstall .PHONY: all options clean dist install uninstall

View File

@ -3,6 +3,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
static gchar *appname = "dunstify"; static gchar *appname = "dunstify";
static gchar *summary = NULL; static gchar *summary = NULL;
@ -13,6 +14,7 @@ static gchar **hint_strs = NULL;
static gchar **action_strs = NULL; static gchar **action_strs = NULL;
static gint timeout = NOTIFY_EXPIRES_DEFAULT; static gint timeout = NOTIFY_EXPIRES_DEFAULT;
static gchar *icon = NULL; static gchar *icon = NULL;
static gchar *raw_icon_path = NULL;
static gboolean capabilities = false; static gboolean capabilities = false;
static gboolean serverinfo = false; static gboolean serverinfo = false;
static gboolean printid = false; static gboolean printid = false;
@ -28,6 +30,7 @@ static GOptionEntry entries[] =
{ "action", 'A', 0, G_OPTION_ARG_STRING_ARRAY, &action_strs, "Actions the user can invoke", "ACTION" }, { "action", 'A', 0, G_OPTION_ARG_STRING_ARRAY, &action_strs, "Actions the user can invoke", "ACTION" },
{ "timeout", 't', 0, G_OPTION_ARG_INT, &timeout, "The time until the notification expires", "TIMEOUT" }, { "timeout", 't', 0, G_OPTION_ARG_INT, &timeout, "The time until the notification expires", "TIMEOUT" },
{ "icon", 'i', 0, G_OPTION_ARG_STRING, &icon, "An Icon that should be displayed with the notification", "ICON" }, { "icon", 'i', 0, G_OPTION_ARG_STRING, &icon, "An Icon that should be displayed with the notification", "ICON" },
{ "raw_icon", 'I', 0, G_OPTION_ARG_STRING, &raw_icon_path, "Path to the icon to be sent as raw image data", "RAW_ICON"},
{ "capabilities", 'c', 0, G_OPTION_ARG_NONE, &capabilities, "Print the server capabilities and exit", NULL}, { "capabilities", 'c', 0, G_OPTION_ARG_NONE, &capabilities, "Print the server capabilities and exit", NULL},
{ "serverinfo", 's', 0, G_OPTION_ARG_NONE, &serverinfo, "Print server information and exit", NULL}, { "serverinfo", 's', 0, G_OPTION_ARG_NONE, &serverinfo, "Print server information and exit", NULL},
{ "printid", 'p', 0, G_OPTION_ARG_NONE, &printid, "Print id, which can be used to update/replace this notification", NULL}, { "printid", 'p', 0, G_OPTION_ARG_NONE, &printid, "Print id, which can be used to update/replace this notification", NULL},
@ -266,6 +269,14 @@ int main(int argc, char *argv[])
GError *err = NULL; GError *err = NULL;
if (raw_icon_path) {
notify_notification_set_image_from_pixbuf(n, gdk_pixbuf_new_from_file(raw_icon_path, &err));
if(err) {
g_printerr("Unable to close notification: %s\n", err->message);
die(1);
}
}
if (close_id > 0) { if (close_id > 0) {
put_id(n, close_id); put_id(n, close_id);
notify_notification_close(n, &err); notify_notification_close(n, &err);