aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson.build2
-rw-r--r--user-notification.c38
-rw-r--r--user-notification.h7
3 files changed, 46 insertions, 1 deletions
diff --git a/meson.build b/meson.build
index 1465fa3e..f17ab7ef 100644
--- a/meson.build
+++ b/meson.build
@@ -181,7 +181,7 @@ executable(
'spawn.c', 'spawn.h',
'tokenize.c', 'tokenize.h',
'url-mode.c', 'url-mode.h',
- 'user-notification.h',
+ 'user-notification.c', 'user-notification.h',
'wayland.c', 'wayland.h',
wl_proto_src + wl_proto_headers, version,
dependencies: [math, threads, libepoll, pixman, wayland_client, wayland_cursor, xkb, fontconfig,
diff --git a/user-notification.c b/user-notification.c
new file mode 100644
index 00000000..497aa08c
--- /dev/null
+++ b/user-notification.c
@@ -0,0 +1,38 @@
+#include "user-notification.h"
+#include <stdio.h>
+#include <stdarg.h>
+
+static bool
+user_notification_add_va(user_notifications_t *notifications,
+ enum user_notification_kind kind, const char *fmt,
+ va_list ap)
+{
+ va_list ap2;
+ va_copy(ap2, ap);
+ int cnt = vsnprintf(NULL, 0, fmt, ap2);
+ va_end(ap2);
+
+ if (cnt < 0)
+ return false;
+
+ char *text = malloc(cnt + 1);
+ vsnprintf(text, cnt + 1, fmt, ap);
+
+ struct user_notification not = {
+ .kind = kind,
+ .text = text,
+ };
+ tll_push_back(*notifications, not);
+ return true;
+}
+
+bool
+user_notification_add(user_notifications_t *notifications,
+ enum user_notification_kind kind, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ bool ret = user_notification_add_va(notifications, kind, fmt, ap);
+ va_end(ap);
+ return ret;
+}
diff --git a/user-notification.h b/user-notification.h
index f184871e..507c1791 100644
--- a/user-notification.h
+++ b/user-notification.h
@@ -1,7 +1,10 @@
#pragma once
+#include <stdbool.h>
#include <tllist.h>
+#include "macros.h"
+
enum user_notification_kind {
USER_NOTIFICATION_DEPRECATED,
USER_NOTIFICATION_WARNING,
@@ -22,3 +25,7 @@ user_notifications_free(user_notifications_t *notifications)
free(it->item.text);
tll_free(*notifications);
}
+
+bool user_notification_add(user_notifications_t *notifications,
+ enum user_notification_kind kind,
+ const char *fmt, ...) PRINTF(3);