From 08d74a6c5651967a31b24cbc11aa71bc5747401a Mon Sep 17 00:00:00 2001 From: pagedown Date: Mon, 21 Nov 2022 12:21:06 +0800 Subject: [PATCH] Add an option to control background image tinting for window gaps --- docs/changelog.rst | 3 +++ kitty/options/definition.py | 10 +++++++++- kitty/options/parse.py | 3 +++ kitty/options/to-c-generated.h | 15 +++++++++++++++ kitty/options/types.py | 2 ++ kitty/shaders.c | 2 +- kitty/state.h | 2 +- 7 files changed, 34 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 9895beedd..54018af3e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -49,6 +49,9 @@ Detailed list of changes - Implement :ref:`edit-in-kitty ` using the new ``kitty-tool`` static executable (:iss:`5546`, :iss:`5630`) +- Add an option :opt:`background_tint_gaps` to control background image tinting for window gaps (:iss:`5596`) + + 0.26.5 [2022-11-07] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/options/definition.py b/kitty/options/definition.py index d2bf84f4e..2dfcff8a2 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -1313,13 +1313,21 @@ this option by reloading the config is not supported. opt('background_tint', '0.0', option_type='unit_float', ctype='float', long_text=''' -How much to tint the background image by the background color. This option +How much to tint the background image by the background color. This option makes it easier to read the text. Tinting is done using the current background color for each window. This option applies only if :opt:`background_opacity` is set and transparent windows are supported or :opt:`background_image` is set. ''' ) +opt('background_tint_gaps', '1.0', + option_type='unit_float', ctype='float', + long_text=''' +How much to tint the background image at the window gaps by the background +color, after applying :opt:`background_tint`. +''' + ) + opt('dim_opacity', '0.75', option_type='unit_float', ctype='float', long_text=''' diff --git a/kitty/options/parse.py b/kitty/options/parse.py index 4dfcf507e..1ac736bbe 100644 --- a/kitty/options/parse.py +++ b/kitty/options/parse.py @@ -84,6 +84,9 @@ class Parser: def background_tint(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: ans['background_tint'] = unit_float(val) + def background_tint_gaps(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: + ans['background_tint_gaps'] = unit_float(val) + def bell_border_color(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: ans['bell_border_color'] = to_color(val) diff --git a/kitty/options/to-c-generated.h b/kitty/options/to-c-generated.h index 60a6d1d45..b2e61caae 100644 --- a/kitty/options/to-c-generated.h +++ b/kitty/options/to-c-generated.h @@ -772,6 +772,19 @@ convert_from_opts_background_tint(PyObject *py_opts, Options *opts) { Py_DECREF(ret); } +static void +convert_from_python_background_tint_gaps(PyObject *val, Options *opts) { + opts->background_tint_gaps = PyFloat_AsFloat(val); +} + +static void +convert_from_opts_background_tint_gaps(PyObject *py_opts, Options *opts) { + PyObject *ret = PyObject_GetAttrString(py_opts, "background_tint_gaps"); + if (ret == NULL) return; + convert_from_python_background_tint_gaps(ret, opts); + Py_DECREF(ret); +} + static void convert_from_python_dim_opacity(PyObject *val, Options *opts) { opts->dim_opacity = PyFloat_AsFloat(val); @@ -1126,6 +1139,8 @@ convert_opts_from_python_opts(PyObject *py_opts, Options *opts) { if (PyErr_Occurred()) return false; convert_from_opts_background_tint(py_opts, opts); if (PyErr_Occurred()) return false; + convert_from_opts_background_tint_gaps(py_opts, opts); + if (PyErr_Occurred()) return false; convert_from_opts_dim_opacity(py_opts, opts); if (PyErr_Occurred()) return false; convert_from_opts_mark1_foreground(py_opts, opts); diff --git a/kitty/options/types.py b/kitty/options/types.py index f01b4c332..4c97e4437 100644 --- a/kitty/options/types.py +++ b/kitty/options/types.py @@ -63,6 +63,7 @@ option_names = ( # {{{ 'background_image_linear', 'background_opacity', 'background_tint', + 'background_tint_gaps', 'bell_border_color', 'bell_on_tab', 'bell_path', @@ -476,6 +477,7 @@ class Options: background_image_linear: bool = False background_opacity: float = 1.0 background_tint: float = 0 + background_tint_gaps: float = 1.0 bell_border_color: Color = Color(255, 90, 0) bell_on_tab: str = '🔔 ' bell_path: typing.Optional[str] = None diff --git a/kitty/shaders.c b/kitty/shaders.c index 17c41866e..90a7f9b53 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -980,7 +980,7 @@ draw_borders(ssize_t vao_idx, unsigned int num_border_rects, BorderRect *rect_bu draw_bg(w); BLEND_ONTO_OPAQUE; background_opacity = 1.0f; - tint_opacity = OPT(background_tint); + tint_opacity = OPT(background_tint) * OPT(background_tint_gaps); tint_premult = w->is_semi_transparent ? OPT(background_tint) : 1.0f; } diff --git a/kitty/state.h b/kitty/state.h index 895225338..06939acf2 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -52,7 +52,7 @@ typedef struct { BackgroundImageLayout background_image_layout; ImageAnchorPosition window_logo_position; bool background_image_linear; - float background_tint, window_logo_alpha; + float background_tint, background_tint_gaps, window_logo_alpha; bool dynamic_background_opacity; float inactive_text_alpha;