Skip to content

Commit a1da6c1

Browse files
committed
huge shuffling so that pane content can raise events instead of relying on termcontrol
1 parent 7c9ffb0 commit a1da6c1

11 files changed

+356
-445
lines changed

src/cascadia/TerminalApp/IPaneContent.idl

+14-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
namespace TerminalApp
55
{
6+
7+
runtimeclass BellEventArgs
8+
{
9+
Boolean FlashTaskbar { get; };
10+
};
11+
612
interface IPaneContent
713
{
814
Windows.UI.Xaml.FrameworkElement GetRoot();
@@ -16,12 +22,18 @@ namespace TerminalApp
1622

1723
Microsoft.Terminal.Settings.Model.NewTerminalArgs GetNewTerminalArgs(Boolean asContent);
1824

19-
void Focus();
25+
void Focus(Windows.UI.Xaml.FocusState reason);
2026

2127
void Close();
22-
// event CloseRequested(...);
2328

2429
event Windows.Foundation.TypedEventHandler<Object, Object> CloseRequested;
30+
31+
event Windows.Foundation.TypedEventHandler<Object, BellEventArgs> BellRequested;
32+
event Windows.Foundation.TypedEventHandler<Object, Object> TitleChanged;
33+
event Windows.Foundation.TypedEventHandler<Object, Object> TabColorChanged;
34+
event Windows.Foundation.TypedEventHandler<Object, Object> TaskbarProgressChanged;
35+
event Windows.Foundation.TypedEventHandler<Object, Object> ReadOnlyChanged;
36+
event Windows.Foundation.TypedEventHandler<Object, Object> FocusRequested;
2537
};
2638

2739

src/cascadia/TerminalApp/Pane.cpp

+144-327
Large diffs are not rendered by default.

src/cascadia/TerminalApp/Pane.h

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class Pane : public std::enable_shared_from_this<Pane>
8888
}
8989

9090
winrt::Windows::UI::Xaml::Controls::Grid GetRootElement();
91+
winrt::TerminalApp::IPaneContent GetContent() const noexcept { return _IsLeaf() ? _content : nullptr; }
9192

9293
bool WasLastFocused() const noexcept;
9394
void UpdateVisuals();

src/cascadia/TerminalApp/PaneArgs.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
#include "pch.h"
5+
#include "PaneArgs.h"
6+
#include "BellEventArgs.g.cpp"

src/cascadia/TerminalApp/PaneArgs.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
#pragma once
5+
6+
#include "BellEventArgs.g.h"
7+
8+
namespace winrt::TerminalApp::implementation
9+
{
10+
struct BellEventArgs : public BellEventArgsT<BellEventArgs>
11+
{
12+
public:
13+
BellEventArgs(bool flashTaskbar) :
14+
FlashTaskbar(flashTaskbar) {}
15+
16+
til::property<bool> FlashTaskbar;
17+
};
18+
};

src/cascadia/TerminalApp/TerminalAppLib.vcxproj

+6
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@
131131
<DependentUpon>EmptyStringVisibilityConverter.idl</DependentUpon>
132132
</ClInclude>
133133
<ClInclude Include="Pane.h" />
134+
<ClInclude Include="PaneArgs.h">
135+
<DependentUpon>IPaneContent.idl</DependentUpon>
136+
</ClInclude>
134137
<ClInclude Include="ColorHelper.h" />
135138
<ClInclude Include="pch.h" />
136139
<ClInclude Include="ShortcutActionDispatch.h">
@@ -233,6 +236,9 @@
233236
<DependentUpon>EmptyStringVisibilityConverter.idl</DependentUpon>
234237
</ClCompile>
235238
<ClCompile Include="Pane.cpp" />
239+
<ClCompile Include="PaneArgs.cpp">
240+
<DependentUpon>IPaneContent.idl</DependentUpon>
241+
</ClCompile>
236242
<ClCompile Include="Pane.LayoutSizeNode.cpp" />
237243
<ClCompile Include="ColorHelper.cpp" />
238244
<ClCompile Include="DebugTapConnection.cpp" />

src/cascadia/TerminalApp/TerminalPaneContent.cpp

