# window.navigation.Window.focus_direction

- **Module:** window.navigation.Window
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/8a648c0894dfffc9303583f753b6c8ae01f2fe76/crates/libtmux/src/window/navigation.rs#L156
- **Page:** https://libtmux.org/reference/rs/window-navigation-window-focus_direction/

```
window.navigation.Window.focus_direction(self, direction: PaneDirection) -> Result<Pane, Error>
```

Move focus one pane in this direction, and report where it landed.

tmux wraps: asking to go up from the topmost pane lands on the bottom
one, and a window holding a single pane stays where it is. Neither is
a failure, and tmux reports neither, so this returns the pane rather
than absence. A caller that wants to know whether it moved compares
the returned ID with the one it started from.

Direction follows the layout, not the pane index: "up" means the pane
drawn above this one.

# Errors

Returns an error when tmux cannot be reached or refuses the move.

## Example

```rust
use libtmux::{PaneDirection, SplitDirection};

let guard = libtmux::test::TestServer::new().await?;
let session = guard.server().new_session("directions").await?;
let window = session.active_window().await?.expect("a session has a window");

// Splitting leaves focus where it was, so the top pane is still active.
let lower = window.split(SplitDirection::Below).await?;

let moved = window.focus_direction(PaneDirection::Below).await?;
assert_eq!(moved.id(), lower.id(), "focus moved down to the new pane");

// Down again from the bottom wraps rather than failing.
let wrapped = window.focus_direction(PaneDirection::Below).await?;
assert_ne!(wrapped.id(), lower.id(), "the edge wraps back to the top");

guard.shutdown().await?;
```
