Skip to content

Commit ef6bb8a

Browse files
committed
hey look, it builds now
1 parent 4e14442 commit ef6bb8a

9 files changed

+58
-68
lines changed

src/cascadia/TerminalApp/AppActionHandlers.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,14 @@ namespace winrt::TerminalApp::implementation
12791279
{
12801280
if (const auto activePane{ activeTab->GetActivePane() })
12811281
{
1282-
_restartPaneConnection(activePane);
1282+
activePane;
1283+
// TODO! If we don't expose the IPaneContent, then there's no
1284+
// way to get a TerminalPaneContent to pass to
1285+
// _restartPaneConnection / _duplicateConnectionForRestart. We
1286+
// probably need to change the signature to accept a
1287+
// TermControl&Profile
1288+
1289+
// _restartPaneConnection(activePane);
12831290
}
12841291
}
12851292
args.Handled(true);

src/cascadia/TerminalApp/Pane.cpp

+1-14
Original file line numberDiff line numberDiff line change
@@ -1251,19 +1251,6 @@ void Pane::Shutdown()
12511251
// modify our tree
12521252
std::unique_lock lock{ _createCloseLock };
12531253

1254-
// TODO! This was added in main after I started working on this
1255-
// // Clear out our media player callbacks, and stop any playing media. This
1256-
// // will prevent the callback from being triggered after we've closed, and
1257-
// // also make sure that our sound stops when we're closed.
1258-
// if (_bellPlayer)
1259-
// {
1260-
// _bellPlayer.Pause();
1261-
// _bellPlayer.Source(nullptr);
1262-
// _bellPlayer.Close();
1263-
// _bellPlayer = nullptr;
1264-
// _bellPlayerCreated = false;
1265-
// }
1266-
12671254
if (_IsLeaf())
12681255
{
12691256
_content.Close();
@@ -3173,7 +3160,7 @@ void Pane::FinalizeConfigurationGivenDefault()
31733160
{
31743161
if (const auto& terminalPane{ _content.try_as<TerminalPaneContent>() })
31753162
{
3176-
terminalPane.FinalizeConfigurationGivenDefault();
3163+
terminalPane.MarkAsDefterm();
31773164
}
31783165
// _isDefTermSession = true;
31793166
}

src/cascadia/TerminalApp/Pane.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class Pane : public std::enable_shared_from_this<Pane>
216216
WINRT_CALLBACK(LostFocus, winrt::delegate<std::shared_ptr<Pane>>);
217217
WINRT_CALLBACK(PaneRaiseBell, winrt::Windows::Foundation::EventHandler<bool>);
218218
WINRT_CALLBACK(Detached, winrt::delegate<std::shared_ptr<Pane>>);
219-
WINRT_CALLBACK(RestartTerminalRequested, winrt::delegate<std::shared_ptr<Pane>>);
219+
// WINRT_CALLBACK(RestartTerminalRequested, winrt::delegate<std::shared_ptr<Pane>>);
220220

221221
private:
222222
struct PanePoint;
@@ -256,10 +256,6 @@ class Pane : public std::enable_shared_from_this<Pane>
256256

257257
bool _zoomed{ false };
258258

259-
// TODO! these were added in main after I started working on this
260-
// winrt::Windows::Media::Playback::MediaPlayer _bellPlayer{ nullptr };
261-
// bool _bellPlayerCreated{ false };
262-
263259
bool _IsLeaf() const noexcept;
264260
bool _HasFocusedChild() const noexcept;
265261
void _SetupChildCloseHandlers();

src/cascadia/TerminalApp/TabManagement.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace winrt::TerminalApp::implementation
6363
// - existingConnection: An optional connection that is already established to a PTY
6464
// for this tab to host instead of creating one.
6565
// If not defined, the tab will create the connection.
66-
HRESULT TerminalPage::_OpenNewTab(const NewTerminalArgs& newTerminalArgs, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection existingConnection)
66+
HRESULT TerminalPage::_OpenNewTab(const NewTerminalArgs& newTerminalArgs)
6767
try
6868
{
6969
const auto profile{ _settings.GetProfileForArgs(newTerminalArgs) };
@@ -86,7 +86,7 @@ namespace winrt::TerminalApp::implementation
8686
//
8787
// This call to _MakePane won't return nullptr, we already checked that
8888
// case above with the _maybeElevate call.
89-
_CreateNewTabFromPane(_MakePane(newTerminalArgs, nullptr, existingConnection));
89+
_CreateNewTabFromPane(_MakePane(newTerminalArgs, nullptr));
9090
return S_OK;
9191
}
9292
CATCH_RETURN();

src/cascadia/TerminalApp/TerminalPage.cpp

+16-10
Original file line numberDiff line numberDiff line change
@@ -1282,15 +1282,20 @@ namespace winrt::TerminalApp::implementation
12821282
return connection;
12831283
}
12841284

