9
9
import sys
10
10
import typing as t
11
11
12
- from libtmux .common import has_gte_version
13
12
from libtmux .server import Server
14
13
from libtmux .session import Session
15
14
@@ -48,65 +47,6 @@ class CLILoadNamespace(argparse.Namespace):
48
47
log_file : t .Optional [str ]
49
48
50
49
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
-
110
50
def load_plugins (session_config : t .Dict [str , t .Any ]) -> t .List [t .Any ]:
111
51
"""Load and return plugins in workspace."""
112
52
plugins = []
@@ -200,20 +140,10 @@ def _load_attached(builder: WorkspaceBuilder, detached: bool) -> None:
200
140
# unset TMUX, save it, e.g. '/tmp/tmux-1000/default,30668,0'
201
141
tmux_env = os .environ .pop ("TMUX" )
202
142
203
- if has_gte_version ("2.6" ):
204
- set_layout_hook (builder .session , "client-session-changed" )
205
-
206
143
builder .session .switch_client () # switch client to new session
207
144
208
145
os .environ ["TMUX" ] = tmux_env # set TMUX back again
209
146
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
-
217
147
if not detached :
218
148
builder .session .attach_session ()
219
149
@@ -230,10 +160,6 @@ def _load_detached(builder: WorkspaceBuilder) -> None:
230
160
231
161
assert builder .session is not None
232
162
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
-
237
163
print ("Session created in detached state." )
238
164
239
165
@@ -248,9 +174,6 @@ def _load_append_windows_to_current_session(builder: WorkspaceBuilder) -> None:
248
174
current_attached_session = builder .find_current_attached_session ()
249
175
builder .build (current_attached_session , append = True )
250
176
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" )
254
177
255
178
256
179
def _setup_plugins (builder : WorkspaceBuilder ) -> Session :
0 commit comments