From 6aabd593d71838770d8de4b5c389efd34329eed1 Mon Sep 17 00:00:00 2001 From: Ramojus Lapinskas Date: Sat, 10 Aug 2024 15:18:55 +0300 Subject: [PATCH] feat(config): add lightness option for transparent bg --- lua/mellifluous/colors/init.lua | 3 +++ lua/mellifluous/colors/shades.lua | 21 +++++++++++---------- lua/mellifluous/config.lua | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/lua/mellifluous/colors/init.lua b/lua/mellifluous/colors/init.lua index b6b9c8b..7290cb2 100644 --- a/lua/mellifluous/colors/init.lua +++ b/lua/mellifluous/colors/init.lua @@ -112,6 +112,9 @@ function M.get_colors() colors = apply_color_overrides(colors) ensure_correct_color_types(colors) + if config.transparent_background and config.transparent_background.lightness and type(config.transparent_background.lightness) == "function" then + colors.bg = colors.bg:with_lightness(config.transparent_background.lightness(colors.bg)) + end colors = require("mellifluous.colors.shades").extend_with_shades(colors) diff --git a/lua/mellifluous/colors/shades.lua b/lua/mellifluous/colors/shades.lua index 5c5085e..0cc1e2b 100644 --- a/lua/mellifluous/colors/shades.lua +++ b/lua/mellifluous/colors/shades.lua @@ -14,6 +14,7 @@ function M.extend_with_shades(colors) local shades = {} local fg = colors.shades_fg or colors.fg + local bg = colors.bg if config.is_bg_dark then shades = { @@ -21,11 +22,11 @@ function M.extend_with_shades(colors) fg3 = fg:darkened(32), fg4 = fg:darkened(48), fg5 = fg:darkened(54), - dark_bg = colors.bg:darkened(2.5), - bg2 = colors.bg:lightened(4), - bg3 = colors.bg:lightened(6), - bg4 = colors.bg:lightened(8), - bg5 = colors.bg:lightened(10), + dark_bg = bg:darkened(2.5), + bg2 = bg:lightened(4), + bg3 = bg:lightened(6), + bg4 = bg:lightened(8), + bg5 = bg:lightened(10), } else shades = { @@ -33,11 +34,11 @@ function M.extend_with_shades(colors) fg3 = fg:lightened(32), fg4 = fg:lightened(48), fg5 = fg:lightened(54), - dark_bg2 = colors.bg:darkened(8), - dark_bg = colors.bg:darkened(2.5), - bg2 = colors.bg:lightened(4), - bg3 = colors.bg:lightened(6), - bg4 = colors.bg:lightened(8), + dark_bg2 = bg:darkened(8), + dark_bg = bg:darkened(2.5), + bg2 = bg:lightened(4), + bg3 = bg:lightened(6), + bg4 = bg:lightened(8), } end diff --git a/lua/mellifluous/config.lua b/lua/mellifluous/config.lua index 10623ab..c040a95 100644 --- a/lua/mellifluous/config.lua +++ b/lua/mellifluous/config.lua @@ -45,6 +45,25 @@ local function get_default_config() }, transparent_background = { enabled = false, + lightness = function(bg) -- used for bg shades + -- This method tries to keep brighter colorsets bright and + -- dimmer colorsets dim and still lighten the shades up so that + -- the colorsets have more chance to look good with transparent + -- background on brighter wallpapers. + local old_lightness = bg:get_hsl().l + local threshold = 20 + local baseline = 10 + if old_lightness < threshold then + -- We will assume that the dimmest of transparent + -- background over users wallpaper is at least of baseline + -- lightness. Presuming old range is [0, threshold], let's + -- position the lightness relatively in a new range of + -- [baseline, threshold]. + local position = old_lightness / threshold + local new_lightness = baseline + ((threshold - baseline) * position) + return new_lightness + end + end, floating_windows = true, telescope = true, file_tree = true,