1285-
TerminalConnection::ITerminalConnection TerminalPage::_duplicateConnectionForRestart(std::shared_ptr<Pane> pane)
1285+
TerminalConnection::ITerminalConnection TerminalPage::_duplicateConnectionForRestart(const TerminalApp::TerminalPaneContent& paneContent)
12861286
{
1287-
const auto& control{ pane->GetTerminalControl() };
1287+
if (paneContent == nullptr)
1288+
{
1289+
return nullptr;
1290+
}
1291+
1292+
const auto& control{ paneContent.GetTerminal() };
12881293
if (control == nullptr)
12891294
{
12901295
return nullptr;
12911296
}
12921297
const auto& connection = control.Connection();
1293-
auto profile{ pane->GetProfile() };
1298+
auto profile{ paneContent.GetProfile() };
12941299

12951300
TerminalSettingsCreateResult controlSettings{ nullptr };
12961301

@@ -2922,10 +2927,9 @@ namespace winrt::TerminalApp::implementation
29222927
// Don't need to worry about duplicating or anything - we'll
29232928
// serialize the actual profile's GUID along with the content guid.
29242929
const auto& profile = _settings.GetProfileForArgs(newTerminalArgs);
2925-
29262930
const auto control = _AttachControlToContent(newTerminalArgs.ContentId());
2927-
2928-
return std::make_shared<Pane>(profile, control);
2931+
auto terminalPane{ winrt::make<TerminalPaneContent>(profile, control) };
2932+
return std::make_shared<Pane>(terminalPane);
29292933
}
29302934

29312935
TerminalSettingsCreateResult controlSettings{ nullptr };
@@ -3003,16 +3007,18 @@ namespace winrt::TerminalApp::implementation
30033007
original->SetActive();
30043008
}
30053009

3006-
resultPane->RestartTerminalRequested({ get_weak(), &TerminalPage::_restartPaneConnection });
3010+
terminalPane.RestartTerminalRequested({ get_weak(), &TerminalPage::_restartPaneConnection });
30073011

30083012
return resultPane;
30093013
}
30103014

3011-
void TerminalPage::_restartPaneConnection(const std::shared_ptr<Pane>& pane)
3015+
void TerminalPage::_restartPaneConnection(
3016+
const TerminalApp::TerminalPaneContent& paneContent,
3017+
const winrt::Windows::Foundation::IInspectable&)
30123018
{
3013-
if (const auto& connection{ _duplicateConnectionForRestart(pane) })
3019+
if (const auto& connection{ _duplicateConnectionForRestart(paneContent) })
30143020
{
3015-
pane->GetTerminalControl().Connection(connection);
3021+
paneContent.GetTerminal().Connection(connection);
30163022
connection.Start();
30173023
}
30183024
}

src/cascadia/TerminalApp/TerminalPage.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,14 @@ namespace winrt::TerminalApp::implementation
294294
winrt::Windows::UI::Xaml::Controls::MenuFlyoutItem _CreateNewTabFlyoutProfile(const Microsoft::Terminal::Settings::Model::Profile profile, int profileIndex);
295295

