Taskbar Spatial Order
Keeps each app's windows on the taskbar in the order they sit on screen, left to right, in thumbnail previews and uncombined buttons
Author: Jori Huisman
Keeps each app's windows on the taskbar in the order they sit on your screens,
left to right, then top to bottom, rather than roughly the order they were
opened. Hover over an app's taskbar button and its leftmost window is the
leftmost thumbnail; uncombined buttons follow the same order.
Without the mod, the previews follow the order the windows were opened:

With it, they follow the windows on screen:

The order follows as windows move, are minimised or restored, open or close.
The mod waits until things have been still for a moment, and while a window
is dragged or the Start menu, search, notifications or a jump list is open.
By default, minimised windows go last and a group whose windows are all
minimised is left alone. The settings can change both and exclude apps.
Limitations
- Windows 11 24H2 and later, with its own taskbar, tested on build 26300;
older versions are untested. The mod relies on internal taskbar functions
found through Windows debug symbols, which an update can change; if one is
missing or looks unexpected, the mod logs it and does nothing.
- A button that moves is taken off the taskbar and put back, which can show
as a brief animation. Only buttons that are out of place move, and they keep
their progress bar, overlay badge and thumbnail toolbar buttons.
- The mod's order wins: a window moved to another place in its group, by hand
or by another mod, goes back at the next sort.
Credits
The move-and-refresh technique and the code that finds the taskbar's lists
are adapted from Taskbar Thumbnail Reorder by m417z, with
a smaller part from his Cycle taskbar buttons with mouse wheel mod.