Skip to content

Add a setting for sending a notification on BEL#20011

Merged
carlos-zamora merged 14 commits into
mainfrom
dev/cazamor/toast/bellStyle
May 4, 2026
Merged

Add a setting for sending a notification on BEL#20011
carlos-zamora merged 14 commits into
mainfrom
dev/cazamor/toast/bellStyle

Conversation

@carlos-zamora
Copy link
Copy Markdown
Member

@carlos-zamora carlos-zamora commented Mar 24, 2026

Summary of the Pull Request

Targets #20010

Adds another bellStyle flag option. This sends a windows toast notification to the user when a BEL is encountered

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

@carlos-zamora
Copy link
Copy Markdown
Member Author

carlos-zamora commented Mar 24, 2026

The only change I made was I changed the settings UI string from "Send notification" to "Desktop notification"

image

Separately, I noticed that the default here is audible. A few related questions:

  1. Any interest in adding "desktop notification" as the default too?
    • I'm leaning "no". Particularly because I know that I hit a BEL in WSL every time I backspace into the prompt and that would be annoying haha. Wanted to poll for opinions though.
  2. visual in the JSON maps to window + taskbar. Should notification be added here too?
    • Kinda torn. It is visual, but it's also kinda outside the frame of the terminal, so I feel like it's a completely different thing.

I also played around with it and I noticed this:

  1. open WSL - Ubuntu terminal
  2. create BEL (backspace into prompt)
  3. Get notification
image 4. Click notification 5. Get a new Terminal window!

I double checked and we are hitting this code in AppCommandlineArgs::ParseArgs() as expected:

// When a toast notification is clicked, Windows may launch a new instance
// with "__fromToast" as the argument. This is a no-op sentinel — the
// in-process Activated handler on the toast already handled activation.
// See DesktopNotification.cpp for more details.
if (args.size() == 2 && args[1] == L"__fromToast")
{
return 0;
}

Shouldn't we refocus the tab/pane that sent the notification instead? @zadjii-msft thoughts?

@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/bellStyle branch from 324223d to a1048d0 Compare March 25, 2026 17:40
Comment on lines +1151 to +1157
// Send a desktop toast notification if requested, but only if
// the pane isn't already in the belled state. This prevents
// sending repeated toasts for repeated BEL characters.
if (bellArgs.SendNotification() && !tab->_tabStatus.BellIndicator())
{
tab->TabToastNotificationRequested.raise(tab->Title(), L"", tab->TabViewIndex());
}
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.

Would this send a toast every 3s if I send a bell every 3s? Is it a concern to us to throttle this even further? (I'd probably lean to "no", personally.)

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.

We have a throttle in DesktopNotification here:

bool DesktopNotification::ShouldSendNotification()
{
FILETIME ft{};
GetSystemTimeAsFileTime(&ft);
const auto now = (static_cast<int64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
auto last = _lastNotificationTime.load(std::memory_order_relaxed);
if (now - last < MinNotificationIntervalTicks)
{
return false;
}
// Attempt to update; if another thread beat us, that's fine — we'll skip this one.
return _lastNotificationTime.compare_exchange_strong(last, now, std::memory_order_relaxed);
}

It's currently set to 5 seconds:

static constexpr int64_t MinNotificationIntervalTicks = 50'000'000LL;

The flow is:
TabToastNotificationRequested --> TerminalPage::_SendDesktopNotification() --> DesktopNotification::SendNotification()

So I think the 5s throttle is good, but we can adjust it if we want.

## 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/bellStyle branch from a1048d0 to 99a2976 Compare March 25, 2026 21:47
lhecker
lhecker previously approved these changes Mar 25, 2026
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/toast/bellStyle branch from db209a1 to 16581fe Compare April 17, 2026 02:06
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/toast/bellStyle branch from 16581fe to ec8f1ec Compare April 29, 2026 23:32
carlos-zamora added a commit that referenced this pull request Apr 30, 2026
## Summary of the Pull Request
Adds the infrastructure for toast notifications. Breakdown:
- `DesktopNotification`:
- `DesktopNotificationArgs` includes the struct to group all
notification-related data together.
   - `SendNotification()` actually sends it
- `AppCommandlineArgs.cpp`: added a check for the `--from-toast` no-op
sentinel; ensures no new window is created
- Most of the other changes are just bubbling up the notification from
the `TerminalPaneContent` to `TerminalPage`
- `TabManagement.cpp`: `_SendDesktopNotification()` does the final
packaging of the notification before calling the `DesktopNotification`
API

This supports finding the right tab when it's been reordered or even
moved to a new window!
This also has expanded to support finding the right pane, which is
resilient to pane swaps/closing too. When the pane can't be found, we
just fallback to the tab.
If the pane is already focused, we don't send a notification.

This simply adds the infrastructure! Looks like nothing can actually
take advantage of it yet, but it's been tested with the changes in
#20011.

Heavily based on #19935
Co-authored by @zadjii-msft
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.

@carlos-zamora carlos-zamora merged commit a834313 into main May 4, 2026
20 checks passed
@carlos-zamora carlos-zamora deleted the dev/cazamor/toast/bellStyle branch May 4, 2026 17:38
Qmoony pushed a commit to Qmoony/terminal that referenced this pull request May 11, 2026
## Summary of the Pull Request
Adds the infrastructure for toast notifications. Breakdown:
- `DesktopNotification`:
- `DesktopNotificationArgs` includes the struct to group all
notification-related data together.
   - `SendNotification()` actually sends it
- `AppCommandlineArgs.cpp`: added a check for the `--from-toast` no-op
sentinel; ensures no new window is created
- Most of the other changes are just bubbling up the notification from
the `TerminalPaneContent` to `TerminalPage`
- `TabManagement.cpp`: `_SendDesktopNotification()` does the final
packaging of the notification before calling the `DesktopNotification`
API

This supports finding the right tab when it's been reordered or even
moved to a new window!
This also has expanded to support finding the right pane, which is
resilient to pane swaps/closing too. When the pane can't be found, we
just fallback to the tab.
If the pane is already focused, we don't send a notification.

This simply adds the infrastructure! Looks like nothing can actually
take advantage of it yet, but it's been tested with the changes in
microsoft#20011.

Heavily based on microsoft#19935
Co-authored by @zadjii-msft
Qmoony pushed a commit to Qmoony/terminal that referenced this pull request May 11, 2026
## Summary of the Pull Request
Targets microsoft#20010 

Adds another `bellStyle` flag option. This sends a windows toast
notification to the user when a BEL is encountered

- [X] Closes microsoft#18605 
- [ ] Documentation updated

Heavily based on microsoft#19936 
Co-authored by @zadjii-msft
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows Notification on Bell

2 participants