296296
void _OpenNewTabDropdown();
297-
HRESULT _OpenNewTab(const Microsoft::Terminal::Settings::Model::NewTerminalArgs& newTerminalArgs, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection existingConnection = nullptr);
297+
HRESULT _OpenNewTab(const Microsoft::Terminal::Settings::Model::NewTerminalArgs& newTerminalArgs);
298298
void _CreateNewTabFromPane(std::shared_ptr<Pane> pane, uint32_t insertPosition = -1);
299299

300300
std::wstring _evaluatePathForCwd(std::wstring_view path);
301301

302302
winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _CreateConnectionFromSettings(Microsoft::Terminal::Settings::Model::Profile profile, Microsoft::Terminal::Settings::Model::TerminalSettings settings, const bool inheritCursor);
303-
winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _duplicateConnectionForRestart(std::shared_ptr<Pane> pane);
304-
void _restartPaneConnection(const std::shared_ptr<Pane>& pane);
303+
winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _duplicateConnectionForRestart(const TerminalApp::TerminalPaneContent& paneContent);
304+
void _restartPaneConnection(const TerminalApp::TerminalPaneContent&, const winrt::Windows::Foundation::IInspectable&);
305305

306306
winrt::fire_and_forget _OpenNewWindow(const Microsoft::Terminal::Settings::Model::NewTerminalArgs newTerminalArgs);
307307

src/cascadia/TerminalApp/TerminalPaneContent.cpp

+16-32
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ namespace winrt::TerminalApp::implementation
5757
// Clear out our media player callbacks, and stop any playing media. This
5858
// will prevent the callback from being triggered after we've closed, and
5959
// also make sure that our sound stops when we're closed.
60-
_mediaEndedRevoker.revoke();
6160
if (_bellPlayer)
6261
{
6362
_bellPlayer.Pause();
6463
_bellPlayer.Source(nullptr);
6564
_bellPlayer.Close();
65+
_bellPlayer = nullptr;
66+
_bellPlayerCreated = false;
6667
}
67-
_bellPlayer = nullptr;
6868
}
6969

7070
// Method Description:
@@ -168,19 +168,15 @@ namespace winrt::TerminalApp::implementation
168168
co_await wil::resume_foreground(_control.Dispatcher());
169169
if (auto pane{ weakThis.get() })
170170
{
171-
// BODGY
172-
// GH#12258: We learned that if you leave the MediaPlayer open, and
173-
// press the media keys (like play/pause), then the OS will _replay the
174-
// bell_. So we have to re-create the MediaPlayer each time we want to
175-
// play the bell, to make sure a subsequent play doesn't come through
176-
// and reactivate the old one.
177-
178-
if (!_bellPlayer)
171+
if (!_bellPlayerCreated)
179172
{
180173
// The MediaPlayer might not exist on Windows N SKU.
181174
try
182175
{
176+
_bellPlayerCreated = true;
183177
_bellPlayer = winrt::Windows::Media::Playback::MediaPlayer();
178+
// GH#12258: The media keys (like play/pause) should have no effect on our bell sound.
179+
_bellPlayer.CommandManager().IsEnabled(false);
184180
}
185181
CATCH_LOG();
186182
}
@@ -190,27 +186,6 @@ namespace winrt::TerminalApp::implementation
190186
const auto item{ winrt::Windows::Media::Playback::MediaPlaybackItem(source) };
191187
_bellPlayer.Source(item);
192188
_bellPlayer.Play();
193-
194-
// This lambda will clean up the bell player when we're done with it.
195-
auto weakThis2{ get_weak() };
196-
_mediaEndedRevoker = _bellPlayer.MediaEnded(winrt::auto_revoke, [weakThis2](auto&&, auto&&) {
197-
if (auto self{ weakThis2.get() })
198-
{
199-
if (self->_bellPlayer)
200-
{
201-
// We need to make sure clear out the current track
202-
// that's being played, again, so that the system can't
203-
// come through and replay it. In testing, we needed to
204-
// do this, closing the MediaPlayer alone wasn't good
205-
// enough.
206-
self->_bellPlayer.Pause();
207-
self->_bellPlayer.Source(nullptr);
208-
self->_bellPlayer.Close();
209-
}
210-
self->_mediaEndedRevoker.revoke();
211-
self->_bellPlayer = nullptr;
212-
}
213-
});
214189
}
215190
}
216191
}
@@ -223,7 +198,7 @@ namespace winrt::TerminalApp::implementation
223198
void TerminalPaneContent::_RestartTerminalRequestedHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/,
224199
const winrt::Windows::Foundation::IInspectable& /*args*/)
225200
{
226-
_RestartTerminalRequestedHandlers(*this, nullptr);
201+
RestartTerminalRequested.raise(*this, nullptr);
227202
}
228203

