Skip to main content

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

From layout.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, or LAYOUT_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

A leaf cell containing a single pane.

Predefined Layouts

tmux includes seven built-in layout algorithms (from layout-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

From layout-set.c:87-124, tmux cycles through all predefined layouts.

Select Specific Layout

Spread Panes Evenly

Implemented in layout_spread_cell() at layout.c:1100-1159:

Custom Layouts

Layout String Format

From layout-custom.c:59-116, layouts can be saved and restored using a compact string representation:
Example layout string:
Breakdown:
  • 2e3a - Checksum (4 hex digits)
  • 80x24,0,0 - Root cell: 80 cols x 24 rows at position 0,0
  • {...} - Left-right split
  • 40x24,0,0,0 - Left pane: 40x24 at 0,0, pane ID 0
  • 39x24,41,0,1 - Right pane: 39x24 at x=41, y=0, pane ID 1

Parse Custom Layout

From layout-custom.c:283-370, the parser constructs a layout tree:
1

Parse Dimensions

Reads size and position of each cell.
2

Identify Container Type

3

Recursively Parse Children

Container cells are parsed recursively until all child cells are constructed.

Save and Restore Layouts

Layout Scripts

Create a complex layout programmatically:
~/bin/dev-layout.sh

Layout Algorithms

Resize Algorithm

From layout.c:417-463, resizing adjusts cells evenly:

Minimum Size Checking

From layout.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

From layout.c:907-1080, splitting a pane:
1

Check Space

Verify there’s enough room for two panes plus border:
2

Calculate Sizes

Determine size of each resulting pane:
3

Create Cell Structure

Insert new cell into layout tree:
  • If parent exists and is same type: insert as sibling
  • Otherwise: create new parent container
4

Update Layout

Recalculate offsets and pane sizes:

Layout Options

Main Pane Dimensions

From layout-set.c:213-237, these accept percentages:

Tiled Layout Configuration

From layout-set.c:601-610, this controls the grid dimensions:

Advanced Techniques

Preserve Layouts Across Sessions

~/.tmux.conf

Dynamic Layout Adjustment

From layout.c:586-616, resize to absolute size:

Layout Rotation

This maintains the layout structure but shifts which pane occupies each position.

Troubleshooting

Common layout issues:
Tmux enforces PANE_MINIMUM (usually 1x1). Check:
From layout-custom.c:165-173, checksums must match:
Regenerate the checksum if manually editing.
From layout.c:229-239, offsets are recalculated: