Skip to content

Commit 40c2012

Browse files
committed
Support negative inactive_text_alpha values for active-window-only fading
1 parent 7bb73a3 commit 40c2012

5 files changed

Lines changed: 30 additions & 8 deletions

File tree

kitty/conf/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ def unit_float(x: ConvertibleToNumbers) -> float:
6767
return max(0, min(float(x), 1))
6868

6969

70+
def signed_unit_float(x: ConvertibleToNumbers) -> float:
71+
return max(-1, min(float(x), 1))
72+
73+
7074
def number_with_unit(x: str, default_unit: str, *extra_units: str) -> tuple[float, str]:
7175
if (mat := number_unit_pat.match(x)) is not None:
7276
try:

kitty/options/definition.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,10 +1397,13 @@
13971397
)
13981398

13991399
opt('inactive_text_alpha', '1.0',
1400-
option_type='unit_float', ctype='float',
1400+
option_type='signed_unit_float', ctype='float',
14011401
long_text='''
1402-
Fade the text in inactive windows by the specified amount (a number between zero
1403-
and one, with zero being fully faded).
1402+
Fade the text in inactive windows by the specified amount. This must be a
1403+
number between negative one and one. The absolute value controls the actual
1404+
opacity, with zero being fully faded and one being fully opaque. Negative
1405+
values cause fading to be applied based only on whether the current window is
1406+
active, ignoring the extra single-window unfocused case.
14041407
'''
14051408
)
14061409

kitty/options/parse.py

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kitty/shaders.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,9 +1405,15 @@ draw_cells(const WindowRenderData *srd, OSWindow *os_window, bool is_active_wind
14051405
bind_vertex_array(srd->vao_idx);
14061406
// We draw with inactive text alpha if:
14071407
// - We're not drawing the tab bar
1408-
// - There's only a single window and the os window is not focused
14091408
// - There are multiple windows and the current window is not active
1410-
float current_inactive_text_alpha = is_tab_bar || (!is_single_window && is_active_window) || (is_single_window && screen->cursor_render_info.is_focused) ? 1.0f : (float)OPT(inactive_text_alpha);
1409+
// When inactive_text_alpha is negative, its absolute value is used as the
1410+
// opacity and fading is based only on whether the current window is active.
1411+
float configured_inactive_text_alpha = (float)OPT(inactive_text_alpha);
1412+
bool use_active_window_only = configured_inactive_text_alpha < 0.f;
1413+
if (configured_inactive_text_alpha < 0.f) configured_inactive_text_alpha = -configured_inactive_text_alpha;
1414+
float current_inactive_text_alpha = use_active_window_only ?
1415+
(is_tab_bar || is_active_window ? 1.0f : configured_inactive_text_alpha) :
1416+
(is_tab_bar || (!is_single_window && is_active_window) || (is_single_window && screen->cursor_render_info.is_focused) ? 1.0f : configured_inactive_text_alpha);
14111417
float bg_alpha = effective_os_window_alpha(os_window);
14121418

14131419
color_type default_bg = cell_update_uniform_block(

kitty_tests/options.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,15 @@ def ac(which=0):
311311
self.ae(opts.kitty_mod, to_modifiers('alt'))
312312
self.ae(next(keys_for_func(opts, 'next_layout')).mods, opts.kitty_mod)
313313

314+
opts = p('inactive_text_alpha 0.25')
315+
self.ae(opts.inactive_text_alpha, 0.25)
316+
opts = p('inactive_text_alpha -0.25')
317+
self.ae(opts.inactive_text_alpha, -0.25)
318+
opts = p('inactive_text_alpha 2')
319+
self.ae(opts.inactive_text_alpha, 1.0)
320+
opts = p('inactive_text_alpha -2')
321+
self.ae(opts.inactive_text_alpha, -1.0)
322+
314323
# deprecation handling
315324
opts = p('clear_all_shortcuts y', 'send_text all f1 hello')
316325
self.ae(len(opts.keyboard_modes[''].keymap), 1)

0 commit comments

Comments
 (0)