Skip to content
Myr

Preserve tmux window zoom when opening a floating pane

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Use new-pane -A on tmux 3.8+ to keep floating pane above zoomed pane - Detect -A from new-pane usage; keep unzoom fallback for 3.7 Fix #4927 Fix junegunn/fzf.vim#1625

authored by Junegunn Choi · committed by Junegunn Choi · parent 981f153 · Browse files · 2 files+25 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Jere Viikari <jere.viikari@gmail.com>

Diff stats

2 files+25 added−16 removed

  • other:+25 added−16 removed

2 files+25 added−16 removed

modified:src/tmux.go+23 added-16 removed
3 unmodified lines
4 "fmt"5 "os"6 "os/exec"7 "path/filepath"8 "regexp"9 "strings"1011 "github.com/junegunn/fzf/src/tui"12)1314// The flag group of new-pane usage includes -A (tmux 3.8 or above)15var tmuxOverZoomFlag = regexp.MustCompile(`new-pane.*\[-[[:alpha:]]*A`)1617// Returns the size of the current window if the tmux server supports14// floating panes (tmux 3.7 or above)15func tmuxFloatingPaneInfo() (int, int, bool) {18// floating panes (tmux 3.7 or above), and whether a floating pane can stay19// above a zoomed pane20func tmuxFloatingPaneInfo() (int, int, bool, bool) {21 // TMUX_PANE is not set when fzf is not started from within a pane22 // (e.g. 'bind-key 0 run-shell "fzf --popup"'). Do not use a floating23 // pane there; a blocking run-shell suspends key processing for the24 // client until the command exits, so fzf in a floating pane would
4 unmodified lines
29 // not suspend key processing, as discussed in:30 // https://github.com/tmux/tmux/issues/538431 target := os.Getenv("TMUX_PANE")32 if target == "" {28 return 0, 0, false33 return 0, 0, false, false34 }35 // A single invocation for both checks. Cannot rely on the exit status;36 // tmux versions before 3.7 exit normally with empty output for an37 // unknown command name, so check the output instead.38 out, err := exec.Command("tmux", "display-message", "-p", "-t", target,39 "#{window_width} #{window_height}", ";", "list-commands", "new-pane").Output()40 if err != nil || !strings.Contains(string(out), "new-pane") {36 return 0, 0, false41 return 0, 0, false, false42 }43 var width, height int44 if _, err := fmt.Sscanf(string(out), "%d %d", &width, &height); err != nil {40 return 0, 0, false45 return 0, 0, false, false46 }47 // The window is too small to fit a floating pane of the minimum size48 if width < 3 || height < 3 {44 return 0, 0, false49 return 0, 0, false, false50 }46 return width, height, true51 return width, height, tmuxOverZoomFlag.Match(out), true52}5354// tmux ends a command at an argument ending in ';', so a trailing one is55// escaped. Elsewhere it is not special
33 unmodified lines
89 }90 return max(3, min(dim, window))91}9288func runTmuxFloatingPane(argStr string, dir string, windowWidth int, windowHeight int, opts *Options) (int, error) {93func runTmuxFloatingPane(argStr string, dir string, windowWidth int, windowHeight int, overZoom bool, opts *Options) (int, error) {94 // Unlike display-popup, the size of a floating pane does not account for95 // the border around it, and the position is that of the content area. To96 // stay consistent with popups, treat the requested size as the total97 // footprint including the border.
72 unmodified lines
170 setup += fmt.Sprintf(`export %s="$TMUX_PANE"; `, tmuxBorderLabelEnv)171 }172 paneCmd := fmt.Sprintf("%s%s %s; echo $? > %s; tmux wait-for -S %s",173 setup, escapeSingleQuote(sh), escapeSingleQuote(temp), code, signal)169 // Unzoom the window first; creating a floating pane over a zoomed170 // window crashes the tmux server on 3.7b, and newer versions of171 // tmux unzoom the window anyway.174 target := os.Getenv("TMUX_PANE")173 newPane := fmt.Sprintf(174 "tmux if -F -t %s '#{window_zoomed_flag}' %s ';' new-pane -P -F '#{pane_id}' -t %s -c %s -x %d -y %d -X %d -Y %d %s -c %s",175 escapeSingleQuote(target), escapeSingleQuote("resize-pane -Z -t "+target),175 newPane := "tmux new-pane -A"176 if !overZoom {177 // Unzoom the window first; creating a floating pane over a178 // zoomed window crashes the tmux server on 3.7b179 newPane = fmt.Sprintf("tmux if -F -t %s '#{window_zoomed_flag}' %s ';' new-pane",180 escapeSingleQuote(target), escapeSingleQuote("resize-pane -Z -t "+target))181 }182 newPane += fmt.Sprintf(" -P -F '#{pane_id}' -t %s -c %s -x %d -y %d -X %d -Y %d %s -c %s",183 escapeSingleQuote(target), escapeSingleQuote(dir), width-2, height-2, x, y,184 escapeSingleQuote(sh), escapeSingleQuote(paneCmd))185186 // The pane is killed when the proxy process is interrupted or hung up,
41 unmodified lines
228 // When the native border is not used (an explicit --border style), a229 // popup is used instead so that the fzf-drawn border is the only border230 // shown; the native border of a tmux floating pane cannot be removed.231 if nativeBorder(opts) {225 if windowWidth, windowHeight, ok := tmuxFloatingPaneInfo(); ok {232 if windowWidth, windowHeight, overZoom, ok := tmuxFloatingPaneInfo(); ok {233 opts.Tmux.border = true234 argStr, dir := popupArgStr(args, opts)228 return runTmuxFloatingPane(argStr, dir, windowWidth, windowHeight, opts)235 return runTmuxFloatingPane(argStr, dir, windowWidth, windowHeight, overZoom, opts)236 }237 }238239 argStr, dir := popupArgStr(args, opts)
36 unmodified lines
modified:CHANGELOG.md+2 added
7 unmodified lines
8- Fixed a key lost when it arrived in the same read as an escape sequence9- Fixed `focus` event not triggered after `reload` when the new item is at the same position as the previous one (#4930)10 - With `--id-nth`, the event is not triggered if the focus moves directly from an item to another item with the same key11 - A `focus` binding that runs `reload` now triggers itself again after each reload, unless `--id-nth` is set and the key does not change12- Fixed `--popup` unzooming the window when opened over a zoomed pane on tmux 3.8 or above (#4927, junegunn/fzf.vim#1625)13 - On tmux 3.7, the window is still unzoomed, as tmux 3.7b crashes when a floating pane is created over a zoomed window14150.74.416------17- Fixed an escape sequence split across reads being parsed as a fragment, which leaked the rest into the query (#4899)
3451 unmodified lines