# LibTmux.Session.windows/2

- **Module:** LibTmux
- **Package:** libtmux
- **Language:** Elixir
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/lib/libtmux/entities.ex#L71
- **Page:** https://libtmux.org/en/elixir/pr-173/reference/libtmux-session-windows-2/

```
windows(snapshot, session)
@spec windows(LibTmux.Snapshot.t(), t()) ::
        LibTmux.Selection.t(LibTmux.Window.t())
```

Returns a selection of captured physical windows in first-link order.

Repeated links to a window contribute it once. For membership indexes use
`LibTmux.Snapshot.related/4` with `:window_links`.

The supplied snapshot owns all returned fields and relationships. Only the
session's ID and incarnation are used; its other fields may be older.
Invalid or stale identities and missing source/relationship coverage raise
`LibTmux.Error`. A covered empty relation returns an empty selection.
No I/O occurs. The selection retains the supplied snapshot for filtering;
relationship predicates still validate their whole captured source domain.
Use `Enum.to_list/1` when only the list is needed.

## Parameters

- `snapshot` (`LibTmux.Snapshot.t()`)
- `session` (`t()`)

## Examples

```elixir
iex> alias LibTmux.{Selection, Session, Snapshot}
iex> rows = %{session: [%{id: "$0"}], window: [%{id: "@7"}],
...>   window_link: [%{session_id: "$0", window_id: "@7", index: 0, active: true},
...>     %{session_id: "$0", window_id: "@7", index: 3, active: false}],
...>   pane: [%{id: "%9", window_id: "@7"}]}
iex> {:ok, snapshot} = Snapshot.new(rows,
...>   server_instance: "example", captured_from: 0, captured_until: 0,
...>   complete: [:window_link, :pane],
...>   fields: %{window_link: [:session_id, :window_id, :active], pane: [:window_id]})
iex> {:ok, session} = Snapshot.fetch(snapshot, :session, "$0")
iex> {:ok, window} = Session.windows(snapshot, session) |> Selection.one()
iex> window.id
"@7"
iex> Session.panes(snapshot, session) |> Enum.map(& &1.id)
["%9"]
iex> Session.active_window(snapshot, session) == window
true
```

## Guides

Pages that discuss `windows/2`.

- [Captured tmux state](/en/elixir/pr-173/concepts/observations/)
