Implement open_url and action_name
This commit is contained in:
parent
b49925c86d
commit
0dfc4ed738
10
src/input.c
10
src/input.c
@ -47,7 +47,7 @@ void input_handle_click(unsigned int button, bool button_down, int mouse_x, int
|
|||||||
continue;
|
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;
|
int y = settings.separator_height;
|
||||||
struct notification *n = NULL;
|
struct notification *n = NULL;
|
||||||
int first = true;
|
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;
|
n->marked_for_closure = REASON_USER;
|
||||||
} else if (act == MOUSE_DO_ACTION) {
|
} else if (act == MOUSE_DO_ACTION) {
|
||||||
notification_do_action(n);
|
notification_do_action(n);
|
||||||
|
} else if (act == MOUSE_OPEN_URL) {
|
||||||
|
notification_open_url(n);
|
||||||
} else {
|
} else {
|
||||||
GList *notifications = NULL;
|
notification_open_context_menu(n);
|
||||||
notifications = g_list_append(notifications, n);
|
|
||||||
notification_lock(n);
|
|
||||||
|
|
||||||
context_menu_for(notifications);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -649,29 +649,45 @@ void notification_update_text_to_render(struct notification *n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* see notification.h */
|
/* 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_size(n->actions)) {
|
||||||
if (g_hash_table_contains(n->actions, "default")) {
|
if (g_hash_table_contains(n->actions, n->default_action_name)) {
|
||||||
signal_action_invoked(n, "default");
|
signal_action_invoked(n, n->default_action_name);
|
||||||
return;
|
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);
|
GList *keys = g_hash_table_get_keys(n->actions);
|
||||||
signal_action_invoked(n, keys->data);
|
signal_action_invoked(n, keys->data);
|
||||||
g_list_free(keys);
|
g_list_free(keys);
|
||||||
return;
|
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) {
|
void notification_invalidate_actions(struct notification *n) {
|
||||||
g_hash_table_remove_all(n->actions);
|
g_hash_table_remove_all(n->actions);
|
||||||
}
|
}
|
||||||
|
@ -196,11 +196,24 @@ void notification_replace_single_field(char **haystack,
|
|||||||
void notification_update_text_to_render(struct notification *n);
|
void notification_update_text_to_render(struct notification *n);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the notification has exactly one action, or one is marked as default,
|
* If the notification has an action named n->default_action_name or there is only one
|
||||||
* invoke it. If there are multiple and no default, open the context menu. If
|
* action and n->default_action_name is set to "default", invoke it. If there is no
|
||||||
* there are no actions, proceed similarly with urls.
|
* 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.
|
* Remove all client action data from the notification.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user