From edba63d0d9f670165e9283b70286d46b9d2b1a8a Mon Sep 17 00:00:00 2001 From: Eyal Chojnowski Date: Thu, 6 Feb 2020 16:15:12 +0100 Subject: [PATCH] Make underline cursor thickness configurable --- docs/changelog.rst | 3 +++ kitty/config_data.py | 2 ++ kitty/fonts.c | 2 +- kitty/fonts/render.py | 10 ++++++---- kitty/state.c | 1 + kitty/state.h | 1 + 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 58b9fe24c..c95ea6403 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -19,6 +19,9 @@ To update |kitty|, :doc:`follow the instructions `. - A new :opt:`cursor_beam_thickness` option to control the thickness of the beam cursor (:iss:`2337`) +- A new :opt:`cursor_underline_thickness` option to control the thickness of the + underline cursor + 0.16.0 [2020-01-28] diff --git a/kitty/config_data.py b/kitty/config_data.py index dd52062d8..0eab46756 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -396,6 +396,8 @@ o('cursor_shape', 'block', option_type=to_cursor_shape, long_text=_( 'The cursor shape can be one of (block, beam, underline)')) o('cursor_beam_thickness', 1.5, option_type=positive_float, long_text=_( 'Defines the thickness of the beam cursor (in pts)')) +o('cursor_underline_thickness', 2.0, option_type=positive_float, long_text=_( + 'Defines the thickness of the underline cursor (in pts)')) o('cursor_blink_interval', -1, option_type=float, long_text=_(''' The interval (in seconds) at which to blink the cursor. Set to zero to disable blinking. Negative values mean use system default. Note that numbers smaller diff --git a/kitty/fonts.c b/kitty/fonts.c index 3d1ad4ff6..5609e131c 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -1232,7 +1232,7 @@ send_prerendered_sprites(FontGroup *fg) { current_send_sprite_to_gpu((FONTS_DATA_HANDLE)fg, x, y, z, fg->canvas); do_increment(fg, &error); if (error != 0) { sprite_map_set_error(error); PyErr_Print(); fatal("Failed"); } - PyObject *args = PyObject_CallFunction(prerender_function, "IIIIIfdd", fg->cell_width, fg->cell_height, fg->baseline, fg->underline_position, fg->underline_thickness, OPT(cursor_beam_thickness), fg->logical_dpi_x, fg->logical_dpi_y); + PyObject *args = PyObject_CallFunction(prerender_function, "IIIIIffdd", fg->cell_width, fg->cell_height, fg->baseline, fg->underline_position, fg->underline_thickness, OPT(cursor_beam_thickness), fg->logical_dpi_x, fg->logical_dpi_y); if (args == NULL) { PyErr_Print(); fatal("Failed to pre-render cells"); } for (ssize_t i = 0; i < PyTuple_GET_SIZE(args) - 1; i++) { x = fg->sprite_tracker.x; y = fg->sprite_tracker.y; z = fg->sprite_tracker.z; diff --git a/kitty/fonts/render.py b/kitty/fonts/render.py index 7e7f1f747..16723a7cc 100644 --- a/kitty/fonts/render.py +++ b/kitty/fonts/render.py @@ -192,7 +192,7 @@ def render_special( return ans -def render_cursor(which, cursor_beam_thickness, cell_width=0, cell_height=0, dpi_x=0, dpi_y=0): +def render_cursor(which, cursor_beam_thickness, cursor_underline_thickness, cell_width=0, cell_height=0, dpi_x=0, dpi_y=0): CharTexture = ctypes.c_ubyte * (cell_width * cell_height) ans = CharTexture() @@ -215,19 +215,21 @@ def render_cursor(which, cursor_beam_thickness, cell_width=0, cell_height=0, dpi if which == 1: # beam vert('left', cursor_beam_thickness) elif which == 2: # underline - horz('bottom', 2.0) + horz('bottom', cursor_underline_thickness) elif which == 3: # hollow vert('left'), vert('right'), horz('top'), horz('bottom') return ans -def prerender_function(cell_width, cell_height, baseline, underline_position, underline_thickness, cursor_beam_thickness, dpi_x, dpi_y): +def prerender_function(cell_width, cell_height, baseline, underline_position, underline_thickness, cursor_beam_thickness, cursor_underline_thickness, dpi_x, dpi_y): # Pre-render the special underline, strikethrough and missing and cursor cells f = partial( render_special, cell_width=cell_width, cell_height=cell_height, baseline=baseline, underline_position=underline_position, underline_thickness=underline_thickness) c = partial( - render_cursor, cursor_beam_thickness=cursor_beam_thickness, cell_width=cell_width, cell_height=cell_height, dpi_x=dpi_x, dpi_y=dpi_y) + render_cursor, cursor_beam_thickness=cursor_beam_thickness, + cursor_underline_thickness=cursor_underline_thickness, cell_width=cell_width, + cell_height=cell_height, dpi_x=dpi_x, dpi_y=dpi_y) cells = f(1), f(2), f(3), f(0, True), f(missing=True), c(1), c(2), c(3) return tuple(map(ctypes.addressof, cells)) + (cells,) diff --git a/kitty/state.c b/kitty/state.c index cc610acab..83b6a62ea 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -569,6 +569,7 @@ PYWRAP1(set_options) { S(scrollback_pager_history_size, PyLong_AsUnsignedLong); S(cursor_shape, PyLong_AsLong); S(cursor_beam_thickness, PyFloat_AsFloat); + S(cursor_underline_thickness, PyFloat_AsFloat); S(url_style, PyLong_AsUnsignedLong); S(tab_bar_edge, PyLong_AsLong); S(mouse_hide_wait, parse_s_double_to_monotonic_t); diff --git a/kitty/state.h b/kitty/state.h index 306738b8c..f6cd6378d 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -21,6 +21,7 @@ typedef struct { bool enable_audio_bell; CursorShape cursor_shape; float cursor_beam_thickness; + float cursor_underline_thickness; unsigned int open_url_modifiers; unsigned int rectangle_select_modifiers; unsigned int terminal_select_modifiers;