config: add new mouse binding ‘launch-url’, bind to alt+BTN_LEFT

This adds a new mouse binding, launch-url (bound to Alt+BTN_LEFT by
default). When executed, the URL under the mouse pointer is
launched (with url.launcher, as usual).

This is done by calling urls_collect(), to get all currently visible
URLs (both auto-detected and OSC-8 ones), and then iterating them all
until we find one that spans the cell the mouse pointer is on.
This commit is contained in:
Daniel Eklöf 2022-06-17 18:45:28 +02:00
parent 8b882b3a13
commit 16d220d3f9
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 39 additions and 1 deletions

35
input.c
View file

@ -454,6 +454,41 @@ execute_binding(struct seat *seat, struct terminal *term,
term, seat->mouse.col, seat->mouse.row, SELECTION_LINE_WISE, false);
return true;
case BIND_ACTION_LAUNCH_URL: {
const int m_row = seat->mouse.row;
const int m_col = seat->mouse.col;
if (m_col >= 0 && m_row >= 0) {
url_list_t urls = tll_init();
urls_collect(term, URL_ACTION_LAUNCH, &urls);
tll_foreach(urls, it) {
const struct url *url = &it->item;
const int start_row = url->range.start.row;
const int start_col = url->range.start.col;
const int end_row = url->range.end.row;
const int end_col = url->range.end.col;
bool start_is_before_point =
start_row < m_row ||
(start_row == m_row && start_col <= m_col);
bool end_is_after_point =
end_row > m_row ||
(end_row == m_row && end_col >= m_col);
if (start_is_before_point && end_is_after_point) {
url_activate(seat, term, url, serial);
break;
}
}
url_list_destroy(&urls);
}
return true;
}
case BIND_ACTION_COUNT:
BUG("Invalid action type");
return false;