From 2eaa36a30975d198d40b8f92c6b4add1eb111d31 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sun, 28 Oct 2018 02:44:09 -0400 Subject: Add notification with notify-send --- ui.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'ui.c') diff --git a/ui.c b/ui.c index c4d83bc..6075217 100644 --- a/ui.c +++ b/ui.c @@ -350,6 +350,28 @@ void uiCloseTag(struct Tag tag) { viewClose(view); } +static void notify(struct Tag tag, const wchar_t *line) { + beep(); + if (!self.notify) return; + + char buf[256]; + size_t cap = sizeof(buf); + + struct Format format = { .str = line }; + formatReset(&format); + while (formatParse(&format, NULL)) { + int len = snprintf( + &buf[sizeof(buf) - cap], cap, + "%.*ls", (int)format.len, format.str + ); + if (len < 0) err(EX_OSERR, "snprintf"); + if ((size_t)len >= cap) break; + cap -= len; + } + + eventPipe((const char *[]) { "notify-send", tag.name, buf, NULL }); +} + void uiLog(struct Tag tag, enum UIHeat heat, const wchar_t *line) { struct View *view = viewTag(tag); int lines = 1; @@ -362,7 +384,7 @@ void uiLog(struct Tag tag, enum UIHeat heat, const wchar_t *line) { } if (heat > UIWarm) { view->hot = true; - beep(); // TODO: Notify. + notify(tag, line); } uiStatus(); } -- cgit 1.4.1