Skip to content

Sort windows in the overview grid to minimize travel distance

When transitioning to or from the overview, windows travel a certain distance between their real desktop position and their place in the overview window grid. The less this travel distance is, the smoother, more polished, and less jarring the overall transition looks. This is why it makes sense to try reordering and repositioning windows to minimize their travel distance. That being said, there are other factors that impact the quality of the overview layout, such as how much the windows get scaled and what portion of the overall available space they take up.

The existing code tries to minimize the travel distance by sorting the windows in each row by their horizontal position. There are, however, two problems with this implementation. First, it compares the coordinates of windows' left edges as opposed to their centers, which means it yields unexpected results when a small window is positioned next to the left edge of a large window. Second, it completely disregards vertical coordinates, instead assigning windows to the grid rows using their monotonically increasing window numbers, effectively vertically sorting them by the order they were created in.

This commit changes both vertical and horizontal ordering to work based on the coordinates of the geometric centers of the windows. That is to say, windows are first assigned to grid rows based on the vertical coordinates of their centers, and subsequently sorted inside each row based on the horizontal coordinates of said centers. In my testing, this leads to a much more intuitive and visually pleasing window placement.

Merge request reports