Cleaned up my code from https://github.com/Zren/kwin-tabbox-thumbnail_grid
The column is calculated recursively, but survived a stress test.
https://github.com/Zren/kwin-tabbox-thumbnail_grid/pull/2
I tested when "show desktop" is configured to be hidden since I know it didn't like it with modding by 0 items in the python test. "show desktop" will show up on an empty desktop though so there's always at least 1 item it seems.
I wrote a python script to easily test the recursive column calculation with __ number of windows.
https://github.com/Zren/kwin-tabbox-thumbnail_grid/blob/master/test_recursion.py
Outlined: