mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
user-notification: add new function ‘user_notification_add()’
This commit is contained in:
parent
df1ed1c8cf
commit
2a99c5a093
3 changed files with 46 additions and 1 deletions
|
|
@ -181,7 +181,7 @@ executable(
|
||||||
'spawn.c', 'spawn.h',
|
'spawn.c', 'spawn.h',
|
||||||
'tokenize.c', 'tokenize.h',
|
'tokenize.c', 'tokenize.h',
|
||||||
'url-mode.c', 'url-mode.h',
|
'url-mode.c', 'url-mode.h',
|
||||||
'user-notification.h',
|
'user-notification.c', 'user-notification.h',
|
||||||
'wayland.c', 'wayland.h',
|
'wayland.c', 'wayland.h',
|
||||||
wl_proto_src + wl_proto_headers, version,
|
wl_proto_src + wl_proto_headers, version,
|
||||||
dependencies: [math, threads, libepoll, pixman, wayland_client, wayland_cursor, xkb, fontconfig,
|
dependencies: [math, threads, libepoll, pixman, wayland_client, wayland_cursor, xkb, fontconfig,
|
||||||
|
|
|
||||||
38
user-notification.c
Normal file
38
user-notification.c
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include <tllist.h>
|
#include <tllist.h>
|
||||||
|
|
||||||
|
#include "macros.h"
|
||||||
|
|
||||||
enum user_notification_kind {
|
enum user_notification_kind {
|
||||||
USER_NOTIFICATION_DEPRECATED,
|
USER_NOTIFICATION_DEPRECATED,
|
||||||
USER_NOTIFICATION_WARNING,
|
USER_NOTIFICATION_WARNING,
|
||||||
|
|
@ -22,3 +25,7 @@ user_notifications_free(user_notifications_t *notifications)
|
||||||
free(it->item.text);
|
free(it->item.text);
|
||||||
tll_free(*notifications);
|
tll_free(*notifications);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool user_notification_add(user_notifications_t *notifications,
|
||||||
|
enum user_notification_kind kind,
|
||||||
|
const char *fmt, ...) PRINTF(3);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue