Skip to content

attempt at fixing #309 layout issues with tmux 2.6 #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion tmuxp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -278,7 +278,49 @@ 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))
# 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
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

Expand Down