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();
 	}