Cosmos - felixfung/skippy-xd GitHub Wiki
Cosmos Expose Layout Algorithm
This article explains the cosmos expose layout algorithm, which we all use and love :D
Rationale
First, fundamentally, what is expose?
Expose/Exposé is simply temporary rearrangement of windows (the window layout) so that they do not overlap, so that the user can inspect and/or select windows.
Hence, while there are infinite possible layouts, various visual cues should preferably be preserved for optimal user intuition and efficiency.
Visual cues/properties:
- Relative window position, so windows move minimally
- Relative window size, an important visual cue
- Window aspect ratio and content
In addition, a good layout would have these properties:
- Compactness, relatively little empty space
- Screen aspect ratio awareness, to reduce useless space on screen edges
- Alignment, as visual cue and for ease of navigation
- Aesthetics, that windows are distributed evenly across the screen
- Of course, much of these properties imply bigger window previews which tie directly to user efficiency
Cosmos
Skippy-xd developed its own expose layout algorithm cosmos which aims to achieve the above properties.
The central approach of cosmos is to see windows as axis-aligned bounding boxes (AABBs) within physics simulation context. The big idea is that each window is a physical rectangular body, and they physically interact and collide with each other, thus achieving non-overlap.
The precise cosmos algorithm involves these phases: scattering, expansion, contraction/collision.
Scattering
For windows that have nearby centre of mass, distribute them as grids. For example with 4 maximized windows, distribute them into a 2x2 grid.
Expansion
Push every window away from the centre of all windows mass. This is to make sure windows do not overlap. Expansion rates along screen axes optimize to screen aspect ratio.
Contraction/Collision
Pull every window toward the centre of all windows mass. Importantly, each window is treated as axis-aligned bounding box (AABB), and when they collide, they are allowed to slide along each other but not overlap.
With contraction, layout achieve compactness and alignment. In addition, special formula drives centre of all windows mass toward screen centre to achieve aesthetics.
Ordering
Cosmos navigation ordering (for example with next/prev keys or used in alt-tab) is based on recursive rectangular bisection algorithm to achieve intuitive navigation.