Add a dim inactive windows custom shader

This commit is contained in:
Kovid Goyal 2026-08-11 09:34:43 +05:30
parent 3705a7fcd1
commit f9acc18553
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
4 changed files with 19 additions and 7 deletions

View file

@ -1795,7 +1795,8 @@ used the text is faded even if only a single window is visible when the OS windo
is not focused. Negative numbers means that text is only faded when more than one kitty window
is visible in an OS Window. Fading happens in all but the active window, even if the OS Window
is not focused. Thus this is useful if you want to rely on the window manager to indicate OS Window focus
and this feature to indicate which kitty window is active insidethe OS Window.
and this feature to indicate which kitty window is active inside the OS Window. For alternate dimming/highlighting
strategies, you can use :opt:`custom_shaders` for example: :code:`custom_shaders dim-inactive-windows`.
""",
)

View file

@ -149,10 +149,10 @@ metadata: dict[str, dict[str, Any]] = {
'cursor-trail-blaze': {'animate': cursor_trail, 'category': 'cursor-trail', 'tagline': 'Set your cursor on fire as it moves around.'},
'cursor-trail-lightning': {'animate': cursor_trail, 'category': 'cursor-trail', 'tagline': 'Make your cursor shoot lightning as it moves around.'},
# Navigation
'focus-highlight': {
'dim-inactive-windows': {
'animate': window_focus,
'category': 'navigation',
'tagline': 'Highlight the active window on focus change.',
'tagline': 'Make the active window standout more.',
'session': 'launch kitten run-shell ls -l\nlaunch kitten run-shell bat -P setup.py\nlaunch kitten run-shell echo Hello World',
},
'tab-change': {
@ -161,6 +161,12 @@ metadata: dict[str, dict[str, Any]] = {
'tagline': 'Highlight the active window on focus change.',
'session': 'new_tab My Shell\nlaunch kitten run-shell ls\nnew_tab My Code\nlaunch nvim -R {self}',
},
'focus-highlight': {
'animate': window_focus,
'category': 'navigation',
'tagline': 'Briefly highlight the active window on focus change.',
'session': 'launch kitten run-shell ls -l\nlaunch kitten run-shell bat -P setup.py\nlaunch kitten run-shell echo Hello World',
},
# Retro terminals
'crt': {'category': 'retro', 'title': 'Cathode Ray Tube', 'tagline': 'Your terminal deserves to have curves.', 'duration': 2},
'crt-blue': {'category': 'retro', 'title': 'CRT Blue', 'tagline': 'Do you have the blues?', 'duration': 2},

View file

@ -0,0 +1,5 @@
startgroup
var float HIGHLIGHT_INTENSITY = 0
var float BORDER_WIDTH = 0
shaders focus-highlight
endgroup

View file

@ -35,6 +35,7 @@ fragment_main(float4 color, KittyTextures t, KittyCustomShaderData d) {
bool inWindow = all(uv >= winMin) && all(uv <= winMax);
if (inWindow) {
if (HIGHLIGHT_INTENSITY == 0 && BORDER_WIDTH == 0) return color;
// Minimum distance from this pixel to any edge of the active window.
float2 edgeDists = min(uv - winMin, winMax - uv);
float nearestEdge = min(edgeDists.x, edgeDists.y);
@ -44,9 +45,8 @@ fragment_main(float4 color, KittyTextures t, KittyCustomShaderData d) {
float boost = (HIGHLIGHT_INTENSITY + borderGlow) * strength;
return float4(color.rgb * (1.0 + boost), color.a);
} else {
// Slightly dim inactive areas to draw the eye to the focused window.
float dim = lerp(1.0, INACTIVE_DIM, strength);
return float4(color.rgb * dim, color.a);
}
// Slightly dim inactive areas to draw the eye to the focused window.
float dim = lerp(1.0, INACTIVE_DIM, strength);
return float4(color.rgb * dim, color.a);
}