Skip to content

Commit 0d9bc0d

Browse files
committed
Add support for tmux control mode (#3656)
1 parent 1980e72 commit 0d9bc0d

39 files changed

+2219
-8
lines changed

src/cascadia/TerminalApp/AppActionHandlers.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,15 @@ namespace winrt::TerminalApp::implementation
283283

284284
const auto& terminalTab{ _senderOrFocusedTab(sender) };
285285

286+
if constexpr (Feature_TmuxControl::IsEnabled())
287+
{
288+
//Tmux control takes over
289+
if (_tmuxControl && _tmuxControl->TabIsTmuxControl(terminalTab))
290+
{
291+
return _tmuxControl->SplitPane(terminalTab, realArgs.SplitDirection());
292+
}
293+
}
294+
286295
_SplitPane(terminalTab,
287296
realArgs.SplitDirection(),
288297
// This is safe, we're already filtering so the value is (0, 1)

src/cascadia/TerminalApp/Pane.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,10 +1304,10 @@ void Pane::UpdateSettings(const CascadiaSettings& settings)
13041304
// - splitType: How the pane should be attached
13051305
// Return Value:
13061306
// - the new reference to the child created from the current pane.
1307-
std::shared_ptr<Pane> Pane::AttachPane(std::shared_ptr<Pane> pane, SplitDirection splitType)
1307+
std::shared_ptr<Pane> Pane::AttachPane(std::shared_ptr<Pane> pane, SplitDirection splitType, const float splitSize)
13081308
{
13091309
// Splice the new pane into the tree
1310-
const auto [first, _] = _Split(splitType, .5, pane);
1310+
const auto [first, _] = _Split(splitType, splitSize, pane);
13111311

13121312
// If the new pane has a child that was the focus, re-focus it
13131313
// to steal focus from the currently focused pane.

src/cascadia/TerminalApp/Pane.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ class Pane : public std::enable_shared_from_this<Pane>
131131
void Close();
132132

133133
std::shared_ptr<Pane> AttachPane(std::shared_ptr<Pane> pane,
134-
winrt::Microsoft::Terminal::Settings::Model::SplitDirection splitType);
134+
winrt::Microsoft::Terminal::Settings::Model::SplitDirection splitType,
135+
const float splitSize = .5);
135136
std::shared_ptr<Pane> DetachPane(std::shared_ptr<Pane> pane);
136137

137138
int GetLeafPaneCount() const noexcept;

src/cascadia/TerminalApp/Resources/en-US/Resources.resw

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,4 +986,7 @@
986986
<data name="InvalidRegex" xml:space="preserve">
987987
<value>An invalid regular expression was found.</value>
988988
</data>
989-
</root>
989+
<data name="NewTmuxControlTab.Text" xml:space="preserve">
990+
<value>Tmux Control Tab</value>
991+
</data>
992+
</root>

src/cascadia/TerminalApp/TerminalAppLib.vcxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@
178178
<ClInclude Include="SettingsPaneContent.h">
179179
<DependentUpon>TerminalPaneContent.idl</DependentUpon>
180180
</ClInclude>
181+
<ClInclude Include="TmuxControl.h">
182+
<DependentUpon>TerminalPage.idl</DependentUpon>
183+
</ClInclude>
181184
<ClInclude Include="Toast.h" />
182185
<ClInclude Include="TerminalSettingsCache.h">
183186
<DependentUpon>TerminalSettingsCache.idl</DependentUpon>
@@ -302,6 +305,9 @@
302305
<ClCompile Include="SettingsPaneContent.cpp">
303306
<DependentUpon>TerminalPaneContent.idl</DependentUpon>
304307
</ClCompile>
308+
<ClCompile Include="TmuxControl.cpp">
309+
<DependentUpon>TerminalPage.xaml</DependentUpon>
310+
</ClCompile>
305311
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
306312
<ClCompile Include="Toast.cpp" />
307313
<ClCompile Include="TerminalSettingsCache.cpp">

src/cascadia/TerminalApp/TerminalPage.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "ScratchpadContent.h"
1919
#include "SnippetsPaneContent.h"
2020
#include "MarkdownPaneContent.h"
21+
#include "TmuxControl.h"
2122
#include "TabRowControl.h"
2223
#include "Remoting.h"
2324

@@ -104,6 +105,11 @@ namespace winrt::TerminalApp::implementation
104105
}
105106
}
106107
_hostingHwnd = hwnd;
108+
109+
if constexpr (Feature_TmuxControl::IsEnabled())
110+
{
111+
_tmuxControl = std::make_unique<TmuxControl>(*this);
112+
}
107113
return S_OK;
108114
}
109115

