Can we add a gap between stacked notifier popups? #2169
Answered by
drowning-cat
Sep 7, 2025
Replies: 2 comments 2 replies
|
Now built into Previous messageI think it can be done better. I’m not sure how to hook up before the layout changes. notifier = {
---@param buf integer
---@param notif snacks.notifier.Notif
---@param ctx snacks.notifier.ctx
style = function(buf, notif, ctx)
local render = ctx.notifier:get_render 'compact'
render(buf, notif, ctx)
vim.schedule(function()
notif.layout.top = notif.layout.top + 1
ctx.notifier:process()
end)
end,
}, |
2 replies
Answer selected by
kaihocd
Hide
---@param self snacks.notifier.Class
---@param gap integer
local gap_layout = function(self, gap)
local uv = vim.uv or vim.loop
-- https://github.com/folke/snacks.nvim/blob/5d9dacd09876eed33bde204d224fa7596ac850e8/lua/snacks/notifier.lua#L261-L268
local function ts()
if uv.clock_gettime then
local ret = assert(uv.clock_gettime 'realtime')
return ret.sec + ret.nsec / 1e9
end
local sec, usec = uv.gettimeofday()
return sec + usec / 1e6
end
-- https://github.com/folke/snacks.nvim/blob/5d9dacd09876eed33bde204d224fa7596ac850e8/lua/snacks/notifier.lua#L671-L724
local layout = self:new_layout()
local wins_updated = 0
local wins_created = 0
local update = {} ---@type snacks.win[]
for _, notif in ipairs(assert(self.sorted)) do
if layout.free < (self.opts.height.min + 2) then -- not enough space
if notif.win then
notif.shown = nil
notif.win:hide()
end
else
local prev_layout = notif.layout and { top = notif.layout.top, height = notif.layout.height, width = notif.layout.width }
if not notif.win or notif.dirty or not notif.win:buf_valid() or type(notif.opts) == 'function' then
notif.dirty = true
self:render(notif)
notif.dirty = false
notif.layout = notif.win:size()
notif.layout.top = prev_layout and prev_layout.top
prev_layout = nil -- always re-render since opts might've changed
end
notif.layout.top = layout.find(notif.layout.height, notif.layout.top)
if notif.layout.top then
-- NOTE: Changed from
-- layout.mark(notif.layout.top, notif.layout.height, false)
layout.mark(notif.layout.top + gap, notif.layout.height, false)
if not vim.deep_equal(prev_layout, notif.layout) then
if notif.win:win_valid() then
wins_updated = wins_updated + 1
else
wins_created = wins_created + 1
end
update[#update + 1] = notif.win
notif.win.opts.row = notif.layout.top - 1
notif.win.opts.col = vim.o.columns - notif.layout.width - self.opts.margin.right
notif.shown = notif.shown or ts()
notif.win:show()
end
elseif notif.win then
notif.shown = nil
notif.win:hide()
end
end
end
if #update > 0 and not self.in_search() then
if vim.api.nvim__redraw then
for _, win in ipairs(update) do
win:redraw()
end
else
vim.cmd.redraw()
end
end
endopts = {
notifier = {
---@param buf integer
---@param notif snacks.notifier.Notif
---@param ctx snacks.notifier.ctx
style = function(buf, notif, ctx)
local render = ctx.notifier:get_render 'compact'
ctx.notifier.layout = function(self)
gap_layout(self, 1)
end
render(buf, notif, ctx)
end,
},
}, |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Now built into
snacks.nvim! See #2331.Previous message
I think it can be done better. I’m not sure how to hook up before the layout changes.