Skip to content

Commit

Permalink
Allow dismissing notif without adding it to history
Browse files Browse the repository at this point in the history
  • Loading branch information
triallax authored and emersion committed Dec 26, 2023
1 parent dc40411 commit 5ee7c85
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 19 deletions.
2 changes: 2 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ static bool apply_style_option(struct mako_style *style, const char *name,
binding.action = MAKO_BINDING_NONE;
} else if (strcmp(value, "dismiss") == 0) {
binding.action = MAKO_BINDING_DISMISS;
} else if (strcmp(value, "dismiss --no-history") == 0) {
binding.action = MAKO_BINDING_DISMISS_NO_HISTORY;
} else if (strcmp(value, "dismiss-all") == 0) {
binding.action = MAKO_BINDING_DISMISS_ALL;
} else if (strcmp(value, "dismiss-group") == 0) {
Expand Down
4 changes: 2 additions & 2 deletions dbus/mako.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static int handle_dismiss_last_notification(sd_bus_message *msg, void *data,

struct mako_notification *notif =
wl_container_of(state->notifications.next, notif, link);
close_notification(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED);
close_notification(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED, true);
set_dirty(notif->surface);

done:
Expand All @@ -82,7 +82,7 @@ static int handle_dismiss_notification(sd_bus_message *msg, void *data,
if (dismiss_group) {
close_group_notifications(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED);
} else {
close_notification(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED);
close_notification(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED, true);
}
set_dirty(notif->surface);
break;
Expand Down
4 changes: 2 additions & 2 deletions dbus/xdg.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static void handle_notification_timer(void *data) {
struct mako_surface *surface = notif->surface;
notif->timer = NULL;

close_notification(notif, MAKO_NOTIFICATION_CLOSE_EXPIRED);
close_notification(notif, MAKO_NOTIFICATION_CLOSE_EXPIRED, true);
set_dirty(surface);
}

Expand Down Expand Up @@ -449,7 +449,7 @@ static int handle_close_notification(sd_bus_message *msg, void *data,
struct mako_notification *notif = get_notification(state, id);
if (notif) {
struct mako_surface *surface = notif->surface;
close_notification(notif, MAKO_NOTIFICATION_CLOSE_REQUEST);
close_notification(notif, MAKO_NOTIFICATION_CLOSE_REQUEST, true);
set_dirty(surface);
}

Expand Down
1 change: 1 addition & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
enum mako_binding_action {
MAKO_BINDING_NONE,
MAKO_BINDING_DISMISS,
MAKO_BINDING_DISMISS_NO_HISTORY,
MAKO_BINDING_DISMISS_GROUP,
MAKO_BINDING_DISMISS_ALL,
MAKO_BINDING_INVOKE_ACTION,
Expand Down
3 changes: 2 additions & 1 deletion include/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ struct mako_notification *create_notification(struct mako_state *state);
void destroy_notification(struct mako_notification *notif);

void close_notification(struct mako_notification *notif,
enum mako_notification_close_reason reason);
enum mako_notification_close_reason reason,
bool add_to_history);
void close_group_notifications(struct mako_notification *notif,
enum mako_notification_close_reason reason);
void close_all_notifications(struct mako_state *state,
Expand Down
5 changes: 3 additions & 2 deletions mako.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ Supported actions:
*none*
Do nothing.

*dismiss*
Dismiss the current notification.
*dismiss [--no-history]*
Dismiss the current notification. If *--no-history* is passed, the notification
won't be added to history.

*dismiss-all*
Dismiss all notifications.
Expand Down
32 changes: 20 additions & 12 deletions notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ void destroy_notification(struct mako_notification *notif) {
}

void close_notification(struct mako_notification *notif,
enum mako_notification_close_reason reason) {
enum mako_notification_close_reason reason,
bool add_to_history) {
notify_notification_closed(notif, reason);
wl_list_remove(&notif->link); // Remove so regrouping works...
wl_list_init(&notif->link); // ...but destroy will remove again.
Expand All @@ -129,12 +130,16 @@ void close_notification(struct mako_notification *notif,
destroy_timer(notif->timer);
notif->timer = NULL;

wl_list_insert(&notif->state->history, &notif->link);
while (wl_list_length(&notif->state->history) >
notif->state->config.max_history) {
struct mako_notification *n =
wl_container_of(notif->state->history.prev, n, link);
destroy_notification(n);
if (add_to_history) {
wl_list_insert(&notif->state->history, &notif->link);
while (wl_list_length(&notif->state->history) >
notif->state->config.max_history) {
struct mako_notification *n =
wl_container_of(notif->state->history.prev, n, link);
destroy_notification(n);
}
} else {
destroy_notification(notif);
}
}

Expand Down Expand Up @@ -168,7 +173,7 @@ void close_group_notifications(struct mako_notification *top_notif,

if (top_notif->style.group_criteria_spec.none) {
// No grouping, just close the notification
close_notification(top_notif, reason);
close_notification(top_notif, reason, true);
return;
}

Expand All @@ -178,7 +183,7 @@ void close_group_notifications(struct mako_notification *top_notif,
struct mako_notification *notif, *tmp;
wl_list_for_each_safe(notif, tmp, &state->notifications, link) {
if (match_criteria(notif_criteria, notif)) {
close_notification(notif, reason);
close_notification(notif, reason, true);
}
}

Expand All @@ -189,7 +194,7 @@ void close_all_notifications(struct mako_state *state,
enum mako_notification_close_reason reason) {
struct mako_notification *notif, *tmp;
wl_list_for_each_safe(notif, tmp, &state->notifications, link) {
close_notification(notif, reason);
close_notification(notif, reason, true);
}
}

Expand Down Expand Up @@ -365,7 +370,7 @@ static void try_invoke_action(struct mako_notification *notif,
break;
}
}
close_notification(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED);
close_notification(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED, true);
}

void notification_execute_binding(struct mako_notification *notif,
Expand All @@ -375,7 +380,10 @@ void notification_execute_binding(struct mako_notification *notif,
case MAKO_BINDING_NONE:
break;
case MAKO_BINDING_DISMISS:
close_notification(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED);
close_notification(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED, true);
break;
case MAKO_BINDING_DISMISS_NO_HISTORY:
close_notification(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED, false);
break;
case MAKO_BINDING_DISMISS_GROUP:
close_group_notifications(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED);
Expand Down

0 comments on commit 5ee7c85

Please sign in to comment.