From 1624abe32ae1fca3d6cd1a86d2bc0fa0c51c6c54 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Thu, 9 Nov 2017 14:53:59 -0600 Subject: [PATCH 1/2] attempt at fixing #309 layout issues with tmux 2.6 even after setting -x and -y with new-session, select-layout won't take effect. However, it is necessary in 2.6 to get pane creation in detached mode to work. the only way found for tmux select-layout to take effect and prior behavior to have viewed the window you are running "select-layout" for in the client. a solution has been devised to connect the client to the session, then run select-layout on each window in the session. However, it's still not enough to load the session, it seems the window must be selected by the client at least once for the select-layout to take effect. so a hook against the session is created for the session that selects each window, runs select layout at the -t target for the window id. and after that, the hook is neatly unset when that's finished. --- tmuxp/cli.py | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/tmuxp/cli.py b/tmuxp/cli.py index 3b942354fb0..c6d18edc357 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -14,7 +14,7 @@ import click import kaptan from click.exceptions import FileError -from libtmux.common import has_minimum_version, which +from libtmux.common import has_minimum_version, which, has_gte_version from libtmux.exc import TmuxCommandNotFound from libtmux.server import Server @@ -278,7 +278,48 @@ def reattach(session): sys.exit('Session created in detached state.') if not detached: + + if has_gte_version('2.6'): + # tmuxp issue: https://github.com/tony/tmuxp/issues/309 + # tmux issue: https://github.com/tmux/tmux/issues/1106 + # + # tmux now requires that the window be viewed with the client + # before select-layout adjustments can be meaningful + # + # To handle this, let's create a temporary hook for this + # session to iterage and run select-layout on all windows + # after client attaches. + cmd = [ + 'set-hook', + '-t', builder.session.id, + 'client-attached' + ] + hook_cmd = [] + for window in builder.session.windows: + # unfortunately, select-layout won't work unless + # we've literally selected the window at least once + # with the client + hook_cmd.append('selectw -t {}'.format(window.id)) + hook_cmd.append('selectl -t {}'.format(window.id)) + hook_cmd.append('selectw -p'.format(window.id)) + + # unset the hook immediately after executing + hook_cmd.append( + 'set-hook -u -t {target_session} client-attached'.format( + target_session=builder.session.id + ) + ) + + # join the hook's commands with semicolons + hook_cmd = '{}'.format('; '.join(hook_cmd)) + + # append the hook command + cmd.append(hook_cmd) + + # create the hook + builder.session.cmd(*cmd) builder.session.attach_session() + except exc.TmuxpException as e: import traceback From 6e08e0396909823a5b5c62a5575d79025f0d47cf Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Thu, 9 Nov 2017 15:50:45 -0600 Subject: [PATCH 2/2] Remove -t from selectl in hook Per the feedback from: - https://github.com/tony/tmuxp/issues/309#issuecomment-343298726 - https://github.com/tony/tmuxp/pull/312#issuecomment-343299428 and verified by me with: - https://github.com/tony/tmuxp/issues/309#issuecomment-343300975 main-pane-width/height wasn't being respected when using targets with selectl. --- tmuxp/cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tmuxp/cli.py b/tmuxp/cli.py index c6d18edc357..6e798d30529 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -300,7 +300,8 @@ def reattach(session): # we've literally selected the window at least once # with the client hook_cmd.append('selectw -t {}'.format(window.id)) - hook_cmd.append('selectl -t {}'.format(window.id)) + # edit: removed -t, or else it won't respect main-pane-w/h + hook_cmd.append('selectl'.format(window.id)) hook_cmd.append('selectw -p'.format(window.id)) # unset the hook immediately after executing