Overview
tmux uses a tree-based layout system to arrange panes within windows. Each layout consists of cells that can be either container nodes (holding other cells) or leaf nodes (containing window panes).Layout Architecture
Fromlayout.c:26-34:
The window layout is a tree of cells each of which can be one of: a left-right container for a list of cells, a top-bottom container for a list of cells, or a container for a window pane. Each window has a pointer to the root of its layout tree (containing its panes), every pane has a pointer back to the cell containing it, and each cell a pointer to its parent cell.
Cell Structure
Each layout cell contains:- Type:
LAYOUT_WINDOWPANE,LAYOUT_LEFTRIGHT, orLAYOUT_TOPBOTTOM - Geometry: Position (
xoff,yoff) and size (sx,sy) - Parent pointer: Link to containing cell
- Children list: For container cells (left-right or top-bottom)
- Window pane reference: For leaf cells
Layout Types
- LAYOUT_WINDOWPANE
- LAYOUT_LEFTRIGHT
- LAYOUT_TOPBOTTOM
A leaf cell containing a single pane.
Predefined Layouts
tmux includes seven built-in layout algorithms (fromlayout-set.c:39-50):
even-horizontal
Distributes panes evenly in a single row.All panes have equal width. Implemented in
layout_set_even_h() at layout-set.c:181-184.even-vertical
Distributes panes evenly in a single column.All panes have equal height. Implemented in
layout_set_even_v() at layout-set.c:187-190.main-horizontal
One large pane on top, others in a row below.From
layout-set.c:193-288. Controlled by:main-pane-height: Height of main pane (default 24 lines)other-pane-height: Height of other panes
main-vertical
One large pane on the left, others in a column on the right.From
layout-set.c:389-484. Controlled by:main-pane-width: Width of main pane (default 80 columns)other-pane-width: Width of other panes
main-horizontal-mirrored
Like main-horizontal, but main pane is on bottom.Implemented at
layout-set.c:291-386.main-vertical-mirrored
Like main-vertical, but main pane is on right.Implemented at
layout-set.c:487-582.tiled
Arranges panes in a grid pattern.From
layout-set.c:585-696. Dynamically calculates optimal rows and columns.Controlled by tiled-layout-max-columns option (default 0 = unlimited).Layout Commands
Cycle Through Layouts
layout-set.c:87-124, tmux cycles through all predefined layouts.
Select Specific Layout
Spread Panes Evenly
layout_spread_cell() at layout.c:1100-1159:
Custom Layouts
Layout String Format
Fromlayout-custom.c:59-116, layouts can be saved and restored using a compact string representation:
2e3a- Checksum (4 hex digits)80x24,0,0- Root cell: 80 cols x 24 rows at position 0,0{...}- Left-right split40x24,0,0,0- Left pane: 40x24 at 0,0, pane ID 039x24,41,0,1- Right pane: 39x24 at x=41, y=0, pane ID 1
Parse Custom Layout
Fromlayout-custom.c:283-370, the parser constructs a layout tree:
Save and Restore Layouts
Layout Scripts
Create a complex layout programmatically:~/bin/dev-layout.sh
Layout Algorithms
Resize Algorithm
Fromlayout.c:417-463, resizing adjusts cells evenly:
Minimum Size Checking
Fromlayout.c:365-415, tmux ensures panes never shrink below minimum:
PANE_MINIMUM: Minimum pane size (typically 1 cell)- Additional space for pane borders
- Space for pane status lines (if enabled)
- Space for scrollbars (if enabled)
Split Algorithm
Fromlayout.c:907-1080, splitting a pane:
Create Cell Structure
Insert new cell into layout tree:
- If parent exists and is same type: insert as sibling
- Otherwise: create new parent container
Layout Options
Main Pane Dimensions
layout-set.c:213-237, these accept percentages:
Tiled Layout Configuration
layout-set.c:601-610, this controls the grid dimensions:
Advanced Techniques
Preserve Layouts Across Sessions
~/.tmux.conf
Dynamic Layout Adjustment
layout.c:586-616, resize to absolute size:
Layout Rotation
Troubleshooting
Panes won't resize below minimum
Panes won't resize below minimum
Tmux enforces
PANE_MINIMUM (usually 1x1). Check:Layout string invalid
Layout string invalid
From Regenerate the checksum if manually editing.
layout-custom.c:165-173, checksums must match:Pane borders not aligning
Pane borders not aligning
From
layout.c:229-239, offsets are recalculated:Related Commands
split-window- Create new paneresize-pane- Adjust pane sizeswap-pane- Exchange pane positionsbreak-pane- Convert pane to windowjoin-pane- Merge window into pane