Skip to content

Commit 4ea5a80

Browse files
authored
Merge pull request #1491 from FelipeFTN/master
Feature: remove_current in notification queues
2 parents 4463c33 + 064ba98 commit 4ea5a80

File tree

10 files changed

+57
-5
lines changed

10 files changed

+57
-5
lines changed

docs/dunst.5.pod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ B<Defaults:>
596596

597597
=item * C<mouse_left_click=close_current>
598598

599-
=item * C<mouse_middle_click=do_action, close_current>
599+
=item * C<mouse_middle_click=do_action, remove_current>
600600

601601
=item * C<mouse_right_click=close_all>
602602

dunstrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@
320320
# * open_url: If the notification has exactly one url, open it. If there are multiple
321321
# ones, open the context menu.
322322
# * close_current: Close current notification.
323+
# * remove_current: Remove current notification from history.
323324
# * close_all: Close all notifications.
324325
# * context: Open context menu for the notification.
325326
# * context_all: Open context menu for all notifications.

src/input.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void input_handle_click(unsigned int button, bool button_down, int mouse_x, int
9797
continue;
9898
}
9999

100-
if (act == MOUSE_DO_ACTION || act == MOUSE_CLOSE_CURRENT || act == MOUSE_CONTEXT || act == MOUSE_OPEN_URL) {
100+
if (act == MOUSE_DO_ACTION || act == MOUSE_CLOSE_CURRENT || act == MOUSE_REMOVE_CURRENT || act == MOUSE_CONTEXT || act == MOUSE_OPEN_URL) {
101101
struct notification *n = get_notification_at(mouse_y);
102102

103103
if (n) {
@@ -107,6 +107,8 @@ void input_handle_click(unsigned int button, bool button_down, int mouse_x, int
107107
notification_do_action(n);
108108
} else if (act == MOUSE_OPEN_URL) {
109109
notification_open_url(n);
110+
} else if (act == MOUSE_REMOVE_CURRENT) {
111+
n->marked_for_removal = REASON_USER;
110112
} else {
111113
notification_open_context_menu(n);
112114
}

src/menu.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,14 @@ static gboolean context_menu_result_dispatch(gpointer user_data)
355355
queues_notification_close(n, n->marked_for_closure);
356356
n->marked_for_closure = 0;
357357
}
358+
359+
// If the notification was marked for removal, remove it from history
360+
if (n->marked_for_removal) {
361+
// Don't close notification if context was aborted
362+
// if (dmenu_output != NULL)
363+
queues_notification_remove(n, n->marked_for_removal);
364+
n->marked_for_removal = 0;
365+
}
358366
}
359367

360368
menu_ctx.locked_notifications = NULL;

src/notification.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ struct notification {
107107
enum behavior_fullscreen fullscreen; //!< The instruction what to do with it, when desktop enters fullscreen
108108
bool script_run; /**< Has the script been executed already? */
109109
guint8 marked_for_closure;
110+
guint8 marked_for_removal; /**< If set, the notification is marked for removal in history */
110111
bool word_wrap;
111112
PangoEllipsizeMode ellipsize;
112113
PangoAlignment alignment;

src/queues.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@ void queues_notification_close(struct notification *n, enum reason reason)
373373
queues_notification_close_id(n->id, reason);
374374
}
375375

376+
void queues_notification_remove(struct notification *n, enum reason reason)
377+
{
378+
assert(n != NULL);
379+
queues_notification_close_id(n->id, reason);
380+
queues_history_remove_by_id(n->id);
381+
}
382+
376383
static void queues_destroy_notification(struct notification *n, gpointer user_data)
377384
{
378385
(void)user_data;
@@ -505,6 +512,13 @@ void queues_update(struct dunst_status status, gint64 time)
505512
continue;
506513
}
507514

515+
if (n->marked_for_removal) {
516+
queues_notification_remove(n, n->marked_for_removal);
517+
n->marked_for_removal = 0;
518+
iter = nextiter;
519+
continue;
520+
}
521+
508522

509523
if (queues_notification_is_finished(n, status, time)) {
510524
queues_notification_close(n, REASON_TIME);

src/queues.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,32 @@ void queues_notification_close_id(gint id, enum reason reason);
104104
*
105105
* @param n (transfer full) The notification to close
106106
* @param reason The #reason to close
107-
* */
107+
*/
108108
void queues_notification_close(struct notification *n, enum reason reason);
109109

110+
/**
111+
* Remove the given notification from all queues
112+
*
113+
* Sends a signal and removes the selected notification from all queues.
114+
*
115+
* @param n (transfer full) The notification to remove
116+
* @param reason The #reason to remove
117+
*/
118+
void queues_notification_remove(struct notification *n, enum reason reason);
119+
120+
/**
121+
* Remove the notification that has n->id == id
122+
*
123+
* Sends a signal and removes the selected notification from all queues.
124+
*
125+
* @param id The id of the notification to remove
126+
* @param reason The #reason to remove
127+
*
128+
* @post Call wake_up() to synchronize the queues with the UI
129+
* (which closes the notification on screen)
130+
*/
131+
void queues_notification_remove_id(gint id, enum reason reason);
132+
110133
/**
111134
* Removes all notifications from history
112135
* Returns the number of removed notifications

src/settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ enum sort_type { SORT_TYPE_ID, SORT_TYPE_URGENCY_ASCENDING, SORT_TYPE_URGENCY_DE
3333
enum vertical_alignment { VERTICAL_TOP, VERTICAL_CENTER, VERTICAL_BOTTOM };
3434
enum separator_color { SEP_FOREGROUND, SEP_AUTO, SEP_FRAME, SEP_CUSTOM };
3535
enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD };
36-
enum mouse_action { MOUSE_NONE, MOUSE_DO_ACTION, MOUSE_CLOSE_CURRENT,
36+
enum mouse_action { MOUSE_NONE, MOUSE_DO_ACTION, MOUSE_CLOSE_CURRENT, MOUSE_REMOVE_CURRENT,
3737
MOUSE_CLOSE_ALL, MOUSE_CONTEXT, MOUSE_CONTEXT_ALL, MOUSE_OPEN_URL,
3838
MOUSE_ACTION_END = LIST_END /* indicates the end of a list of mouse actions */};
3939
#ifndef ZWLR_LAYER_SHELL_V1_LAYER_ENUM

src/settings_data.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ static const struct string_to_enum_def mouse_action_enum_data[] = {
312312
{"context", MOUSE_CONTEXT },
313313
{"context_all", MOUSE_CONTEXT_ALL },
314314
{"open_url", MOUSE_OPEN_URL },
315+
{"remove_current", MOUSE_REMOVE_CURRENT },
315316
ENUM_END,
316317
};
317318

@@ -1306,7 +1307,7 @@ static const struct setting allowed_settings[] = {
13061307
.section = "global",
13071308
.description = "Action of middle click event",
13081309
.type = TYPE_LIST,
1309-
.default_value = "do_action, close_current",
1310+
.default_value = "do_action, remove_current",
13101311
.value = &settings.mouse_middle_click,
13111312
.parser = NULL,
13121313
.parser_data = GINT_TO_POINTER(MOUSE_LIST),

test/option_parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,15 @@ TEST test_string_to_list(void)
373373
"none, close_current",
374374
"close_all,close_current",
375375
"close_all,close_current,close_all",
376+
"remove_current,close_current,close_all",
376377
};
377378
const enum mouse_action results[][4] = {
378379
{MOUSE_CLOSE_CURRENT, MOUSE_ACTION_END},
379380
{MOUSE_NONE, MOUSE_ACTION_END},
380381
{MOUSE_NONE, MOUSE_CLOSE_CURRENT, MOUSE_ACTION_END},
381382
{MOUSE_CLOSE_ALL, MOUSE_CLOSE_CURRENT, MOUSE_ACTION_END},
382383
{MOUSE_CLOSE_ALL, MOUSE_CLOSE_CURRENT, MOUSE_CLOSE_ALL, MOUSE_ACTION_END},
384+
{MOUSE_REMOVE_CURRENT, MOUSE_CLOSE_CURRENT, MOUSE_CLOSE_ALL, MOUSE_ACTION_END},
383385
};
384386

385387
static char buf[100];

0 commit comments

Comments
 (0)