Skip to content

Commit cd871b1

Browse files
committed
PRE-MERGE #20012 Add support for OSC777 (Send Notification)
2 parents b05ae68 + 5788845 commit cd871b1

35 files changed

Lines changed: 164 additions & 1 deletion

.github/actions/spelling/expect/expect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,6 +1797,7 @@ UPKEY
17971797
upss
17981798
uregex
17991799
URegular
1800+
urxvt
18001801
usebackq
18011802
USECALLBACK
18021803
USECOLOR

doc/cascadia/profiles.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,6 +2787,11 @@
27872787
"description": "When set to true, VT applications will be allowed to set the contents of the local clipboard using OSC 52 (Manipulate Selection Data).",
27882788
"type": "boolean"
27892789
},
2790+
"compatibility.allowOSC777": {
2791+
"default": true,
2792+
"description": "When set to true, applications can send OSC 777 escape sequences to trigger desktop toast notifications with a custom title and body.",
2793+
"type": "boolean"
2794+
},
27902795
"unfocusedAppearance": {
27912796
"$ref": "#/$defs/AppearanceConfig",
27922797
"description": "Sets the appearance of the terminal when it is unfocused.",

src/cascadia/TerminalApp/TerminalPaneContent.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace winrt::TerminalApp::implementation
4646
_controlEvents._ReadOnlyChanged = _control.ReadOnlyChanged(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlReadOnlyChanged });
4747
_controlEvents._FocusFollowMouseRequested = _control.FocusFollowMouseRequested(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlFocusFollowMouseRequested });
4848
_controlEvents._OutputIdle = _control.OutputIdle(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlOutputIdleHandler });
49+
_controlEvents._ShowNotification = _control.ShowNotification(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlShowNotification });
4950
}
5051
void TerminalPaneContent::_removeControlEvents()
5152
{
@@ -210,6 +211,11 @@ namespace winrt::TerminalApp::implementation
210211
FocusRequested.raise(*this, nullptr);
211212
}
212213

214+
void TerminalPaneContent::_controlShowNotification(const IInspectable& /*sender*/, const ShowNotificationEventArgs& args)
215+
{
216+
NotificationRequested.raise(*this, winrt::make<implementation::NotificationEventArgs>(args.Title(), args.Body()));
217+
}
218+
213219
// Method Description:
214220
// - Called when our attached control is closed. Triggers listeners to our close
215221
// event, if we're a leaf pane.

src/cascadia/TerminalApp/TerminalPaneContent.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ namespace winrt::TerminalApp::implementation
9898
winrt::Microsoft::Terminal::Control::TermControl::SetTaskbarProgress_revoker _SetTaskbarProgress;
9999
winrt::Microsoft::Terminal::Control::TermControl::ReadOnlyChanged_revoker _ReadOnlyChanged;
100100
winrt::Microsoft::Terminal::Control::TermControl::FocusFollowMouseRequested_revoker _FocusFollowMouseRequested;
101+
winrt::Microsoft::Terminal::Control::TermControl::ShowNotification_revoker _ShowNotification;
101102

102103
} _controlEvents;
103104
void _setupControlEvents();
@@ -118,6 +119,7 @@ namespace winrt::TerminalApp::implementation
118119
void _controlSetTaskbarProgress(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args);
119120
void _controlReadOnlyChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args);
120121
void _controlFocusFollowMouseRequested(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args);
122+
void _controlShowNotification(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Microsoft::Terminal::Control::ShowNotificationEventArgs& args);
121123

122124
void _closeTerminalRequestedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
123125
void _restartTerminalRequestedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);

src/cascadia/TerminalControl/ControlCore.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
144144

145145
auto pfnOutputStarted = [this] { _terminalOutputStarted(); };
146146
_terminal->SetOutputStartedCallback(pfnOutputStarted);
147+
148+
auto pfnShowNotification = [this](auto&& PH1, auto&& PH2) { _terminalShowNotification(std::forward<decltype(PH1)>(PH1), std::forward<decltype(PH2)>(PH2)); };
149+
_terminal->SetShowNotificationCallback(pfnShowNotification);
147150

148151
auto pfnClearQuickFix = [this] { ClearQuickFix(); };
149152
_terminal->SetClearQuickFixCallback(pfnClearQuickFix);
@@ -1727,6 +1730,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
17271730
SearchMissingCommand.raise(*this, make<implementation::SearchMissingCommandEventArgs>(hstring{ missingCommand }, bufferRow));
17281731
}
17291732

