99import  sys 
1010import  typing  as  t 
1111
12- from  libtmux .common  import  has_gte_version 
1312from  libtmux .server  import  Server 
1413from  libtmux .session  import  Session 
1514
@@ -48,65 +47,6 @@ class CLILoadNamespace(argparse.Namespace):
4847    log_file : t .Optional [str ]
4948
5049
51- def  set_layout_hook (session : Session , hook_name : str ) ->  None :
52-     """Set layout hooks to normalize layout. 
53- 
54-     References 
55-     ---------- 
56-         - tmuxp issue: https://github.com/tmux-python/tmuxp/issues/309 
57-         - tmux issue: https://github.com/tmux/tmux/issues/1106 
58- 
59-     tmux 2.6+ requires that the window be viewed with the client before 
60-     select-layout adjustments can take effect. 
61- 
62-     To handle this, this function creates temporary hook for this session to 
63-     iterate through all windows and select the layout. 
64- 
65-     In order for layout changes to take effect, a client must at the very 
66-     least be attached to the window (not just the session). 
67- 
68-     hook_name is provided to allow this to set to multiple scenarios, such 
69-     as 'client-attached' (which the user attaches the session). You may 
70-     also want 'after-switch-client' for cases where the user loads tmuxp 
71-     sessions inside tmux since tmuxp offers to switch for them. 
72- 
73-     Also, the hooks are set immediately unbind after they're invoked via -u. 
74- 
75-     Parameters 
76-     ---------- 
77-     session : :class:`libtmux.session.Session` 
78-         session to bind hook to 
79-     hook_name : str 
80-         hook name to bind to, e.g. 'client-attached' 
81-     """ 
82-     assert  session .id  is  not None 
83-     cmd : t .List [str ] =  ["set-hook" , hook_name ]
84-     hook_cmd  =  []
85-     active_window  =  session .active_window 
86-     for  window  in  session .windows :
87-         # unfortunately, select-layout won't work unless 
88-         # we've literally selected the window at least once 
89-         # with the client 
90-         hook_cmd .append (f"selectw -t { window .id }  )
91-         # edit: removed -t, or else it won't respect main-pane-w/h 
92-         hook_cmd .append ("selectl" )
93-         hook_cmd .append ("selectw -p" )
94- 
95-     # unset the hook immediately after executing 
96-     hook_cmd .extend (
97-         (f"set-hook -u -t { session .id } { hook_name }  , f"selectw -t { active_window .id }  )
98-     )
99- 
100-     # join the hook's commands with semicolons 
101-     _hook_cmd  =  "{}" .format ("; " .join (hook_cmd ))
102- 
103-     # append the hook command 
104-     cmd .append (_hook_cmd )
105- 
106-     # create the hook 
107-     session .cmd (* cmd , target = session .id )
108- 
109- 
11050def  load_plugins (session_config : t .Dict [str , t .Any ]) ->  t .List [t .Any ]:
11151    """Load and return plugins in workspace.""" 
11252    plugins  =  []
@@ -200,20 +140,10 @@ def _load_attached(builder: WorkspaceBuilder, detached: bool) -> None:
200140        # unset TMUX, save it, e.g. '/tmp/tmux-1000/default,30668,0' 
201141        tmux_env  =  os .environ .pop ("TMUX" )
202142
203-         if  has_gte_version ("2.6" ):
204-             set_layout_hook (builder .session , "client-session-changed" )
205- 
206143        builder .session .switch_client ()  # switch client to new session 
207144
208145        os .environ ["TMUX" ] =  tmux_env   # set TMUX back again 
209146    else :
210-         if  has_gte_version ("2.6" ):
211-             # if attaching for first time 
212-             set_layout_hook (builder .session , "client-attached" )
213- 
214-             # for cases where user switches client for first time 
215-             set_layout_hook (builder .session , "client-session-changed" )
216- 
217147        if  not  detached :
218148            builder .session .attach_session ()
219149
@@ -230,10 +160,6 @@ def _load_detached(builder: WorkspaceBuilder) -> None:
230160
231161    assert  builder .session  is  not None 
232162
233-     if  has_gte_version ("2.6" ):  # prepare for both cases 
234-         set_layout_hook (builder .session , "client-attached" )
235-         set_layout_hook (builder .session , "client-session-changed" )
236- 
237163    print ("Session created in detached state." )
238164
239165
@@ -248,9 +174,6 @@ def _load_append_windows_to_current_session(builder: WorkspaceBuilder) -> None:
248174    current_attached_session  =  builder .find_current_attached_session ()
249175    builder .build (current_attached_session , append = True )
250176    assert  builder .session  is  not None 
251-     if  has_gte_version ("2.6" ):  # prepare for both cases 
252-         set_layout_hook (builder .session , "client-attached" )
253-         set_layout_hook (builder .session , "client-session-changed" )
254177
255178
256179def  _setup_plugins (builder : WorkspaceBuilder ) ->  Session :
0 commit comments