Make background_image tint useable even without a background image in a transparent window

This commit is contained in:
Kovid Goyal 2020-02-02 12:40:29 +05:30
parent ab2c901e85
commit 0830fc3b5a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 16 additions and 11 deletions

View File

@ -13,6 +13,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- Add support for specifying a background image, see :opt:`background_image` - Add support for specifying a background image, see :opt:`background_image`
(:iss:`163` and :pull:`2326`) (:iss:`163` and :pull:`2326`)
- A new :opt:`background_tint` option to darken the background under the text
area when using background images and/or transparent windows.
0.16.0 [2020-01-28] 0.16.0 [2020-01-28]

View File

@ -864,12 +864,6 @@ Path to a background image. Must be in PNG format.'''))
o('background_image_layout', 'tiled', option_type=choices('tiled', 'scaled', 'mirror-tiled'), long_text=_(''' o('background_image_layout', 'tiled', option_type=choices('tiled', 'scaled', 'mirror-tiled'), long_text=_('''
Whether to tile or scale the background image.''')) Whether to tile or scale the background image.'''))
o('background_image_tint', 0.5, option_type=unit_float, long_text=_('''
How much to tint the background image by the background area. The tint is applied
only under the text area, not margin/borders. Makes it easier to read the text.
Tinting is done using the current background color for each window.
'''))
o('background_image_linear', False, long_text=_(''' o('background_image_linear', False, long_text=_('''
When background image is scaled, whether linear interpolation should be used.''')) When background image is scaled, whether linear interpolation should be used.'''))
@ -879,6 +873,14 @@ shortcuts (:sc:`increase_background_opacity` and :sc:`decrease_background_opacit
or the remote control facility. or the remote control facility.
''')) '''))
o('background_tint', 0.0, option_type=unit_float, long_text=_('''
How much to tint the background image by the background color. The tint is applied
only under the text area, not margin/borders. Makes it easier to read the text.
Tinting is done using the current background color for each window. This setting
applies only if :opt:`background_opacity` is set and transparent windows are supported
or :opt:`background_image` is set.
'''))
o('dim_opacity', 0.75, option_type=unit_float, long_text=_(''' 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 How much to dim text that has the DIM/FAINT attribute set. One means no dimming and
zero means fully dimmed (i.e. invisible).''')) zero means fully dimmed (i.e. invisible).'''))

View File

@ -446,7 +446,7 @@ draw_tint(bool premult, Screen *screen, GLfloat xstart, GLfloat ystart, GLfloat
bind_program(TINT_PROGRAM); bind_program(TINT_PROGRAM);
color_type window_bg = colorprofile_to_color(screen->color_profile, screen->color_profile->overridden.default_bg, screen->color_profile->configured.default_bg); color_type window_bg = colorprofile_to_color(screen->color_profile, screen->color_profile->overridden.default_bg, screen->color_profile->configured.default_bg);
#define C(shift) ((((GLfloat)((window_bg >> shift) & 0xFF)) / 255.0f)) #define C(shift) ((((GLfloat)((window_bg >> shift) & 0xFF)) / 255.0f))
float alpha = OPT(background_image_tint); float alpha = OPT(background_tint);
if (premult) glUniform4f(tint_program_layout.tint_color_location, C(16) * alpha, C(8) * alpha, C(0) * alpha, alpha); if (premult) glUniform4f(tint_program_layout.tint_color_location, C(16) * alpha, C(8) * alpha, C(0) * alpha, alpha);
else glUniform4f(tint_program_layout.tint_color_location, C(16), C(8), C(0), alpha); else glUniform4f(tint_program_layout.tint_color_location, C(16), C(8), C(0), alpha);
#undef C #undef C
@ -464,7 +464,7 @@ draw_cells_interleaved(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen, OSWind
bind_program(CELL_BG_PROGRAM); bind_program(CELL_BG_PROGRAM);
glUniform1ui(cell_program_layouts[CELL_BG_PROGRAM].draw_bg_bitfield_location, 3); glUniform1ui(cell_program_layouts[CELL_BG_PROGRAM].draw_bg_bitfield_location, 3);
glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, screen->lines * screen->columns); glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, screen->lines * screen->columns);
} else if (OPT(background_image_tint) > 0) draw_tint(false, screen, xstart, ystart, width, height); } else if (OPT(background_tint) > 0) draw_tint(false, screen, xstart, ystart, width, height);
if (screen->grman->num_of_below_refs || has_bgimage(w)) { if (screen->grman->num_of_below_refs || has_bgimage(w)) {
if (screen->grman->num_of_below_refs) draw_graphics( if (screen->grman->num_of_below_refs) draw_graphics(
@ -490,7 +490,7 @@ draw_cells_interleaved(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen, OSWind
static void static void
draw_cells_interleaved_premult(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen, OSWindow *os_window, GLfloat xstart, GLfloat ystart, GLfloat width, GLfloat height) { draw_cells_interleaved_premult(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen, OSWindow *os_window, GLfloat xstart, GLfloat ystart, GLfloat width, GLfloat height) {
if (has_bgimage(os_window) && OPT(background_image_tint) > 0.f) { if (OPT(background_tint) > 0.f) {
glEnable(GL_BLEND); glEnable(GL_BLEND);
BLEND_PREMULT; BLEND_PREMULT;
draw_tint(true, screen, xstart, ystart, width, height); draw_tint(true, screen, xstart, ystart, width, height);

View File

@ -560,7 +560,7 @@ PYWRAP1(set_options) {
S(cursor_stop_blinking_after, parse_s_double_to_monotonic_t); S(cursor_stop_blinking_after, parse_s_double_to_monotonic_t);
S(background_opacity, PyFloat_AsFloat); S(background_opacity, PyFloat_AsFloat);
S(background_image_layout, bglayout); S(background_image_layout, bglayout);
S(background_image_tint, PyFloat_AsFloat); S(background_tint, PyFloat_AsFloat);
S(background_image_linear, PyObject_IsTrue); S(background_image_linear, PyObject_IsTrue);
S(dim_opacity, PyFloat_AsFloat); S(dim_opacity, PyFloat_AsFloat);
S(dynamic_background_opacity, PyObject_IsTrue); S(dynamic_background_opacity, PyObject_IsTrue);

View File

@ -42,7 +42,7 @@ typedef struct {
char* background_image; char* background_image;
BackgroundImageLayout background_image_layout; BackgroundImageLayout background_image_layout;
bool background_image_linear; bool background_image_linear;
float background_image_tint; float background_tint;
bool dynamic_background_opacity; bool dynamic_background_opacity;
float inactive_text_alpha; float inactive_text_alpha;