Multigrid UI: Z-indexing grids

Hey guys, I’m developing a UI for Neovim (nvui) and was wondering how I can calculate the z-index of a grid.
Currently, I’m sorting grids by a timestamp of their creation and then sorting by that, but for some floating grids this doesn’t work (e.g. nvim-lazygit’s floating window shows a blank screen since the outline covers the interface grid).
Here’s what I’ve tried so far:

  • Sorting by grid id: LazyGit works, but Telescope shows a blank screen. This is because the Telescope outline grid (borders etc.) has an ID higher than the grids that contain the files, previews, and the current query.
  • Sorting by the window ID handle given by all the multigrid win_* commands (LazyGit works, Telescope once again shows a blank screen).
  • Sorting by Neovide’s scheme e.g. partition by floating windows, use the hidden “sort_order” win_viewport argument to sort between floating windows, and then draw floating windows over regular windows. This also doesn’t work since multiple floating grids are given the same sort order, and Neovide also has this problem if you set floating windows to be completely opaque.

Edit: Here’s an example video of what’s happening (Telescope opens, Lazygit interface doesn’t show):

Thanks in advance!