From ed9b332da5763a7c7b66458f07d9dbb1b6df49d2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 5 Dec 2017 12:28:10 +0530 Subject: [PATCH] Add an option to control the underline style for highlighting URLs on mouse over --- CHANGELOG.rst | 1 + kitty/cell_vertex.glsl | 4 ++-- kitty/config.py | 8 ++++++++ kitty/kitty.conf | 4 +++- kitty/shaders.c | 4 ++-- kitty/state.c | 1 + kitty/state.h | 1 + 7 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2be7ede3b..d0e63ea02 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -37,6 +37,7 @@ version 0.6.0 [future] - Allow drag and drop of files into kitty. On drop kitty will paste the file path to the running program. +- Add an option to control the underline style for URL highlighting on hover version 0.5.1 [2017-12-01] --------------------------- diff --git a/kitty/cell_vertex.glsl b/kitty/cell_vertex.glsl index 636b2b76d..f798649f6 100644 --- a/kitty/cell_vertex.glsl +++ b/kitty/cell_vertex.glsl @@ -6,7 +6,7 @@ layout(std140) uniform CellRenderData { float xstart, ystart, dx, dy, sprite_dx, sprite_dy, background_opacity; - uint default_fg, default_bg, highlight_fg, highlight_bg, cursor_color, url_color; + uint default_fg, default_bg, highlight_fg, highlight_bg, cursor_color, url_color, url_style; int color1, color2; @@ -160,7 +160,7 @@ void main() { // Underline and strike through (rendered via sprites) float in_url = in_range(c, r); decoration_fg = choose_color(in_url, color_to_vec(url_color), to_color(colors[2], resolved_fg)); - underline_pos = choose_color(in_url, to_sprite_pos(pos, THREE, ZERO, ZERO), to_sprite_pos(pos, (text_attrs >> 2) & DECORATION_MASK, ZERO, ZERO)); + underline_pos = choose_color(in_url, to_sprite_pos(pos, url_style, ZERO, ZERO), to_sprite_pos(pos, (text_attrs >> 2) & DECORATION_MASK, ZERO, ZERO)); strike_pos = to_sprite_pos(pos, ((text_attrs >> 7) & STRIKE_MASK) * FOUR, ZERO, ZERO); // Cursor diff --git a/kitty/config.py b/kitty/config.py index 3c629b258..1bfd07ddf 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -248,6 +248,13 @@ def tab_font_style(x): return {'bold-italic': (True, True), 'bold': (True, False), 'italic': (False, True)}.get(x.lower().replace('_', '-'), (False, False)) +def url_style(x): + return url_style.map.get(x, url_style.map['curly']) + + +url_style.map = dict(((v, i) for i, v in enumerate('none single double curly'.split()))) + + type_map = { 'adjust_line_height': adjust_line_height, 'scrollback_lines': positive_int, @@ -283,6 +290,7 @@ type_map = { 'tab_separator': tab_separator, 'active_tab_font_style': tab_font_style, 'inactive_tab_font_style': tab_font_style, + 'url_style': url_style, } for name in ( diff --git a/kitty/kitty.conf b/kitty/kitty.conf index 443efb1b1..d0fdf7601 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -61,8 +61,10 @@ selection_foreground #000000 # The background for selections selection_background #FFFACD -# The color for highlighting URLs on mouse-over +# The color and style for highlighting URLs on mouse-over. url_style can be one of: +# none, single, double, curly url_color #0087BD +url_style curly # The cursor color cursor #cccccc diff --git a/kitty/shaders.c b/kitty/shaders.c index 68061bc09..2e0ff60f6 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -202,7 +202,7 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, G struct CellRenderData { GLfloat xstart, ystart, dx, dy, sprite_dx, sprite_dy, background_opacity; - GLuint default_fg, default_bg, highlight_fg, highlight_bg, cursor_color, url_color; + GLuint default_fg, default_bg, highlight_fg, highlight_bg, cursor_color, url_color, url_style; GLint color1, color2; @@ -236,7 +236,7 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, G #define COLOR(name) colorprofile_to_color(screen->color_profile, screen->color_profile->overridden.name, screen->color_profile->configured.name) rd->default_fg = COLOR(default_fg); rd->default_bg = COLOR(default_bg); rd->highlight_fg = COLOR(highlight_fg); rd->highlight_bg = COLOR(highlight_bg); #undef COLOR - rd->cursor_color = cursor->color; rd->url_color = OPT(url_color); + rd->cursor_color = cursor->color; rd->url_color = OPT(url_color); rd->url_style = OPT(url_style); unmap_vao_buffer(vao_idx, uniform_buffer); rd = NULL; } diff --git a/kitty/state.c b/kitty/state.c index b9adf7a4b..cfb85020c 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -310,6 +310,7 @@ PYWRAP1(set_options) { S(cursor_stop_blinking_after, PyFloat_AsDouble); S(background_opacity, PyFloat_AsDouble); S(cursor_shape, PyLong_AsLong); + S(url_style, PyLong_AsUnsignedLong); S(x11_bell_volume, PyLong_AsLong); S(mouse_hide_wait, PyFloat_AsDouble); S(wheel_scroll_multiplier, PyFloat_AsDouble); diff --git a/kitty/state.h b/kitty/state.h index 0c9df0a8f..f851e20f4 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -15,6 +15,7 @@ typedef struct { bool enable_audio_bell; CursorShape cursor_shape; unsigned int open_url_modifiers; + unsigned int url_style; char_type select_by_word_characters[256]; size_t select_by_word_characters_count; color_type url_color, background; double repaint_delay, input_delay;