Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add backdrop #1759

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ local DEFAULT_SETTINGS = {
-- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
border = "none",

-- The backdrop opacity. 0 is fully opaque, 100 is fully transparent.
backdrop = 100,

---@since 1.0.0
-- Width of the window. Accepts:
-- - Integer greater than 1 for fixed width.
Expand Down
3 changes: 3 additions & 0 deletions doc/mason.txt
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ Example:
-- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
border = "none",

-- The backdrop opacity. 0 is fully opaque, 100 is fully transparent.
backdrop = 100,

---@since 1.0.0
-- Width of the window. Accepts:
-- - Integer greater than 1 for fixed width.
Expand Down
36 changes: 35 additions & 1 deletion lua/mason-core/ui/display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ end
---@param filetype string
function M.new_view_only_win(name, filetype)
local namespace = vim.api.nvim_create_namespace(("installer_%s"):format(name))
local bufnr, renderer, mutate_state, get_state, unsubscribe, win_id, window_mgmt_augroup, autoclose_augroup, registered_keymaps, registered_keybinds, registered_effect_handlers, sticky_cursor
local bufnr, backdrop_bufnr, renderer, mutate_state, get_state, unsubscribe, win_id, backdrop_win_id, window_mgmt_augroup, autoclose_augroup, registered_keymaps, registered_keybinds, registered_effect_handlers, sticky_cursor
local has_initiated = false
---@type WindowOpts
local window_opts = {}
Expand Down Expand Up @@ -239,6 +239,14 @@ function M.new_view_only_win(name, filetype)
log.trace "Deleting buffer"
vim.api.nvim_buf_delete(bufnr, { force = true })
end
if backdrop_win_id and vim.api.nvim_win_is_valid(backdrop_win_id) then
log.trace "Deleting backdrop window"
vim.api.nvim_win_close(backdrop_win_id, true)
end
if backdrop_bufnr and vim.api.nvim_buf_is_valid(backdrop_bufnr) then
log.trace "Deleting backdrop buffer"
vim.api.nvim_buf_delete(backdrop_bufnr, { force = true })
end
end)
end

Expand Down Expand Up @@ -371,6 +379,32 @@ function M.new_view_only_win(name, filetype)
bufnr = vim.api.nvim_create_buf(false, true)
win_id = vim.api.nvim_open_win(bufnr, true, create_popup_window_opts(window_opts, false))

backdrop_bufnr = vim.api.nvim_create_buf(false, true)
backdrop_win_id = vim.api.nvim_open_win(backdrop_bufnr, false, {
relative = "editor",
width = vim.o.columns,
height = vim.o.lines,
row = 0,
col = 0,
style = "minimal",
focusable = false,
zindex = 44,
})

local wo = function(win, k, v)
if vim.api.nvim_set_option_value then
vim.api.nvim_set_option_value(k, v, { scope = "local", win = win })
else
vim.wo[win][k] = v
end
end

vim.api.nvim_set_hl(0, "MasonBackdrop", { bg = "#000000", default = true })
wo(backdrop_win_id, "winhighlight", "Normal:MasonBackdrop")
wo(backdrop_win_id, "winblend", settings.current.ui.backdrop)
vim.bo[backdrop_bufnr].buftype = "nofile"
vim.bo[backdrop_bufnr].filetype = "mason_backdrop"

vim.api.nvim_create_autocmd("CmdLineEnter", {
buffer = bufnr,
callback = function()
Expand Down
3 changes: 3 additions & 0 deletions lua/mason/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ local DEFAULT_SETTINGS = {
-- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
border = "none",

-- The backdrop opacity. 0 is fully opaque, 100 is fully transparent.
backdrop = 100,

---@since 1.0.0
-- Width of the window. Accepts:
-- - Integer greater than 1 for fixed width.
Expand Down