229204
void TerminalPaneContent::UpdateSettings(const TerminalSettingsCreateResult& settings,
@@ -232,4 +207,13 @@ namespace winrt::TerminalApp::implementation
232207
_profile = profile;
233208
_control.UpdateControlSettings(settings.DefaultSettings(), settings.UnfocusedSettings());
234209
}
210+
211+
// Method Description:
212+
// - Should be called when this pane is created via a default terminal handoff
213+
// - Finalizes our configuration given the information that we have been
214+
// created via default handoff
215+
void TerminalPaneContent::MarkAsDefterm()
216+
{
217+
_isDefTermSession = true;
218+
}
235219
}

src/cascadia/TerminalApp/TerminalPaneContent.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55
#include "TerminalPaneContent.g.h"
66
#include "../../cascadia/inc/cppwinrt_utils.h"
7+
#include <til/winrt.h>
78

89
namespace winrt::TerminalApp::implementation
910
{
@@ -21,6 +22,8 @@ namespace winrt::TerminalApp::implementation
2122
void UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult& settings,
2223
const winrt::Microsoft::Terminal::Settings::Model::Profile& profile);
2324

25+
void MarkAsDefterm();
26+
2427
winrt::Microsoft::Terminal::Settings::Model::Profile GetProfile() const
2528
{
2629
return _profile;
@@ -31,14 +34,16 @@ namespace winrt::TerminalApp::implementation
3134
uint64_t TaskbarProgress() { return _control.TaskbarProgress(); }
3235
bool ReadOnly() { return _control.ReadOnly(); }
3336

37+
til::typed_event<TerminalApp::TerminalPaneContent, winrt::Windows::Foundation::IInspectable> RestartTerminalRequested;
38+
3439
private:
3540
winrt::Microsoft::Terminal::Control::TermControl _control{ nullptr };
3641
winrt::Microsoft::Terminal::TerminalConnection::ConnectionState _connectionState{ winrt::Microsoft::Terminal::TerminalConnection::ConnectionState::NotConnected };
3742
winrt::Microsoft::Terminal::Settings::Model::Profile _profile{ nullptr };
3843
bool _isDefTermSession{ false };
3944

4045
winrt::Windows::Media::Playback::MediaPlayer _bellPlayer{ nullptr };
41-
winrt::Windows::Media::Playback::MediaPlayer::MediaEnded_revoker _mediaEndedRevoker;
46+
bool _bellPlayerCreated{ false };
4247

4348
struct ControlEventTokens
4449
{

src/cascadia/TerminalApp/TerminalPaneContent.idl

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ namespace TerminalApp
1212
void UpdateSettings(const Microsoft.Terminal.Settings.Model.TerminalSettingsCreateResult settings,
1313
const Microsoft.Terminal.Settings.Model.Profile profile);
1414

15+
void MarkAsDefterm();
16+
1517
Microsoft.Terminal.Settings.Model.Profile GetProfile();
18+
19+
20+
event Windows.Foundation.TypedEventHandler<TerminalPaneContent, Object> RestartTerminalRequested;
1621
}
1722
}

0 commit comments

Comments
 (0)