From eebe12a972e150a0cd6b726345e46f8df88b051d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 5 Feb 2019 10:34:56 +0530 Subject: [PATCH] Allow specifying a value of ``none`` for the :opt:`selection_foreground`` which will cause kitty to not change text color in selections Fixes #1358 --- docs/changelog.rst | 3 +++ kitty/cell_vertex.glsl | 3 +++ kitty/config_data.py | 13 ++++++++++--- kitty/main.py | 1 + kitty/window.py | 9 ++++++++- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 3efc08e91..c23948764 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -7,6 +7,9 @@ To update |kitty|, :doc:`follow the instructions `. 0.13.4 [future] --------------------- +- Allow specifying a value of ``none`` for the :opt:`selection_foreground`` + which will cause kitty to not change text color in selections (:iss:`1358`) + - icat kitten: Add support for displaying images at http(s) URLs (:iss:`1340`) - A new option :opt:`strip_trailing_spaces` to optionally remove trailing diff --git a/kitty/cell_vertex.glsl b/kitty/cell_vertex.glsl index c774163f3..29d9353e5 100644 --- a/kitty/cell_vertex.glsl +++ b/kitty/cell_vertex.glsl @@ -5,6 +5,7 @@ #define REVERSE_SHIFT {REVERSE_SHIFT} #define STRIKE_SHIFT {STRIKE_SHIFT} #define DIM_SHIFT {DIM_SHIFT} +#define USE_SELECTION_FG // Inputs {{{ layout(std140) uniform CellRenderData { @@ -171,8 +172,10 @@ void main() { foreground = color_to_vec(resolved_fg); float has_dim = float((text_attrs >> DIM_SHIFT) & ONE); effective_text_alpha = inactive_text_alpha * mix(1.0, dim_opacity, has_dim); +#ifdef USE_SELECTION_FG // Selection foreground = choose_color(float(is_selected & ONE), color_to_vec(highlight_fg), foreground); +#endif // Underline and strike through (rendered via sprites) float in_url = float((is_selected & TWO) >> 1); decoration_fg = choose_color(in_url, color_to_vec(url_color), to_color(colors[2], resolved_fg)); diff --git a/kitty/config_data.py b/kitty/config_data.py index 416473c9f..c9e542e03 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -655,9 +655,16 @@ o('dim_opacity', 0.75, option_type=unit_float, long_text=_(''' How much to dim text that has the DIM/FAINT attribute set. One means no dimming and zero means fully dimmed (i.e. invisible).''')) -o('selection_foreground', '#000000', option_type=to_color, long_text=_(''' -The foreground and background for text selected with the mouse''')) -o('selection_background', '#FFFACD', option_type=to_color) + +def selection_foreground(x): + if x.lower() != 'none': + return to_color(x) + + +o('selection_foreground', '#000000', option_type=selection_foreground, long_text=_(''' +The foreground for text selected with the mouse. A value of none means to leave the color unchanged.''')) +o('selection_background', '#FFFACD', option_type=to_color, long_text=_(''' +The background for text selected with the mouse.''')) g('colors.table') o('color0', '#000000', long_text=_('black'), option_type=to_color) diff --git a/kitty/main.py b/kitty/main.py index 4fc3501a6..ce2928cc6 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -122,6 +122,7 @@ def _run_app(opts, args): if not is_wayland and not is_macos: # no window icons on wayland with open(logo_data_file, 'rb') as f: set_default_window_icon(f.read(), 256, 256) + load_shader_programs.use_selection_fg = opts.selection_foreground is not None with cached_values_for(run_app.cached_values_name) as cached_values: with startup_notification_handler(extra_callback=run_app.first_window_callback) as pre_show_callback: window_id = create_os_window( diff --git a/kitty/window.py b/kitty/window.py index 80c1bcdf2..d5ac00c96 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -79,6 +79,9 @@ def load_shader_programs(semi_transparent=0): if semi_transparent: vv = vv.replace('#define NOT_TRANSPARENT', '#define TRANSPARENT') ff = ff.replace('#define NOT_TRANSPARENT', '#define TRANSPARENT') + if not load_shader_programs.use_selection_fg: + vv = vv.replace('#define USE_SELECTION_FG', '#define DONT_USE_SELECTION_FG') + ff = ff.replace('#define USE_SELECTION_FG', '#define DONT_USE_SELECTION_FG') compile_program(p, vv, ff) v, f = load_shaders('graphics') for which, p in { @@ -90,14 +93,18 @@ def load_shader_programs(semi_transparent=0): init_cell_program() +load_shader_programs.use_selection_fg = True + + def setup_colors(screen, opts): screen.color_profile.update_ansi_color_table(build_ansi_color_table(opts)) cursor_text_color = opts.cursor_text_color or (12, 12, 12) cursor_text_color_as_bg = 3 if opts.cursor_text_color is None else 1 + sfg = (0, 0, 0) if opts.selection_foreground is None else opts.selection_foreground screen.color_profile.set_configured_colors(*map(color_as_int, ( opts.foreground, opts.background, opts.cursor, cursor_text_color, (0, 0, cursor_text_color_as_bg), - opts.selection_foreground, opts.selection_background) + sfg, opts.selection_background) ))