From 21089ade5d94710b878bc03a4aed133f4be7480a Mon Sep 17 00:00:00 2001 From: Ramojus Lapinskas <41536253+ramojus@users.noreply.github.com> Date: Sat, 2 Nov 2024 13:26:30 +0200 Subject: [PATCH] feat(config): add lightness option for transparent bg (#75) The background usually becomes lighter when transparent background is enabled. The default is something that works relatively well for the types of wallpapers that I use, while still preserving the style and readability of the colorset quite well. --- lua/mellifluous/colors/init.lua | 7 +++++++ lua/mellifluous/config.lua | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lua/mellifluous/colors/init.lua b/lua/mellifluous/colors/init.lua index b6b9c8b..eab66f0 100644 --- a/lua/mellifluous/colors/init.lua +++ b/lua/mellifluous/colors/init.lua @@ -112,6 +112,13 @@ 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/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,