+36-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "pch.h"
55
#include "TerminalPaneContent.h"
6+
#include "PaneArgs.h"
67
#include "TerminalPaneContent.g.cpp"
78

89
#include <Mmsystem.h>
@@ -25,9 +26,15 @@ namespace winrt::TerminalApp::implementation
2526
void TerminalPaneContent::_setupControlEvents()
2627
{
2728
_controlEvents._ConnectionStateChanged = _control.ConnectionStateChanged(winrt::auto_revoke, { this, &TerminalPaneContent::_ControlConnectionStateChangedHandler });
28-
_controlEvents._WarningBell = _control.WarningBell(winrt::auto_revoke, { this, &TerminalPaneContent::_ControlWarningBellHandler });
29-
_controlEvents._CloseTerminalRequested = _control.CloseTerminalRequested(winrt::auto_revoke, { this, &TerminalPaneContent::_CloseTerminalRequestedHandler });
30-
_controlEvents._RestartTerminalRequested = _control.RestartTerminalRequested(winrt::auto_revoke, { this, &TerminalPaneContent::_RestartTerminalRequestedHandler });
29+
_controlEvents._WarningBell = _control.WarningBell(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_ControlWarningBellHandler });
30+
_controlEvents._CloseTerminalRequested = _control.CloseTerminalRequested(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_CloseTerminalRequestedHandler });
31+
_controlEvents._RestartTerminalRequested = _control.RestartTerminalRequested(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_RestartTerminalRequestedHandler });
32+
33+
_controlEvents._TitleChanged = _control.TitleChanged(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlTitleChanged });
34+
_controlEvents._TabColorChanged = _control.TabColorChanged(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlTabColorChanged });
35+
_controlEvents._SetTaskbarProgress = _control.SetTaskbarProgress(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlSetTaskbarProgress });
36+
_controlEvents._ReadOnlyChanged = _control.ReadOnlyChanged(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlReadOnlyChanged });
37+
_controlEvents._FocusFollowMouseRequested = _control.FocusFollowMouseRequested(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlFocusFollowMouseRequested });
3138
}
3239
void TerminalPaneContent::_removeControlEvents()
3340
{
@@ -46,9 +53,9 @@ namespace winrt::TerminalApp::implementation
4653
{
4754
return _control.MinimumSize();
4855
}
49-
void TerminalPaneContent::Focus()
56+
void TerminalPaneContent::Focus(winrt::Windows::UI::Xaml::FocusState reason)
5057
{
51-
_control.Focus(FocusState::Programmatic);
58+
_control.Focus(reason);
5259
}
5360
void TerminalPaneContent::Close()
5461
{
@@ -122,6 +129,27 @@ namespace winrt::TerminalApp::implementation
122129
return args;
123130
}
124131

132+
void TerminalPaneContent::_controlTitleChanged(const IInspectable&, const IInspectable&)
133+
{
134+
TitleChanged.raise(*this, nullptr);
135+
}
136+
void TerminalPaneContent::_controlTabColorChanged(const IInspectable&, const IInspectable&)
137+
{
138+
TabColorChanged.raise(*this, nullptr);
139+
}
140+
void TerminalPaneContent::_controlSetTaskbarProgress(const IInspectable&, const IInspectable&)
141+
{
142+
TaskbarProgressChanged.raise(*this, nullptr);
143+
}
144+
void TerminalPaneContent::_controlReadOnlyChanged(const IInspectable&, const IInspectable&)
145+
{
146+
ReadOnlyChanged.raise(*this, nullptr);
147+
}
148+
void TerminalPaneContent::_controlFocusFollowMouseRequested(const IInspectable&, const IInspectable&)
149+
{
150+
FocusRequested.raise(*this, nullptr);
151+
}
152+
125153
// Method Description:
126154
// - Called when our attached control is closed. Triggers listeners to our close
127155
// event, if we're a leaf pane.
@@ -209,9 +237,9 @@ namespace winrt::TerminalApp::implementation
209237
_control.BellLightOn();
210238
}
211239

