about 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)
downloadtest-2eaa36a30975d198d40b8f92c6b4add1eb111d31.tar.gz
test-2eaa36a30975d198d40b8f92c6b4add1eb111d31.zip
Add notification with notify-send
Diffstat (limited to 'ui.c')
-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();
 	}
rmat.cJune McEnroe 2018-09-13Fix len for format->split at end of stringJune McEnroe 2018-09-13Avoid uninitialized x in uiReadJune McEnroe 2018-09-13Add IRCDefault to colors enumJune McEnroe 2018-09-13Return a format->split even at the end of the stringJune McEnroe 2018-09-13Fix weird tab-complete after commaJune McEnroe 2018-09-13Rewrite UI againJune McEnroe 2018-09-12Add note about C-oJune McEnroe 2018-09-12Use formatParse split to position input cursorJune McEnroe 2018-09-12Factor out IRC formatting parsingJune McEnroe 2018-09-11Add /help equivalent to /manJune McEnroe 2018-09-11Don't render every PM as a pingJune McEnroe 2018-09-11Add urlOpenMatchJune McEnroe 2018-09-10Depend on man.sh for chroot.tar targetJune McEnroe 2018-09-10Set LESSSECURE=1 in man.shJune McEnroe 2018-09-10Add /man commandJune McEnroe 2018-09-10Install man page in chrootJune McEnroe 2018-09-10Install man pageJune McEnroe 2018-09-10Split keys into subsections and document colorsJune McEnroe 2018-09-10Add "blank" lines to chatte.1June McEnroe 2018-09-10Document key bindings in chatte.1June McEnroe 2018-09-08Document slash commands in chatte.1June McEnroe