Skip to content

Commit

Permalink
Make foreground opacity configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
quantum5 committed Dec 27, 2020
1 parent 209bdb0 commit 4f04437
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions kitty/cell_vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// Inputs {{{
layout(std140) uniform CellRenderData {
float xstart, ystart, dx, dy, sprite_dx, sprite_dy, background_opacity, cursor_text_uses_bg;
float xstart, ystart, dx, dy, sprite_dx, sprite_dy, background_opacity, foreground_opacity, cursor_text_uses_bg;

uint default_fg, default_bg, highlight_fg, highlight_bg, cursor_color, cursor_text_color, url_color, url_style, inverted;

Expand Down Expand Up @@ -184,7 +184,7 @@ void main() {
fg_as_uint = has_mark * color_table[NUM_COLORS + MARK_MASK + 1 + mark] + (ONE - has_mark) * fg_as_uint;
foreground = color_to_vec(fg_as_uint);
float has_dim = float((text_attrs >> DIM_SHIFT) & ONE);
effective_text_alpha = inactive_text_alpha * mix(1.0, dim_opacity, has_dim);
effective_text_alpha = foreground_opacity * inactive_text_alpha * mix(1.0, dim_opacity, has_dim);
float in_url = float((is_selected & TWO) >> 1);
decoration_fg = choose_color(in_url, color_to_vec(url_color), to_color(colors[2], fg_as_uint));
#ifdef USE_SELECTION_FG
Expand Down
5 changes: 5 additions & 0 deletions kitty/config_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,11 @@ def active_tab_title_template(x: str) -> Optional[str]:
default as it has a performance cost)
'''))

o('foreground_opacity', 1.0, option_type=unit_float, long_text=_('''
The opacity of the foreground. A number between 0 and 1, where 1 is opaque and
0 is fully transparent. This has similar constraints to :opt:`background_opacity`
'''))


def config_or_absolute_path(x: str) -> Optional[str]:
if x.lower() == 'none':
Expand Down
3 changes: 2 additions & 1 deletion kitty/shaders.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ send_graphics_data_to_gpu(size_t image_count, ssize_t gvao_idx, const ImageRende
static inline void
cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, GLfloat xstart, GLfloat ystart, GLfloat dx, GLfloat dy, CursorRenderInfo *cursor, bool inverted, OSWindow *os_window) {
struct CellRenderData {
GLfloat xstart, ystart, dx, dy, sprite_dx, sprite_dy, background_opacity, cursor_text_uses_bg;
GLfloat xstart, ystart, dx, dy, sprite_dx, sprite_dy, background_opacity, foreground_opacity, cursor_text_uses_bg;

GLuint default_fg, default_bg, highlight_fg, highlight_bg, cursor_color, cursor_text_color, url_color, url_style, inverted;

Expand Down Expand Up @@ -295,6 +295,7 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, G
rd->sprite_dx = 1.0f / (float)x; rd->sprite_dy = 1.0f / (float)y;
rd->inverted = inverted ? 1 : 0;
rd->background_opacity = os_window->is_semi_transparent ? os_window->background_opacity : 1.0f;
rd->foreground_opacity = os_window->is_semi_transparent ? OPT(foreground_opacity) : 1.0f;

#define COLOR(name) colorprofile_to_color(screen->color_profile, screen->color_profile->overridden.name, screen->color_profile->configured.name)
rd->default_fg = COLOR(default_fg); rd->default_bg = COLOR(default_bg); rd->highlight_fg = COLOR(highlight_fg); rd->highlight_bg = COLOR(highlight_bg);
Expand Down
1 change: 1 addition & 0 deletions kitty/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ PYWRAP1(set_options) {
S(background_image_layout, bglayout);
S(background_tint, PyFloat_AsFloat);
S(background_image_linear, PyObject_IsTrue);
S(foreground_opacity, PyFloat_AsFloat);
S(dim_opacity, PyFloat_AsFloat);
S(dynamic_background_opacity, PyObject_IsTrue);
S(inactive_text_alpha, PyFloat_AsFloat);
Expand Down
2 changes: 1 addition & 1 deletion kitty/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef struct {
WindowTitleIn macos_show_window_title_in;
int adjust_line_height_px, adjust_column_width_px;
float adjust_line_height_frac, adjust_column_width_frac;
float background_opacity, dim_opacity;
float background_opacity, foreground_opacity, dim_opacity;

char* background_image;
BackgroundImageLayout background_image_layout;
Expand Down

0 comments on commit 4f04437

Please sign in to comment.