1733+
void ControlCore::_terminalShowNotification(std::wstring_view title, std::wstring_view body)
1734+
{
1735+
ShowNotification.raise(*this, make<implementation::ShowNotificationEventArgs>(hstring{ title }, hstring{ body }));
1736+
}
1737+
17301738
void ControlCore::OpenCWD()
17311739
{
17321740
const auto workingDirectory = WorkingDirectory();

src/cascadia/TerminalControl/ControlCore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
294294
til::typed_event<IInspectable, Control::OpenHyperlinkEventArgs> OpenHyperlink;
295295
til::typed_event<IInspectable, Control::CompletionsChangedEventArgs> CompletionsChanged;
296296
til::typed_event<IInspectable, Control::SearchMissingCommandEventArgs> SearchMissingCommand;
297+
til::typed_event<IInspectable, Control::ShowNotificationEventArgs> ShowNotification;
297298
til::typed_event<> RefreshQuickFixUI;
298299
til::typed_event<IInspectable, Control::WindowSizeChangedEventArgs> WindowSizeChanged;
299300

@@ -337,6 +338,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
337338
const int velocity,
338339
const std::chrono::microseconds duration);
339340
void _terminalSearchMissingCommand(std::wstring_view missingCommand, const til::CoordType& bufferRow);
341+
void _terminalShowNotification(std::wstring_view title, std::wstring_view body);
340342
void _terminalWindowSizeChanged(int32_t width, int32_t height);
341343

342344
void _terminalCompletionsChanged(std::wstring_view menuJson, unsigned int replaceLength);

src/cascadia/TerminalControl/ControlCore.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ namespace Microsoft.Terminal.Control
200200
event Windows.Foundation.TypedEventHandler<Object, Object> RendererEnteredErrorState;
201201
event Windows.Foundation.TypedEventHandler<Object, ShowWindowArgs> ShowWindowChanged;
202202
event Windows.Foundation.TypedEventHandler<Object, SearchMissingCommandEventArgs> SearchMissingCommand;
203+
event Windows.Foundation.TypedEventHandler<Object, ShowNotificationEventArgs> ShowNotification;
203204
event Windows.Foundation.TypedEventHandler<Object, Object> RefreshQuickFixUI;
204205
event Windows.Foundation.TypedEventHandler<Object, WindowSizeChangedEventArgs> WindowSizeChanged;
205206

src/cascadia/TerminalControl/EventArgs.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "CharSentEventArgs.g.h"
2121
#include "StringSentEventArgs.g.h"
2222
#include "SearchMissingCommandEventArgs.g.h"
23+
#include "ShowNotificationEventArgs.g.h"
2324
#include "WindowSizeChangedEventArgs.g.h"
2425

2526
namespace winrt::Microsoft::Terminal::Control::implementation
@@ -252,6 +253,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation
252253
til::property<til::CoordType> BufferRow;
253254
};
254255

256+
struct ShowNotificationEventArgs : public ShowNotificationEventArgsT<ShowNotificationEventArgs>
257+
{
258+
public:
259+
ShowNotificationEventArgs(const winrt::hstring& title, const winrt::hstring& body) :
260+
Title(title),
261+
Body(body) {}
262+
263+
til::property<winrt::hstring> Title;
264+
til::property<winrt::hstring> Body;
265+
};
266+
255267
struct WindowSizeChangedEventArgs : public WindowSizeChangedEventArgsT<WindowSizeChangedEventArgs>
256268
{
257269
public:

src/cascadia/TerminalControl/EventArgs.idl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ namespace Microsoft.Terminal.Control
160160
Int32 BufferRow { get; };
161161
}
162162

163+
runtimeclass ShowNotificationEventArgs
164+
{
165+
String Title { get; };
166+
String Body { get; };
167+
}
168+
163169
runtimeclass WindowSizeChangedEventArgs
164170
{
165171
Int32 Width;

src/cascadia/TerminalControl/TermControl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
328328
_revokers.CompletionsChanged = _core.CompletionsChanged(winrt::auto_revoke, { get_weak(), &TermControl::_bubbleCompletionsChanged });
329329
_revokers.RestartTerminalRequested = _core.RestartTerminalRequested(winrt::auto_revoke, { get_weak(), &TermControl::_bubbleRestartTerminalRequested });
330330
_revokers.SearchMissingCommand = _core.SearchMissingCommand(winrt::auto_revoke, { get_weak(), &TermControl::_bubbleSearchMissingCommand });
331+
_revokers.ShowNotification = _core.ShowNotification(winrt::auto_revoke, { get_weak(), &TermControl::_bubbleShowNotification });
331332
_revokers.WindowSizeChanged = _core.WindowSizeChanged(winrt::auto_revoke, { get_weak(), &TermControl::_bubbleWindowSizeChanged });
332333
_revokers.WriteToClipboard = _core.WriteToClipboard(winrt::auto_revoke, { get_weak(), &TermControl::_bubbleWriteToClipboard });
333334

0 commit comments

Comments
 (0)