212-
// TODO!
213-
// // raise the event with the bool value corresponding to the taskbar flag
214-
// _PaneRaiseBellHandlers(nullptr, WI_IsFlagSet(_profile.BellStyle(), winrt::Microsoft::Terminal::Settings::Model::BellStyle::Taskbar));
240+
// raise the event with the bool value corresponding to the taskbar flag
241+
BellRequested.raise(*this,
242+
*winrt::make_self<TerminalApp::implementation::BellEventArgs>(WI_IsFlagSet(_profile.BellStyle(), BellStyle::Taskbar)));
215243
}
216244
}
217245
}

src/cascadia/TerminalApp/TerminalPaneContent.h

+23-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace winrt::TerminalApp::implementation
1616
winrt::Windows::UI::Xaml::FrameworkElement GetRoot();
1717
winrt::Microsoft::Terminal::Control::TermControl GetTerminal();
1818
winrt::Windows::Foundation::Size MinSize();
19-
void Focus();
19+
void Focus(winrt::Windows::UI::Xaml::FocusState reason = winrt::Windows::UI::Xaml::FocusState::Programmatic);
2020
void Close();
2121

2222
winrt::Microsoft::Terminal::Settings::Model::NewTerminalArgs GetNewTerminalArgs(const bool asContent) const;
@@ -41,6 +41,12 @@ namespace winrt::TerminalApp::implementation
4141

4242
til::typed_event<TerminalApp::TerminalPaneContent, winrt::Windows::Foundation::IInspectable> RestartTerminalRequested;
4343
til::typed_event<> CloseRequested;
44+
til::typed_event<winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::BellEventArgs> BellRequested;
45+
til::typed_event<> TitleChanged;
46+
til::typed_event<> TabColorChanged;
47+
til::typed_event<> TaskbarProgressChanged;
48+
til::typed_event<> ReadOnlyChanged;
49+
til::typed_event<> FocusRequested;
4450

4551
private:
4652
winrt::Microsoft::Terminal::Control::TermControl _control{ nullptr };
@@ -57,6 +63,13 @@ namespace winrt::TerminalApp::implementation
5763
winrt::Microsoft::Terminal::Control::TermControl::WarningBell_revoker _WarningBell;
5864
winrt::Microsoft::Terminal::Control::TermControl::CloseTerminalRequested_revoker _CloseTerminalRequested;
5965
winrt::Microsoft::Terminal::Control::TermControl::RestartTerminalRequested_revoker _RestartTerminalRequested;
66+
67+
winrt::Microsoft::Terminal::Control::TermControl::TitleChanged_revoker _TitleChanged;
68+
winrt::Microsoft::Terminal::Control::TermControl::TabColorChanged_revoker _TabColorChanged;
69+
winrt::Microsoft::Terminal::Control::TermControl::SetTaskbarProgress_revoker _SetTaskbarProgress;
70+
winrt::Microsoft::Terminal::Control::TermControl::ReadOnlyChanged_revoker _ReadOnlyChanged;
71+
winrt::Microsoft::Terminal::Control::TermControl::FocusFollowMouseRequested_revoker _FocusFollowMouseRequested;
72+
6073
} _controlEvents;
6174
void _setupControlEvents();
6275
void _removeControlEvents();
@@ -66,11 +79,19 @@ namespace winrt::TerminalApp::implementation
6679
void _ControlConnectionStateChangedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
6780
void _ControlWarningBellHandler(const winrt::Windows::Foundation::IInspectable& sender,
6881
const winrt::Windows::Foundation::IInspectable& e);
82+
83+
void _controlTitleChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args);
84+
void _controlTabColorChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args);
85+
void _controlSetTaskbarProgress(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args);
86+
void _controlReadOnlyChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args);
87+
void _controlFocusFollowMouseRequested(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args);
88+
6989
// void _ControlGotFocusHandler(const winrt::Windows::Foundation::IInspectable& sender,
7090
// const winrt::Windows::UI::Xaml::RoutedEventArgs& e);
7191
// void _ControlLostFocusHandler(const winrt::Windows::Foundation::IInspectable& sender,
7292
// const winrt::Windows::UI::Xaml::RoutedEventArgs& e);
73-
void _CloseTerminalRequestedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
93+
void
94+
_CloseTerminalRequestedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
7495
void _RestartTerminalRequestedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
7596
};
7697
}

0 commit comments

Comments
 (0)