From 4a17dd24927a9f686c57d593febe5f1657f24bb1 Mon Sep 17 00:00:00 2001 From: ThinkChaos Date: Sat, 22 Feb 2025 21:19:09 -0500 Subject: [PATCH] Add max-urgency option Allow limiting notification urgency to a given maximum. I'm unfortunately forced to use MS Teams for work, and basically all its notifications are marked as urgent (at least when using the website). This change allows me to cap that: ```ini [app-name=Chromium] max-urgency=normal ``` (I use a dedicated browser for work, so app-name is enough filtering.) --- config.c | 11 +++++++++++ contrib/completions/bash/mako | 5 +++++ contrib/completions/fish/mako.fish | 1 + contrib/completions/zsh/_mako | 1 + dbus/xdg.c | 4 ++++ doc/mako.5.scd | 6 ++++++ include/config.h | 4 +++- main.c | 1 + 8 files changed, 32 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 817f7e97..1116a8c7 100644 --- a/config.c +++ b/config.c @@ -111,6 +111,8 @@ void init_default_style(struct mako_style *style) { style->default_timeout = 0; style->ignore_timeout = false; + style->max_urgency = MAKO_NOTIFICATION_URGENCY_CRITICAL; + style->colors.background = 0x285577FF; style->colors.text = 0xFFFFFFFF; style->colors.border = 0x4C7899FF; @@ -311,6 +313,11 @@ bool apply_style(struct mako_style *target, const struct mako_style *style) { target->spec.ignore_timeout = true; } + if (style->spec.max_urgency) { + target->max_urgency = style->max_urgency; + target->spec.max_urgency = true; + } + if (style->spec.colors.background) { target->colors.background = style->colors.background; target->spec.colors.background = true; @@ -642,6 +649,9 @@ static bool apply_style_option(struct mako_style *style, const char *name, } else if (strcmp(name, "ignore-timeout") == 0) { return spec->ignore_timeout = parse_boolean(value, &style->ignore_timeout); + } else if (strcmp(name, "max-urgency") == 0) { + return spec->max_urgency = + parse_urgency(value, &style->max_urgency); } else if (strcmp(name, "group-by") == 0) { return spec->group_criteria_spec = parse_criteria_spec(value, &style->group_criteria_spec); @@ -921,6 +931,7 @@ int parse_config_arguments(struct mako_config *config, int argc, char **argv) { {"history", required_argument, 0, 0}, {"default-timeout", required_argument, 0, 0}, {"ignore-timeout", required_argument, 0, 0}, + {"max-urgency", required_argument, 0, 0}, {"output", required_argument, 0, 0}, {"layer", required_argument, 0, 0}, {"anchor", required_argument, 0, 0}, diff --git a/contrib/completions/bash/mako b/contrib/completions/bash/mako index bdb5bbb6..4757c034 100644 --- a/contrib/completions/bash/mako +++ b/contrib/completions/bash/mako @@ -34,6 +34,7 @@ _mako() '--sort' '--default-timeout' '--ignore-timeout' + '--max-urgency' '--output' '--layer' '--anchor' @@ -45,6 +46,10 @@ _mako() return ;; --icons|--markup|--actions|--history|--ignore-timeout) + COMPREPLY=($(compgen -W "low normal critical" -- "$cur")) + return + ;; + --max-urgency) COMPREPLY=($(compgen -W "0 1" -- "$cur")) return ;; diff --git a/contrib/completions/fish/mako.fish b/contrib/completions/fish/mako.fish index c64d203d..ddf7943c 100644 --- a/contrib/completions/fish/mako.fish +++ b/contrib/completions/fish/mako.fish @@ -33,6 +33,7 @@ complete -c mako -l history -d 'Add expired notifications to history' -xa "1 0" complete -c mako -l sort -d 'Set notification sorting method' -x complete -c mako -l default-timeout -d 'Notification timeout in ms' -x complete -c mako -l ignore-timeout -d 'Enable notification timeout or not' -xa "1 0" +complete -c mako -l max-urgency -d 'Max allowed notification urgency' -xa "low normal critical" complete -c mako -l output -d 'Show notifications on this output' -xa '(complete_outputs)' complete -c mako -l layer -d 'Show notifications on this layer' -x complete -c mako -l anchor -d 'Position on output to put notifications' -x diff --git a/contrib/completions/zsh/_mako b/contrib/completions/zsh/_mako index 4a1f01c2..a554f54f 100644 --- a/contrib/completions/zsh/_mako +++ b/contrib/completions/zsh/_mako @@ -27,6 +27,7 @@ _arguments \ '--history[Add expired notification to history.]:history:' \ '--default-timeout[Default timeout in milliseconds.]:timeout (ms):' \ '--ignore-timeout[If set, mako will ignore the expire timeout sent by notifications and use the one provided by default-timeout instead.]:Use default timeout:(0 1)' \ + '--max-urgency[Maximum allowed notification urgency.]:urgency:(low normal critical)' \ '--output[Show notifications on this output.]:name:' \ '--layer[Arrange notifications at this layer.]:layer:(background bottom top overlay)' \ '--anchor[Position on output to put notifications.]:position:(top-right bottom-right bottom-center bottom-left top-left top-center center-right center-left center)' \ diff --git a/dbus/xdg.c b/dbus/xdg.c index 1f914314..a4ee06d9 100644 --- a/dbus/xdg.c +++ b/dbus/xdg.c @@ -408,6 +408,10 @@ static int handle_notify(sd_bus_message *msg, void *data, handle_notification_timer, notif); } + if (notif->style.spec.max_urgency && notif->urgency > notif->style.max_urgency) { + notif->urgency = notif->style.max_urgency; + } + if (notif->style.icons) { notif->icon = create_icon(notif); } diff --git a/doc/mako.5.scd b/doc/mako.5.scd index 6c1683a2..f57ef814 100644 --- a/doc/mako.5.scd +++ b/doc/mako.5.scd @@ -274,6 +274,12 @@ Default when grouped: (%g) %s\\n%b Default: 0 +*max-urgency*=low|normal|critical + Set the maximum allowed urgency to the given value. Intended to be used + as part of a criteria for applications abusing urgency. + + Default: critical (meaning no practical limit) + *group-by*=_field[,field,...]_ A comma-separated list of criteria fields that will be compared to other visible notifications to determine if this one should form a group with diff --git a/include/config.h b/include/config.h index 48769898..d8e1da6f 100644 --- a/include/config.h +++ b/include/config.h @@ -40,7 +40,7 @@ enum mako_icon_location { // structs are also mirrored. struct mako_style_spec { bool width, height, outer_margin, margin, padding, border_size, border_radius, font, - markup, format, text_alignment, actions, default_timeout, ignore_timeout, + markup, format, text_alignment, actions, default_timeout, ignore_timeout, max_urgency, icons, max_icon_size, icon_path, icon_border_radius, group_criteria_spec, invisible, history, icon_location, max_visible, layer, output, anchor; struct { @@ -78,6 +78,8 @@ struct mako_style { int default_timeout; // in ms bool ignore_timeout; + enum mako_notification_urgency max_urgency; + struct { uint32_t background; uint32_t text; diff --git a/main.c b/main.c index c273a4b8..1d5e0a27 100644 --- a/main.c +++ b/main.c @@ -53,6 +53,7 @@ static const char usage[] = " descending(-) order.\n" " --default-timeout Default timeout in milliseconds.\n" " --ignore-timeout <0|1> Enable/disable notification timeout.\n" + " --max-urgency Max allowed notification urgency.\n" " --output Show notifications on this output.\n" " --layer Arrange notifications at this layer.\n" " --anchor Position on output to put notifications.\n"