summary refs log tree commit diff
path: root/ui.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-10-28 02:44:09 -0400
committerJune McEnroe <june@causal.agency>2018-10-28 02:44:09 -0400
commit2eaa36a30975d198d40b8f92c6b4add1eb111d31 (patch)
treed39803cd370c118def0e099725e0fa761bd5d40a /ui.c
parentUse const char *argv[] signatures (diff)
downloadcatgirl-2eaa36a30975d198d40b8f92c6b4add1eb111d31.tar.gz
catgirl-2eaa36a30975d198d40b8f92c6b4add1eb111d31.zip
Add notification with notify-send
Diffstat (limited to '')
-rw-r--r--ui.c24
1 files changed, 23 insertions, 1 deletions
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();
 	}
5b5f77969f2d3001c9382be01c8205006&follow=1'>Use sigaction in sandmanJune McEnroe 2018-11-30Handle signals consistently in the event loopJune McEnroe 2018-11-30Separate ircConnect and ircDisconnectJune McEnroe 2018-11-30Measure length of log timestamp more consistentlyJune McEnroe 2018-11-30Reformat sandman Objective-C codeJune McEnroe 2018-11-30Ignore sandmanJune McEnroe 2018-11-30Add sandmanJune McEnroe 2018-11-29Strip timestamps from log replayJune McEnroe 2018-11-29Add basic log replayJune McEnroe 2018-11-29Show unread count in term titleJune McEnroe 2018-11-29Handle no such nick errorJune McEnroe 2018-11-29Add /whoisJune McEnroe 2018-11-29Set LIBRESSL_PREFIX in Darwin.mkJune McEnroe 2018-11-28Add NetBSD.mkJune McEnroe 2018-11-28Make use of config.mk and add Darwin.mkJune McEnroe