From 934336e64278dae88ab87aa75c9bf553a5931fa6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 20 Apr 2019 08:25:44 +0530 Subject: [PATCH] Allow disabling ligatures always --- docs/changelog.rst | 2 +- kitty/config_data.py | 14 +++++++++++--- kitty/fonts.c | 4 ++-- kitty/shaders.c | 5 +++-- kitty/state.c | 2 +- kitty/state.h | 3 ++- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 8f5f14e65..ac35943c8 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -20,7 +20,7 @@ To update |kitty|, :doc:`follow the instructions `. - macOS: Allow opening new kitty tabs/top-level windows from Finder (:pull:`1350`) -- Add an option :opt:`disable_ligatures_under_cursor` to disable +- Add an option :opt:`disable_ligatures` to disable multi-character ligatures under the cursor to make editing easier (:iss:`461`) diff --git a/kitty/config_data.py b/kitty/config_data.py index c13355335..49d3d3155 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -256,9 +256,17 @@ Syntax is:: ''')) -o('disable_ligatures_under_cursor', False, long_text=_(''' -Render the characters of a multi-character ligature under the cursor -individually to make editing more intuitive. + +def disable_ligatures(x): + cmap = {'never': 0, 'cursor': 1, 'always': 2} + return cmap.get(x.lower(), 0) + + +o('disable_ligatures', 'never', option_type=disable_ligatures, long_text=_(''' +Choose how you want to handle multi-character ligatures. The default is to +always render them. You can tell kitty to not render them when the cursor is +over them by using :code:`cursor` to make editing easier, or have kitty never +render them at all by using :code:`never`, if you don't like them. ''')) diff --git a/kitty/fonts.c b/kitty/fonts.c index 698743568..cb07fe78e 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -744,7 +744,7 @@ shape(CPUCell *first_cpu_cell, GPUCell *first_gpu_cell, index_type num_cells, hb group_state.last_gpu_cell = first_gpu_cell + (num_cells ? num_cells - 1 : 0); load_hb_buffer(first_cpu_cell, first_gpu_cell, num_cells); - if (disable_ligature) { + if (disable_ligature || OPT(disable_ligatures) == DISABLE_LIGATURES_ALWAYS) { hb_shape(font, harfbuzz_buffer, &no_calt_feature, 1); } else { hb_shape(font, harfbuzz_buffer, NULL, 0); @@ -1064,7 +1064,7 @@ render_line(FONTS_DATA_HANDLE fg_, Line *line, index_type lnum, Cursor *cursor) bool disable_ligature_in_line = false; index_type first_cell_in_run, i; attrs_type prev_width = 0; - if (cursor != NULL && OPT(disable_ligatures_under_cursor)) { + if (cursor != NULL && OPT(disable_ligatures) == DISABLE_LIGATURES_CURSOR) { if (lnum == cursor->y) disable_ligature_in_line = true; } for (i=0, first_cell_in_run=0; i < line->xnum; i++) { diff --git a/kitty/shaders.c b/kitty/shaders.c index 0b1d3ef80..66ca6f3f3 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -293,11 +293,12 @@ cell_prepare_to_render(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen, GLfloa bool cursor_pos_changed = screen->cursor->x != screen->last_rendered_cursor_x || screen->cursor->y != screen->last_rendered_cursor_y; + bool disable_ligatures = OPT(disable_ligatures) == DISABLE_LIGATURES_CURSOR; - if (screen->scroll_changed || screen->is_dirty || (OPT(disable_ligatures_under_cursor) && cursor_pos_changed)) { + if (screen->scroll_changed || screen->is_dirty || (disable_ligatures && cursor_pos_changed)) { sz = sizeof(GPUCell) * screen->lines * screen->columns; address = alloc_and_map_vao_buffer(vao_idx, sz, cell_data_buffer, GL_STREAM_DRAW, GL_WRITE_ONLY); - screen_update_cell_data(screen, address, fonts_data, OPT(disable_ligatures_under_cursor) && cursor_pos_changed); + screen_update_cell_data(screen, address, fonts_data, disable_ligatures && cursor_pos_changed); unmap_vao_buffer(vao_idx, cell_data_buffer); address = NULL; changed = true; } diff --git a/kitty/state.c b/kitty/state.c index 7375e0088..434b61409 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -408,7 +408,7 @@ PYWRAP1(set_options) { S(macos_hide_from_tasks, PyObject_IsTrue); S(macos_thicken_font, PyFloat_AsDouble); S(tab_bar_min_tabs, PyLong_AsUnsignedLong); - S(disable_ligatures_under_cursor, PyObject_IsTrue); + S(disable_ligatures, PyLong_AsLong); GA(tab_bar_style); global_state.tab_bar_hidden = PyUnicode_CompareWithASCIIString(ret, "hidden") == 0 ? true: false; diff --git a/kitty/state.h b/kitty/state.h index 182a6ff63..84bcb75c2 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -11,6 +11,7 @@ #define OPT(name) global_state.opts.name typedef enum { LEFT_EDGE, TOP_EDGE, RIGHT_EDGE, BOTTOM_EDGE } Edge; +typedef enum { DISABLE_LIGATURES_NEVER, DISABLE_LIGATURES_CURSOR, DISABLE_LIGATURES_ALWAYS } DisableLigature; typedef struct { double visual_bell_duration, cursor_blink_interval, cursor_stop_blinking_after, mouse_hide_wait, click_interval, wheel_scroll_multiplier, touch_scroll_multiplier; @@ -35,7 +36,7 @@ typedef struct { float window_padding_width; Edge tab_bar_edge; unsigned long tab_bar_min_tabs; - bool disable_ligatures_under_cursor; + DisableLigature disable_ligatures; bool sync_to_monitor; bool close_on_child_death; bool window_alert_on_bell;