diff options
Diffstat (limited to 'render.c')
| -rw-r--r-- | render.c | 196 |
1 files changed, 168 insertions, 28 deletions
@@ -1,6 +1,7 @@ #include "render.h" #include <string.h> +#include <wctype.h> #include <unistd.h> #include <sys/ioctl.h> @@ -28,13 +29,14 @@ #include "config.h" #include "grid.h" #include "hsl.h" +#include "ime.h" #include "quirks.h" #include "selection.h" -#include "sixel.h" #include "shm.h" +#include "sixel.h" +#include "url-mode.h" #include "util.h" #include "xmalloc.h" -#include "ime.h" #define TIME_SCROLL_DAMAGE 0 @@ -411,7 +413,7 @@ render_cell(struct terminal *term, pixman_image_t *pix, uint32_t _fg = 0; uint32_t _bg = 0; - if (is_selected && term->conf->colors.selection_uses_custom_colors) { + if (is_selected && term->conf->colors.use_custom.selection) { _fg = term->conf->colors.selection_fg; _bg = term->conf->colors.selection_bg; } else { @@ -615,6 +617,15 @@ render_cell(struct terminal *term, pixman_image_t *pix, if (cell->attrs.strikethrough) draw_strikeout(term, pix, font, &fg, x, y, cell_cols); + if (unlikely(cell->attrs.url)) { + pixman_color_t url_color = color_hex_to_pixman( + term->conf->colors.use_custom.url + ? term->conf->colors.url + : term->colors.table[3] + ); + draw_underline(term, pix, font, &url_color, x, y, cell_cols); + } + draw_cursor: if (has_cursor && (term->cursor_style != CURSOR_BLOCK || !term->kbd_focus)) draw_cursor(term, cell, font, pix, &fg, &bg, x, y, cell_cols); @@ -1604,27 +1615,27 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx) uint32_t _color; uint16_t alpha = 0xffff; bool is_active = false; - const bool *is_set = NULL; + bool is_set = false; const uint32_t *conf_color = NULL; switch (surf_idx) { case CSD_SURF_MINIMIZE: _color = term->colors.default_table[4]; /* blue */ - is_set = &term->conf->csd.color.minimize_set; + is_set = term->conf->csd.color.minimize_set; conf_color = &term->conf->csd.color.minimize; is_active = term->active_surface == TERM_SURF_BUTTON_MINIMIZE; break; case CSD_SURF_MAXIMIZE: _color = term->colors.default_table[2]; /* green */ - is_set = &term->conf->csd.color.maximize_set; + is_set = term->conf->csd.color.maximize_set; conf_color = &term->conf->csd.color.maximize; is_active = term->active_surface == TERM_SURF_BUTTON_MAXIMIZE; break; case CSD_SURF_CLOSE: _color = term->colors.default_table[1]; /* red */ - is_set = &term->conf->csd.color.close_set; + is_set = term->conf->csd.color.close_set; conf_color = &term->conf->csd.color.close; is_active = term->active_surface == TERM_SURF_BUTTON_CLOSE; break; @@ -1635,7 +1646,7 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx) } if (is_active) { - if (*is_set) { + if (is_set) { _color = *conf_color; alpha = _color >> 24 | (_color >> 24 << 8); } @@ -2518,6 +2529,120 @@ render_search_box(struct terminal *term) } static void +render_urls(struct terminal *term) +{ + struct wl_window *win = term->window; + xassert(tll_length(win->urls) > 0); + + /* Calculate view start, counted from the *current* scrollback start */ + const int scrollback_end + = (term->grid->offset + term->rows) & (term->grid->num_rows - 1); + const int view_start + = (term->grid->view + - scrollback_end + + term->grid->num_rows) & (term->grid->num_rows - 1); + const int view_end = view_start + term->rows - 1; + + tll_foreach(win->urls, it) { + const struct url *url = it->item.url; + const wchar_t *text = url->text; + const wchar_t *key = url->key; + const size_t entered_key_len = wcslen(term->url_keys); + + struct wl_surface *surf = it->item.surf; + struct wl_subsurface *sub_surf = it->item.sub_surf; + + if (surf == NULL || sub_surf == NULL) + continue; + + bool hide = false; + const struct coord *pos = &url->start; + const int _row + = (pos->row + - scrollback_end + + term->grid->num_rows) & (term->grid->num_rows - 1); + + if (_row < view_start || _row > view_end) + hide = true; + if (wcslen(key) <= entered_key_len) + hide = true; + if (wcsncmp(term->url_keys, key, entered_key_len) != 0) + hide = true; + + if (hide) { + wl_surface_attach(surf, NULL, 0, 0); + wl_surface_commit(surf); + continue; + } + + size_t text_len = wcslen(text); + size_t chars = wcslen(key) + (text_len > 0 ? 3 + text_len : 0); + + const size_t max_chars = 50; + chars = min(chars, max_chars); + + wchar_t label[chars + 2]; + if (text_len == 0) + wcscpy(label, key); + else { + int count = swprintf(label, chars + 1, L"%ls - %ls", key, text); + if (count >= max_chars) { + label[max_chars] = L'…'; + label[max_chars + 1] = L'\0'; + } + } + + for (size_t i = 0; i < wcslen(key); i++) + label[i] = towupper(label[i]); + + for (size_t i = 0; i < entered_key_len; i++) + label[i] = L' '; + + size_t len = wcslen(label); + int cols = wcswidth(label, len); + + const int x_margin = 2 * term->scale; + const int y_margin = 1 * term->scale; + int width = 2 * x_margin + cols * term->cell_width; + int height = 2 * y_margin + term->cell_height; + + struct buffer *buf = shm_get_buffer( + term->wl->shm, width, height, shm_cookie_url(url), false, 1); + + int col = pos->col; + int row = pos->row - term->grid->view; + while (row < 0) + row += term->grid->num_rows; + row &= (term->grid->num_rows - 1); + + int x = col * term->cell_width - 15 * term->cell_width / 10; + int y = row * term->cell_height - 5 * term->cell_height / 10; + + if (x < 0) + x = 0; +#if 0 + if (y < 0) + y += 15 * term->cell_height / 10; +#endif + + wl_subsurface_set_position( + sub_surf, + (term->margins.left + x) / term->scale, + (term->margins.top + y) / term->scale); + + uint32_t fg = term->conf->colors.use_custom.jump_label + ? term->conf->colors.jump_label.fg + : term->colors.table[0]; + uint32_t bg = term->conf->colors.use_custom.jump_label + ? term->conf->colors.jump_label.bg + : term->colors.table[3]; + + render_osd(term, surf, sub_surf, buf, label, + fg, bg, width, height, x_margin, y_margin); + } +} + +static void render_update_title(struct terminal *term) { static const size_t max_len = 2048; @@ -2545,13 +2670,15 @@ frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_da bool grid = term->render.pending.grid; bool csd = term->render.pending.csd; - bool search = term->render.pending.search; + bool search = term->is_searching && term->render.pending.search; bool title = term->render.pending.title; + bool urls = urls_mode_is_active(term) > 0 && term->render.pending.urls; term->render.pending.grid = false; term->render.pending.csd = false; term->render.pending.search = false; term->render.pending.title = false; + term->render.pending.urls = false; if (csd && term->window->use_csd == CSD_YES) { quirk_weston_csd_on(term); @@ -2562,15 +2689,19 @@ frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_da if (title) render_update_title(term); - if (search && term->is_searching) + if (search) render_search_box(term); - tll_foreach(term->wl->seats, it) - if (it->item.kbd_focus == term) - ime_update_cursor_rect(&it->item, term); + if (urls) + render_urls(term); - if (grid && (!term->delayed_render_timer.is_armed || csd || search)) + if (grid && (!term->delayed_render_timer.is_armed | csd | search | urls)) grid_render(term); + + tll_foreach(term->wl->seats, it) { + if (it->item.kbd_focus == term) + ime_update_cursor_rect(&it->item, term); + } } static void @@ -2755,6 +2886,9 @@ maybe_resize(struct terminal *term, int width, int height, bool force) /* Cancel an application initiated "Synchronized Update" */ term_disable_app_sync_updates(term); + /* Drop out of URL mode */ + urls_reset(term); + term->width = width; term->height = height; term->scale = scale; @@ -2981,27 +3115,21 @@ fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data) bool grid = term->render.refresh.grid; bool csd = term->render.refresh.csd; - bool search = term->render.refresh.search; + bool search = term->is_searching && term->render.refresh.search; bool title = term->render.refresh.title; + bool urls = urls_mode_is_active(term) && term->render.refresh.urls; - if (!term->is_searching) - search = false; - - if (!(grid | csd | search | title)) + if (!(grid | csd | search | title | urls)) continue; - if (term->render.app_sync_updates.enabled && !(csd | search | title)) + if (term->render.app_sync_updates.enabled && !(csd | search | title | urls)) continue; - if (csd | search) { - /* Force update of parent surface */ - grid = true; - } - term->render.refresh.grid = false; term->render.refresh.csd = false; term->render.refresh.search = false; term->render.refresh.title = false; + term->render.refresh.urls = false; if (term->window->frame_callback == NULL) { if (csd && term->window->use_csd == CSD_YES) { @@ -3013,17 +3141,22 @@ fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data) render_update_title(term); if (search) render_search_box(term); - tll_foreach(term->wl->seats, it) + if (urls) + render_urls(term); + if (grid | csd | search | urls) + grid_render(term); + + tll_foreach(term->wl->seats, it) { if (it->item.kbd_focus == term) ime_update_cursor_rect(&it->item, term); - if (grid) - grid_render(term); + } } else { /* Tells the frame callback to render again */ term->render.pending.grid |= grid; term->render.pending.csd |= csd; term->render.pending.search |= search; term->render.pending.title |= title; + term->render.pending.urls |= urls; } } @@ -3065,6 +3198,13 @@ render_refresh_search(struct terminal *term) term->render.refresh.search = true; } +void +render_refresh_urls(struct terminal *term) +{ + if (urls_mode_is_active(term)) + term->render.refresh.urls = true; +} + bool render_xcursor_set(struct seat *seat, struct terminal *term, const char *xcursor) { |
