From 332714a92549570d4c88c50d9be7f2bd14be6e5a Mon Sep 17 00:00:00 2001 From: Eyal Chojnowski Date: Thu, 6 Feb 2020 12:54:42 +0100 Subject: [PATCH 1/2] Make cursor beam thickness configurable --- kitty/config_data.py | 2 ++ kitty/fonts.c | 2 +- kitty/fonts/render.py | 8 ++++---- kitty/state.c | 1 + kitty/state.h | 1 + 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/kitty/config_data.py b/kitty/config_data.py index df338fad4..989c750da 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -394,6 +394,8 @@ Choose the color of text under the cursor. If you want it rendered with the background color of the cell underneath instead, use the special keyword: background''')) 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=float, long_text=_( + 'Defines the thickness of the beam cursor')) 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 0c6d1f43f..3d1ad4ff6 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, "IIIIIdd", fg->cell_width, fg->cell_height, fg->baseline, fg->underline_position, fg->underline_thickness, fg->logical_dpi_x, fg->logical_dpi_y); + 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); 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 55355fb28..7e7f1f747 100644 --- a/kitty/fonts/render.py +++ b/kitty/fonts/render.py @@ -192,7 +192,7 @@ def render_special( return ans -def render_cursor(which, cell_width=0, cell_height=0, dpi_x=0, dpi_y=0): +def render_cursor(which, cursor_beam_thickness, cell_width=0, cell_height=0, dpi_x=0, dpi_y=0): CharTexture = ctypes.c_ubyte * (cell_width * cell_height) ans = CharTexture() @@ -213,7 +213,7 @@ def render_cursor(which, cell_width=0, cell_height=0, dpi_x=0, dpi_y=0): ans[offset + x] = 255 if which == 1: # beam - vert('left', 1.5) + vert('left', cursor_beam_thickness) elif which == 2: # underline horz('bottom', 2.0) elif which == 3: # hollow @@ -221,13 +221,13 @@ def render_cursor(which, cell_width=0, cell_height=0, dpi_x=0, dpi_y=0): return ans -def prerender_function(cell_width, cell_height, baseline, underline_position, underline_thickness, dpi_x, dpi_y): +def prerender_function(cell_width, cell_height, baseline, underline_position, underline_thickness, cursor_beam_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, cell_width=cell_width, cell_height=cell_height, dpi_x=dpi_x, dpi_y=dpi_y) + render_cursor, cursor_beam_thickness=cursor_beam_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 a1b3b87a4..cc610acab 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -568,6 +568,7 @@ PYWRAP1(set_options) { S(window_padding_width, PyFloat_AsFloat); S(scrollback_pager_history_size, PyLong_AsUnsignedLong); S(cursor_shape, PyLong_AsLong); + S(cursor_beam_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 4427d506b..306738b8c 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -20,6 +20,7 @@ typedef struct { double wheel_scroll_multiplier, touch_scroll_multiplier; bool enable_audio_bell; CursorShape cursor_shape; + float cursor_beam_thickness; unsigned int open_url_modifiers; unsigned int rectangle_select_modifiers; unsigned int terminal_select_modifiers; From 830364e02671b3ab462b3724835c8ca9e96fc2d7 Mon Sep 17 00:00:00 2001 From: Eyal Chojnowski Date: Thu, 6 Feb 2020 13:05:10 +0100 Subject: [PATCH 2/2] Fix option_type --- kitty/config_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kitty/config_data.py b/kitty/config_data.py index 989c750da..6355626d9 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -394,7 +394,7 @@ Choose the color of text under the cursor. If you want it rendered with the background color of the cell underneath instead, use the special keyword: background''')) 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=float, long_text=_( +o('cursor_beam_thickness', 1.5, option_type=positive_float, long_text=_( 'Defines the thickness of the beam cursor')) 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