mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-11 08:21:01 -04:00
url-mode: urls_collect(): URL list pointer as an argument
This commit is contained in:
parent
2c10a147ea
commit
a988138492
4 changed files with 61 additions and 55 deletions
6
input.c
6
input.c
|
|
@ -280,9 +280,9 @@ execute_binding(struct seat *seat, struct terminal *term,
|
||||||
? URL_ACTION_COPY
|
? URL_ACTION_COPY
|
||||||
: URL_ACTION_LAUNCH;
|
: URL_ACTION_LAUNCH;
|
||||||
|
|
||||||
urls_collect(term, url_action);
|
urls_collect(term, url_action, &term->urls);
|
||||||
urls_tag_cells(term);
|
urls_assign_key_combos(&term->urls);
|
||||||
render_refresh_urls(term);
|
urls_render(term);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -234,6 +234,7 @@ struct url {
|
||||||
struct coord end;
|
struct coord end;
|
||||||
enum url_action action;
|
enum url_action action;
|
||||||
};
|
};
|
||||||
|
typedef tll(struct url) url_list_t;
|
||||||
|
|
||||||
struct terminal {
|
struct terminal {
|
||||||
struct fdm *fdm;
|
struct fdm *fdm;
|
||||||
|
|
@ -513,7 +514,7 @@ struct terminal {
|
||||||
unsigned max_height; /* Maximum image height, in pixels */
|
unsigned max_height; /* Maximum image height, in pixels */
|
||||||
} sixel;
|
} sixel;
|
||||||
|
|
||||||
tll(struct url) urls;
|
url_list_t urls;
|
||||||
wchar_t url_keys[5];
|
wchar_t url_keys[5];
|
||||||
|
|
||||||
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
||||||
|
|
|
||||||
100
url-mode.c
100
url-mode.c
|
|
@ -141,7 +141,7 @@ urls_input(struct seat *seat, struct terminal *term, uint32_t key,
|
||||||
IGNORE_WARNING("-Wpedantic")
|
IGNORE_WARNING("-Wpedantic")
|
||||||
|
|
||||||
static void
|
static void
|
||||||
auto_detected(struct terminal *term, enum url_action action)
|
auto_detected(const struct terminal *term, enum url_action action, url_list_t *urls)
|
||||||
{
|
{
|
||||||
static const wchar_t *const prots[] = {
|
static const wchar_t *const prots[] = {
|
||||||
L"http://",
|
L"http://",
|
||||||
|
|
@ -299,7 +299,7 @@ auto_detected(struct terminal *term, enum url_action action)
|
||||||
end.row += term->grid->view;
|
end.row += term->grid->view;
|
||||||
|
|
||||||
tll_push_back(
|
tll_push_back(
|
||||||
term->urls,
|
*urls,
|
||||||
((struct url){
|
((struct url){
|
||||||
.url = xwcsdup(url),
|
.url = xwcsdup(url),
|
||||||
.text = xwcsdup(L""),
|
.text = xwcsdup(L""),
|
||||||
|
|
@ -321,12 +321,16 @@ auto_detected(struct terminal *term, enum url_action action)
|
||||||
UNIGNORE_WARNINGS
|
UNIGNORE_WARNINGS
|
||||||
|
|
||||||
void
|
void
|
||||||
urls_collect(struct terminal *term, enum url_action action)
|
urls_collect(const struct terminal *term, enum url_action action, url_list_t *urls)
|
||||||
{
|
{
|
||||||
xassert(tll_length(term->urls) == 0);
|
xassert(tll_length(term->urls) == 0);
|
||||||
auto_detected(term, action);
|
auto_detected(term, action, urls);
|
||||||
|
}
|
||||||
|
|
||||||
size_t count = tll_length(term->urls);
|
void
|
||||||
|
urls_assign_key_combos(url_list_t *urls)
|
||||||
|
{
|
||||||
|
size_t count = tll_length(*urls);
|
||||||
|
|
||||||
/* Assign key combos */
|
/* Assign key combos */
|
||||||
|
|
||||||
|
|
@ -337,7 +341,7 @@ urls_collect(struct terminal *term, enum url_action action)
|
||||||
|
|
||||||
if (count < ALEN(single)) {
|
if (count < ALEN(single)) {
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
tll_foreach(term->urls, it) {
|
tll_foreach(*urls, it) {
|
||||||
xassert(wcslen(single[idx]) < ALEN(it->item.key) - 1);
|
xassert(wcslen(single[idx]) < ALEN(it->item.key) - 1);
|
||||||
wcscpy(it->item.key, single[idx++]);
|
wcscpy(it->item.key, single[idx++]);
|
||||||
}
|
}
|
||||||
|
|
@ -347,7 +351,7 @@ urls_collect(struct terminal *term, enum url_action action)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_DEBUG) && LOG_ENABLE_DBG
|
#if defined(_DEBUG) && LOG_ENABLE_DBG
|
||||||
tll_foreach(term->urls, it) {
|
tll_foreach(*urls, it) {
|
||||||
char url[1024];
|
char url[1024];
|
||||||
wcstombs(url, it->item.url, sizeof(url) - 1);
|
wcstombs(url, it->item.url, sizeof(url) - 1);
|
||||||
|
|
||||||
|
|
@ -358,6 +362,43 @@ urls_collect(struct terminal *term, enum url_action action)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
tag_cells_for_url(struct terminal *term, const struct url *url, bool value)
|
||||||
|
{
|
||||||
|
const struct coord *start = &url->start;
|
||||||
|
const struct coord *end = &url->end;
|
||||||
|
|
||||||
|
size_t end_r = end->row & (term->grid->num_rows - 1);
|
||||||
|
|
||||||
|
size_t r = start->row & (term->grid->num_rows - 1);
|
||||||
|
size_t c = start->col;
|
||||||
|
|
||||||
|
struct row *row = term->grid->rows[r];
|
||||||
|
row->dirty = true;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
struct cell *cell = &row->cells[c];
|
||||||
|
cell->attrs.url = value;
|
||||||
|
cell->attrs.clean = 0;
|
||||||
|
|
||||||
|
if (r == end_r && c == end->col)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (++c >= term->cols) {
|
||||||
|
r = (r + 1) & (term->grid->num_rows - 1);
|
||||||
|
c = 0;
|
||||||
|
|
||||||
|
row = term->grid->rows[r];
|
||||||
|
row->dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
urls_render(struct terminal *term)
|
||||||
|
{
|
||||||
struct wl_window *win = term->window;
|
struct wl_window *win = term->window;
|
||||||
struct wayland *wayl = term->wl;
|
struct wayland *wayl = term->wl;
|
||||||
|
|
||||||
|
|
@ -397,49 +438,10 @@ urls_collect(struct terminal *term, enum url_action action)
|
||||||
};
|
};
|
||||||
|
|
||||||
tll_push_back(win->urls, url);
|
tll_push_back(win->urls, url);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
tag_cells_for_url(struct terminal *term, const struct url *url, bool value)
|
|
||||||
{
|
|
||||||
const struct coord *start = &url->start;
|
|
||||||
const struct coord *end = &url->end;
|
|
||||||
|
|
||||||
size_t end_r = end->row & (term->grid->num_rows - 1);
|
|
||||||
|
|
||||||
size_t r = start->row & (term->grid->num_rows - 1);
|
|
||||||
size_t c = start->col;
|
|
||||||
|
|
||||||
struct row *row = term->grid->rows[r];
|
|
||||||
row->dirty = true;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
struct cell *cell = &row->cells[c];
|
|
||||||
cell->attrs.url = value;
|
|
||||||
cell->attrs.clean = 0;
|
|
||||||
|
|
||||||
if (r == end_r && c == end->col)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (++c >= term->cols) {
|
|
||||||
r = (r + 1) & (term->grid->num_rows - 1);
|
|
||||||
c = 0;
|
|
||||||
|
|
||||||
row = term->grid->rows[r];
|
|
||||||
row->dirty = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
urls_tag_cells(struct terminal *term)
|
|
||||||
{
|
|
||||||
if (unlikely(tll_length(term->urls)) == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
tll_foreach(term->urls, it)
|
|
||||||
tag_cells_for_url(term, &it->item, true);
|
tag_cells_for_url(term, &it->item, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
render_refresh_urls(term);
|
||||||
render_refresh(term);
|
render_refresh(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,11 @@ static inline bool urls_mode_is_active(const struct terminal *term)
|
||||||
return tll_length(term->urls) > 0;
|
return tll_length(term->urls) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void urls_collect(struct terminal *term, enum url_action action);
|
void urls_collect(
|
||||||
void urls_tag_cells(struct terminal *term);
|
const struct terminal *term, enum url_action action, url_list_t *urls);
|
||||||
|
void urls_assign_key_combos(url_list_t *urls);
|
||||||
|
|
||||||
|
void urls_render(struct terminal *term);
|
||||||
void urls_reset(struct terminal *term);
|
void urls_reset(struct terminal *term);
|
||||||
|
|
||||||
void urls_input(struct seat *seat, struct terminal *term, uint32_t key,
|
void urls_input(struct seat *seat, struct terminal *term, uint32_t key,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue