mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-28 01:40:17 -05:00
Merge branch 'user-notification-cleanup'
This commit is contained in:
commit
ef862bd747
3 changed files with 25 additions and 44 deletions
21
config.c
21
config.c
|
|
@ -152,9 +152,7 @@ log_and_notify_va(struct config *conf, enum log_class log_class,
|
||||||
|
|
||||||
char *formatted_msg = xvasprintf(fmt, va);
|
char *formatted_msg = xvasprintf(fmt, va);
|
||||||
log_msg(log_class, LOG_MODULE, file, lineno, "%s", formatted_msg);
|
log_msg(log_class, LOG_MODULE, file, lineno, "%s", formatted_msg);
|
||||||
tll_push_back(
|
user_notification_add(&conf->notifications, kind, formatted_msg);
|
||||||
conf->notifications,
|
|
||||||
((struct user_notification){.kind = kind, .text = formatted_msg}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void NOINLINE PRINTF(5)
|
static void NOINLINE PRINTF(5)
|
||||||
|
|
@ -3118,11 +3116,8 @@ config_clone(const struct config *old)
|
||||||
conf->notifications.length = 0;
|
conf->notifications.length = 0;
|
||||||
conf->notifications.head = conf->notifications.tail = 0;
|
conf->notifications.head = conf->notifications.tail = 0;
|
||||||
tll_foreach(old->notifications, it) {
|
tll_foreach(old->notifications, it) {
|
||||||
struct user_notification notif = {
|
char *text = xstrdup(it->item.text);
|
||||||
.kind = it->item.kind,
|
user_notification_add(&conf->notifications, it->item.kind, text);
|
||||||
.text = xstrdup(it->item.text),
|
|
||||||
};
|
|
||||||
tll_push_back(conf->notifications, notif);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return conf;
|
return conf;
|
||||||
|
|
@ -3249,13 +3244,13 @@ check_if_font_is_monospaced(const char *pattern,
|
||||||
"setting [tweak].font-monospace-warn=no",
|
"setting [tweak].font-monospace-warn=no",
|
||||||
pattern);
|
pattern);
|
||||||
|
|
||||||
user_notification_add(
|
static const char fmt[] =
|
||||||
notifications,
|
|
||||||
USER_NOTIFICATION_WARNING,
|
|
||||||
"%s: font does not appear to be monospace; "
|
"%s: font does not appear to be monospace; "
|
||||||
"check your config, or disable this warning by "
|
"check your config, or disable this warning by "
|
||||||
"setting \033[1m[tweak].font-monospace-warn=no\033[22m",
|
"setting \033[1m[tweak].font-monospace-warn=no\033[22m";
|
||||||
pattern);
|
|
||||||
|
user_notification_add_fmt(notifications, USER_NOTIFICATION_WARNING,
|
||||||
|
fmt, pattern);
|
||||||
|
|
||||||
is_monospaced = false;
|
is_monospaced = false;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,14 @@
|
||||||
#include "user-notification.h"
|
#include "user-notification.h"
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include "xmalloc.h"
|
||||||
|
|
||||||
static bool
|
void
|
||||||
user_notification_add_va(user_notifications_t *notifications,
|
user_notification_add_fmt(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, ...)
|
enum user_notification_kind kind, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
bool ret = user_notification_add_va(notifications, kind, fmt, ap);
|
char *text = xvasprintf(fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return ret;
|
user_notification_add(notifications, kind, text);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <tllist.h>
|
#include <tllist.h>
|
||||||
|
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
|
|
@ -26,6 +25,17 @@ user_notifications_free(user_notifications_t *notifications)
|
||||||
tll_free(*notifications);
|
tll_free(*notifications);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool user_notification_add(user_notifications_t *notifications,
|
static inline void
|
||||||
|
user_notification_add(user_notifications_t *notifications,
|
||||||
|
enum user_notification_kind kind, char *text)
|
||||||
|
{
|
||||||
|
struct user_notification notification = {
|
||||||
|
.kind = kind,
|
||||||
|
.text = text
|
||||||
|
};
|
||||||
|
tll_push_back(*notifications, notification);
|
||||||
|
}
|
||||||
|
|
||||||
|
void user_notification_add_fmt(user_notifications_t *notifications,
|
||||||
enum user_notification_kind kind,
|
enum user_notification_kind kind,
|
||||||
const char *fmt, ...) PRINTF(3);
|
const char *fmt, ...) PRINTF(3);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue