diff --git a/CHANGES b/CHANGES index 21bc8198b91..94087c3c202 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,13 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force - _Insert changes/features/fixes for next release here_ +## tmuxp 1.13.1 (unreleased) + +### Bug fixes + +- Fix layout related issues from {issue}`667`, {issue}`704`, {issue}`737`, via + {issue}`793`. Thank you @nvasilas. + ## tmuxp 1.13.0 (2022-08-14) ### Internal diff --git a/tests/test_workspacebuilder.py b/tests/test_workspacebuilder.py index e30a9168bc0..048dd7e5c7b 100644 --- a/tests/test_workspacebuilder.py +++ b/tests/test_workspacebuilder.py @@ -10,7 +10,7 @@ import libtmux from libtmux import Window -from libtmux.common import has_gte_version +from libtmux.common import has_gte_version, has_lt_version from libtmux.test import retry_until, temp_session from tmuxp import config, exc from tmuxp.cli.load import load_plugins @@ -1183,3 +1183,37 @@ def f(): # handle case with OS X adding /private/ to /tmp/ paths assert retry_until(f) + + +@pytest.mark.skipif( + has_lt_version("2.9"), reason="needs option introduced in tmux >= 2.9" +) +def test_layout_main_horizontal(session): + yaml_config = test_utils.read_config_file("workspacebuilder/three_pane.yaml") + + sconfig = kaptan.Kaptan(handler="yaml") + sconfig = sconfig.import_config(yaml_config).get() + + builder = WorkspaceBuilder(sconf=sconfig) + builder.build(session=session) + + assert session.windows + window = session.windows[0] + + assert len(window.panes) == 3 + main_horizontal_pane, *panes = window.panes + + def height(p): + return int(p._info["pane_height"]) + + def width(p): + return int(p._info["pane_width"]) + + assert height(main_horizontal_pane) > height(panes[0]) + assert width(main_horizontal_pane) > width(panes[0]) + + def is_almost_equal(x, y): + return abs(x - y) <= 1 + + assert is_almost_equal(height(panes[0]), height(panes[1])) + assert is_almost_equal(width(panes[0]), width(panes[1])) diff --git a/tmuxp/workspacebuilder.py b/tmuxp/workspacebuilder.py index 5ea9fc92abf..b21f0dc8a2c 100644 --- a/tmuxp/workspacebuilder.py +++ b/tmuxp/workspacebuilder.py @@ -12,6 +12,7 @@ from libtmux.server import Server from libtmux.session import Session from libtmux.window import Window +from libtmux.common import has_gte_version from . import exc from .util import get_current_pane, run_before_script @@ -217,6 +218,10 @@ def build(self, session=None, append=False): assert self.sconf["session_name"] == session.name assert len(self.sconf["session_name"]) > 0 + if has_gte_version("2.9"): + # Use tmux default session size, overwrite Server::new_session + session.set_option("default-size", "80x24") + self.session = session self.server = session.server @@ -264,9 +269,6 @@ def build(self, session=None, append=False): assert isinstance(p, Pane) p = p - if "layout" in wconf: - w.select_layout(wconf["layout"]) - if "focus" in pconf and pconf["focus"]: focus_pane = p @@ -281,6 +283,8 @@ def build(self, session=None, append=False): if focus_pane: focus_pane.select_pane() + w.select_layout(wconf.get("layout", "even-vertical")) + if focus: focus.select_window() @@ -421,8 +425,6 @@ def get_pane_shell(): ) assert isinstance(p, Pane) - if "layout" in wconf: - w.select_layout(wconf["layout"]) if "suppress_history" in pconf: suppress = pconf["suppress_history"]