Skip to content

Add support for OSC777 (Send Notification)#20012

Open
carlos-zamora wants to merge 22 commits intomainfrom
dev/cazamor/toast/osc777
Open

Add support for OSC777 (Send Notification)#20012
carlos-zamora wants to merge 22 commits intomainfrom
dev/cazamor/toast/osc777

Conversation

@carlos-zamora
Copy link
Copy Markdown
Member

Summary of the Pull Request

targets #20010

This adds support for the OSC 777 ; notify ; title ; body ST sequence. This allows client applications to send a notification to the Terminal. When this notification is clicked, it summons the terminal window that sent it.

Validation Steps Performed

# in PowerShell. Terminal should not be focused.
sleep 2; Write-Output "`e]777;notify;Hello;This is a notification`a"

PR Checklist

Heavily based on #19938
Co-authored by @zadjii-msft

Comment thread src/terminal/adapter/adaptDispatch.cpp Outdated
Comment thread src/terminal/adapter/adaptDispatch.cpp
Comment thread src/terminal/parser/OutputStateMachineEngine.cpp Outdated
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/toast/base branch from 4357c17 to aeb531f Compare March 25, 2026 17:29
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/toast/osc777 branch from 2f5763e to 34b985d Compare March 25, 2026 17:51
Comment thread src/terminal/adapter/ITermDispatch.hpp Fixed
Comment thread src/terminal/adapter/adaptDispatch.cpp Fixed
Comment thread src/terminal/adapter/adaptDispatch.cpp Fixed
Comment thread src/terminal/adapter/adaptDispatch.hpp Fixed
Comment thread src/terminal/adapter/termDispatch.hpp Fixed
Comment thread src/terminal/parser/OutputStateMachineEngine.cpp Fixed
@github-actions

This comment has been minimized.

## Summary of the Pull Request
Targets #20010 

Manually assign an AUMID to our process when we're running unpackaged.
Main difference from #19937 is what AUMID we use. Before, it was per
branding, but the `WindowEmperor` already appends an exe path hash for
unpackaged instances to prevent crosstalk. Here, we're just using the
same pattern: `Microsoft.WindowsTerminal.<hash>`.

Heavily based on #19937
Co-authored by @zadjii-msft
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/toast/osc777 branch from 34b985d to 7ea4f2f Compare March 25, 2026 21:49
Comment thread .github/actions/spelling/expect/expect.txt Fixed
@github-actions

This comment has been minimized.

Comment thread src/terminal/adapter/adaptDispatch.cpp Outdated
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/toast/osc777 branch from 7a378e1 to 33546f1 Compare March 27, 2026 01:36
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@carlos-zamora carlos-zamora force-pushed the dev/cazamor/toast/osc777 branch from 5788845 to 36c361e Compare April 17, 2026 02:08
lhecker
lhecker previously approved these changes Apr 21, 2026
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/toast/osc777 branch from 36c361e to d4ff09f Compare April 29, 2026 23:33
Base automatically changed from dev/cazamor/toast/base to main April 30, 2026 00:24
@carlos-zamora carlos-zamora dismissed lhecker’s stale review April 30, 2026 00:24

The base branch was changed.

@microsoft-github-policy-service microsoft-github-policy-service Bot added Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Area-VT Virtual Terminal sequence support Product-Terminal The new Windows Terminal. labels Apr 30, 2026
Comment thread src/cascadia/inc/ControlProperties.h Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, this seems wrong. it's not "Activity," is it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I think this one's fine, actually. It's all used here:

void TerminalPage::_SendDesktopNotification(const winrt::hstring& tabTitle, const winrt::hstring& body, const winrt::com_ptr<Tab>& tab, const winrt::TerminalApp::IPaneContent& content)
{
// Don't send a notification if the window is focused and the requesting
// pane is the active pane. The user is already looking at it.
if (_activated && tab == _GetFocusedTabImpl())
{
if (const auto activePane{ tab->GetActivePane() })
{
if (activePane->GetContent() == content)
{
return;
}
}
}
// Build the notification message.
// If a custom body is provided (e.g. from OSC 777), use the title/body directly.
// Otherwise, build the standard tab-activity notification message.
winrt::hstring notificationTitle;
winrt::hstring message;
if (!body.empty())
{
notificationTitle = tabTitle;
message = body;
}
else
{
// Use the window name if available for context; otherwise just use the tab title.
// Use the raw WindowName (not WindowNameForDisplay) so we don't include
// the "<unnamed window>" placeholder in the notification body.
const auto windowName = _WindowProperties ? _WindowProperties.WindowName() : winrt::hstring{};
if (!windowName.empty())
{
message = RS_fmt(L"NotificationMessage_TabActivityInWindow", std::wstring_view{ tabTitle }, std::wstring_view{ windowName });
}
else
{
message = RS_fmt(L"NotificationMessage_TabActivity", std::wstring_view{ tabTitle });
}
notificationTitle = CascadiaSettings::ApplicationDisplayName();
}

So, if OSC777 includes a body, we use the body & title from the sequence.
Otherwise, we fall back to these resources to say a generic "Activity in tab X".

Open to suggestions.

Comment thread src/cascadia/TerminalApp/DesktopNotification.cpp Outdated
Comment thread src/cascadia/TerminalApp/DesktopNotification.cpp
Comment thread src/cascadia/TerminalApp/TabManagement.cpp
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qq: why does this need a public class type of its own? It's an implementation detail used only inside TerminalApp to talk to TerminalApp

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really just because we're using...

//  IPaneContent.idl
event Windows.Foundation.TypedEventHandler<IPaneContent, NotificationEventArgs> NotificationRequested;

I could update it to using a delegate so that we don't have a new public class type and we just pass the payload directly instead. Deciding against that in this PR because (1) it's a different style from the other ones in this file and (2) #20014 also uses this system to pass the payload up.

That said, I'm open to doing that as a follow-up once both of these merge. I think it's worth it and it looks nicer.

To get an idea of what it would look like:

// IPaneContent.idl
delegate void NotificationRequestedHandler(String title, String body);

interface IPaneContent
{
   event NotificationRequestedHandler NotificationRequested;
}

@microsoft-github-policy-service microsoft-github-policy-service Bot added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels May 4, 2026
@carlos-zamora
Copy link
Copy Markdown
Member Author

Feedback from Bug Bash (5/5)

  • should be disabled by default

@DHowett Got a reason why? Is it that we just don't want applications to spam the user with notifications?

@carlos-zamora
Copy link
Copy Markdown
Member Author

Updated default to false.

Validated that this works. Can be tested using:

Write-Host "$([char]27)]777;notify;Title;Message$([char]27)\"

@carlos-zamora carlos-zamora requested a review from DHowett May 5, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-VT Virtual Terminal sequence support Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Terminal The new Windows Terminal. zBugBash-Consider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send Desktop Notification via VT Sequence (OSC777)

5 participants