diff --git a/src/input.c b/src/input.c index f689696..dd2a796 100644 --- a/src/input.c +++ b/src/input.c @@ -47,7 +47,7 @@ void input_handle_click(unsigned int button, bool button_down, int mouse_x, int continue; } - if (act == MOUSE_DO_ACTION || act == MOUSE_CLOSE_CURRENT || act == MOUSE_CONTEXT) { + if (act == MOUSE_DO_ACTION || act == MOUSE_CLOSE_CURRENT || act == MOUSE_CONTEXT || act == MOUSE_OPEN_URL) { int y = settings.separator_height; struct notification *n = NULL; int first = true; @@ -67,12 +67,10 @@ void input_handle_click(unsigned int button, bool button_down, int mouse_x, int n->marked_for_closure = REASON_USER; } else if (act == MOUSE_DO_ACTION) { notification_do_action(n); + } else if (act == MOUSE_OPEN_URL) { + notification_open_url(n); } else { - GList *notifications = NULL; - notifications = g_list_append(notifications, n); - notification_lock(n); - - context_menu_for(notifications); + notification_open_context_menu(n); } } } diff --git a/src/notification.c b/src/notification.c index e9ab576..86f97ce 100644 --- a/src/notification.c +++ b/src/notification.c @@ -649,29 +649,45 @@ void notification_update_text_to_render(struct notification *n) } /* see notification.h */ -void notification_do_action(const struct notification *n) +void notification_do_action(struct notification *n) { + assert(n->default_action_name); + if (g_hash_table_size(n->actions)) { - if (g_hash_table_contains(n->actions, "default")) { - signal_action_invoked(n, "default"); + if (g_hash_table_contains(n->actions, n->default_action_name)) { + signal_action_invoked(n, n->default_action_name); return; } - if (g_hash_table_size(n->actions) == 1) { + if (strcmp(n->default_action_name, "default") == 0 && g_hash_table_size(n->actions) == 1) { GList *keys = g_hash_table_get_keys(n->actions); signal_action_invoked(n, keys->data); g_list_free(keys); return; } - context_menu(); + notification_open_context_menu(n); - } else if (n->urls) { - if (strstr(n->urls, "\n")) - context_menu(); - else - open_browser(n->urls); } } +/* see notification.h */ +void notification_open_url(struct notification *n) +{ + if (strstr(n->urls, "\n")) + notification_open_context_menu(n); + else + open_browser(n->urls); +} + +/* see notification.h */ +void notification_open_context_menu(struct notification *n) +{ + GList *notifications = NULL; + notifications = g_list_append(notifications, n); + notification_lock(n); + + context_menu_for(notifications); +} + void notification_invalidate_actions(struct notification *n) { g_hash_table_remove_all(n->actions); } diff --git a/src/notification.h b/src/notification.h index 1107bfd..bfaab72 100644 --- a/src/notification.h +++ b/src/notification.h @@ -196,11 +196,24 @@ void notification_replace_single_field(char **haystack, void notification_update_text_to_render(struct notification *n); /** - * If the notification has exactly one action, or one is marked as default, - * invoke it. If there are multiple and no default, open the context menu. If - * there are no actions, proceed similarly with urls. + * If the notification has an action named n->default_action_name or there is only one + * action and n->default_action_name is set to "default", invoke it. If there is no + * such action, open the context menu if threre are other actions. Otherwise, do nothing. */ -void notification_do_action(const struct notification *n); +void notification_do_action(struct notification *n); + +/** + * If the notification has exactly one url, invoke it. If there are multiple, + * open the context menu. If there are no urls, do nothing. + */ +void notification_open_url(struct notification *n); + +/** + * Open the context menu for the notification. + * + * Convenience function that creates the GList and passes it to context_menu_for(). + */ +void notification_open_context_menu(struct notification *n); /** * Remove all client action data from the notification.