Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add max-urgency option #559

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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},
Expand Down
5 changes: 5 additions & 0 deletions contrib/completions/bash/mako
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ _mako()
'--sort'
'--default-timeout'
'--ignore-timeout'
'--max-urgency'
'--output'
'--layer'
'--anchor'
Expand All @@ -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
;;
Expand Down
1 change: 1 addition & 0 deletions contrib/completions/fish/mako.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions contrib/completions/zsh/_mako
Original file line number Diff line number Diff line change
Expand Up @@ -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)' \
Expand Down
4 changes: 4 additions & 0 deletions dbus/xdg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions doc/mako.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ Default when grouped: (%g) <b>%s</b>\\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
Expand Down
4 changes: 3 additions & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static const char usage[] =
" descending(-) order.\n"
" --default-timeout <timeout> Default timeout in milliseconds.\n"
" --ignore-timeout <0|1> Enable/disable notification timeout.\n"
" --max-urgency <urgency> Max allowed notification urgency.\n"
" --output <name> Show notifications on this output.\n"
" --layer <layer> Arrange notifications at this layer.\n"
" --anchor <position> Position on output to put notifications.\n"
Expand Down