@@ -238,6 +244,15 @@ namespace winrt::TerminalApp::implementation
238244
_newTabButton.Click([weakThis{ get_weak() }](auto&&, auto&&) {
239245
if (auto page{ weakThis.get() })
240246
{
247+
if constexpr (Feature_TmuxControl::IsEnabled())
248+
{
249+
//Tmux control takes over
250+
if (page->_tmuxControl && page->_tmuxControl->TabIsTmuxControl(page->_GetFocusedTabImpl()))
251+
{
252+
return;
253+
}
254+
}
255+
241256
page->_OpenNewTerminalViaDropdown(NewTerminalArgs());
242257
}
243258
});
@@ -1203,6 +1218,15 @@ namespace winrt::TerminalApp::implementation
12031218
}
12041219
if (altPressed && !debugTap)
12051220
{
1221+
// tmux control panes don't share tab with other panes
1222+
if constexpr (Feature_TmuxControl::IsEnabled())
1223+
{
1224+
if (_tmuxControl && _tmuxControl->TabIsTmuxControl(_GetFocusedTabImpl()))
1225+
{
1226+
return;
1227+
}
1228+
}
1229+
12061230
this->_SplitPane(_GetFocusedTabImpl(),
12071231
SplitDirection::Automatic,
12081232
0.5f,
@@ -2241,6 +2265,15 @@ namespace winrt::TerminalApp::implementation
22412265
return false;
22422266
}
22432267

2268+
if constexpr (Feature_TmuxControl::IsEnabled())
2269+
{
2270+
//Tmux control tab doesn't support to drag
2271+
if (_tmuxControl && _tmuxControl->TabIsTmuxControl(tab))
2272+
{
2273+
return false;
2274+
}
2275+
}
2276+
22442277
// If there was a windowId in the action, try to move it to the
22452278
// specified window instead of moving it in our tab row.
22462279
const auto windowId{ args.Window() };
@@ -3188,7 +3221,7 @@ namespace winrt::TerminalApp::implementation
31883221
const auto tabViewItem = eventArgs.Tab();
31893222
if (auto tab{ _GetTabByTabViewItem(tabViewItem) })
31903223
{
3191-
_HandleCloseTabRequested(tab);
3224+
tab.try_as<TabBase>()->CloseRequested.raise(nullptr, nullptr);
31923225
}
31933226
}
31943227

@@ -3355,6 +3388,16 @@ namespace winrt::TerminalApp::implementation
33553388
original->SetActive();
33563389
}
33573390

3391+
if constexpr (Feature_TmuxControl::IsEnabled())
3392+
{
3393+
if (profile.AllowTmuxControl() && _tmuxControl)
3394+
{
3395+
control.SetTmuxControlHandlerProducer([this, control](auto print) {
3396+
return _tmuxControl->TmuxControlHandlerProducer(control, print);
3397+
});
3398+
}
3399+
}
3400+
33583401
return resultPane;
33593402
}
33603403

@@ -5242,6 +5285,14 @@ namespace winrt::TerminalApp::implementation
52425285
tabImpl.copy_from(winrt::get_self<TabBase>(tabBase));
52435286
if (tabImpl)
52445287
{
5288+
if constexpr (Feature_TmuxControl::IsEnabled())
5289+
{
5290+
//Tmux control tab doesn't support to drag
5291+
if (_tmuxControl && _tmuxControl->TabIsTmuxControl(tabImpl.try_as<TerminalTab>()))
5292+
{
5293+
return;
5294+
}
5295+
}
52455296
// First: stash the tab we started dragging.
52465297
// We're going to be asked for this.
52475298
_stashed.draggedTab = tabImpl;

src/cascadia/TerminalApp/TerminalPage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "RenameWindowRequestedArgs.g.h"
1111
#include "RequestMoveContentArgs.g.h"
1212
#include "LaunchPositionRequest.g.h"
13+
#include "TmuxControl.h"
1314
#include "Toast.h"
1415

1516
#include "WindowsPackageManagerFactory.h"
@@ -245,6 +246,7 @@ namespace winrt::TerminalApp::implementation
245246
std::vector<std::vector<Microsoft::Terminal::Settings::Model::ActionAndArgs>> _previouslyClosedPanesAndTabs{};
246247

247248
uint32_t _systemRowsToScroll{ DefaultRowsToScroll };
249+
std::unique_ptr<TmuxControl> _tmuxControl{ nullptr };
248250

249251
// use a weak reference to prevent circular dependency with AppLogic
250252
winrt::weak_ref<winrt::TerminalApp::IDialogPresenter> _dialogPresenter;
@@ -565,6 +567,7 @@ namespace winrt::TerminalApp::implementation
565567

566568
friend class TerminalAppLocalTests::TabTests;
567569
friend class TerminalAppLocalTests::SettingsTests;
570+
friend class TmuxControl;
568571
};
569572
}
570573

0 commit comments

Comments
 (0)