Skip to content

Add a setting for sending a notification on BEL#20011

Open
carlos-zamora wants to merge 3 commits intodev/cazamor/toast/basefrom
dev/cazamor/toast/bellStyle
Open

Add a setting for sending a notification on BEL#20011
carlos-zamora wants to merge 3 commits intodev/cazamor/toast/basefrom
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.

@carlos-zamora carlos-zamora force-pushed the dev/cazamor/toast/bellStyle branch from a1048d0 to 99a2976 Compare March 25, 2026 21:47
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/toast/bellStyle branch from db209a1 to 16581fe Compare April 17, 2026 02:06
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.

2 participants