kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.83k stars 995 forks source link

When setting a transparent_background_color without an opacity via set_colors, the color is transparent #7912

Closed rivenirvana closed 2 months ago

rivenirvana commented 2 months ago

Describe the bug Setting transparent_background_colors in the main kitty.conf with or without an opacity parameter works, but when setting it without an opacity parameter in a separate conf file that set_colors reads via boss.call_remote_control, the color becomes fully transparent instead of taking the set background_opacity value in kitty.conf

kovidgoyal commented 2 months ago

I dont quite follow, set_colors doesnt read anything via boss.remote_control_command and as far as I know

kitten @ set-colors transparent_background_colors=#2d2d2d@0.5

works fine. Are you saying running the above without the @0.5 will cause the color to become full transparent? Because I cannot replicate that.

rivenirvana commented 2 months ago

Version: kitty v0.36.4-2-g76cd68760 (from git-describe)

relevant configs in kitty.conf (for posterity)

include current-theme.conf # <- Default theme
background_opacity 0.9
watcher scripts/editor-setup.py

.config/nvim/lua/autocommands.lua


vim.api.nvim_create_autocmd({ 'VimEnter', 'VimResume' }, {
group = vim.api.nvim_create_augroup('KittySetVarVimEnter', { clear = true }),
callback = function()
io.stdout:write '\x1b]30001\x1b\\' -- save colors, watcher sets different colors after variable set
io.stdout:write '\x1b]1337;SetUserVar=KITTY_IN_NVIM=MQ==\007'
end,
})

vim.api.nvim_create_autocmd({ 'VimLeave', 'VimSuspend' }, { group = vim.api.nvim_create_augroup('KittyUnsetVarVimLeave', { clear = true }), callback = function() io.stdout:write '\x1b]1337;SetUserVar=KITTY_IN_NVIM\007' io.stdout:write '\x1b]30101\x1b\' -- restore colors end, })

> .config/kitty/scripts/editor-setup.py
```py
from typing import Any, Dict

from kitty.boss import Boss
from kitty.window import Window

def on_set_user_var(boss: Boss, window: Window, data: Dict[str, Any]) -> None:
    key, val = data["key"], data["value"]
    match key:
        case "KITTY_IN_NVIM":
            if val is not None:
                boss.call_remote_control(window, ("disable_ligatures", "cursor"))
                boss.call_remote_control(window, ("set-colors", "~/.config/kitty/editor-theme.conf")) # <- relevant part
            else:
                boss.call_remote_control(window, ("disable_ligatures", "always"))
                # not relying on set-colors --reset because it restores colors on all windows, not individual ones

.config/kitty/editor-theme.conf

include Tokyo Night.conf
# cursorline color <= not setting an opacity parameter makes color fully transparent; works correctly otherwise
# issue is here; I see that rc/set_colors.py parses this conf if I'm reading this correctly
# https://github.com/kovidgoyal/kitty/blob/76cd68760afce34f3abde65ae8bcad270d05d347/kitty/rc/set_colors.py#L41
transparent_background_colors #292e42

.config/kitty/Tokyo Night.conf <- just dumped from kitten-themes, can ignore


# vim:ft=kitty

name: Tokyo Night

license: MIT

author: Folke Lemaitre

upstream: https://github.com/folke/tokyonight.nvim/raw/main/extras/kitty/tokyonight_night.conf

background #1a1b26 foreground #c0caf5 selection_background #283457 selection_foreground #c0caf5 url_color #73daca cursor #c0caf5 cursor_text_color #1a1b26

Tabs

active_tab_background #7aa2f7 #\

active_tab_foreground #16161e #|

inactive_tab_background #292e42 #|

inactive_tab_foreground #545c7e #|

tab_bar_background #15161e #|

                                #-> disabled because not saved/restored by color control code but set-colors recognizes & changes them

Windows #|

active_border_color #7aa2f7 #|

inactive_border_color #292e42 #/

normal

color0 #15161e color1 #f7768e color2 #9ece6a color3 #e0af68 color4 #7aa2f7 color5 #bb9af7 color6 #7dcfff color7 #a9b1d6

bright

color8 #414868 color9 #f7768e color10 #9ece6a color11 #e0af68 color12 #7aa2f7 color13 #bb9af7 color14 #7dcfff color15 #c0caf5

extended colors

color16 #ff9e64 color17 #db4b4b



**Screenshots**
- When opacity parameter is not set (transparent instead of using `background_opacity` value): `transparent_background_colors #292e42`

![image](https://github.com/user-attachments/assets/5950ea33-b1ba-47b6-b281-d791b5528fc1)

- When opacity parameter is set (cursorline has proper opacity):  `transparent_background_colors #292e42@0.9`

![image](https://github.com/user-attachments/assets/e94af223-fb2a-4aea-b634-f11bf55eadab)