diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json
index fe245e5caef..8df2b28457f 100644
--- a/doc/cascadia/profiles.schema.json
+++ b/doc/cascadia/profiles.schema.json
@@ -2988,6 +2988,85 @@
"description": "Sets the sound played when the application emits a BEL. When set to an array, the terminal will pick one of those sounds at random.",
"$ref": "#/$defs/BellSound"
},
+ "notifyOnActivity": {
+ "oneOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "array",
+ "items": {
+ "type": "string",
+ "enum": [
+ "taskbar",
+ "audible",
+ "tab",
+ "notification"
+ ]
+ }
+ },
+ {
+ "type": "string",
+ "enum": [
+ "taskbar",
+ "audible",
+ "tab",
+ "notification",
+ "all",
+ "none"
+ ]
+ }
+ ],
+ "description": "Controls how you are notified when an inactive tab produces new output."
+ },
+ "notifyOnNextPrompt": {
+ "oneOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "array",
+ "items": {
+ "type": "string",
+ "enum": [
+ "taskbar",
+ "audible",
+ "tab",
+ "notification"
+ ]
+ }
+ },
+ {
+ "type": "string",
+ "enum": [
+ "taskbar",
+ "audible",
+ "tab",
+ "notification",
+ "all",
+ "none"
+ ]
+ }
+ ],
+ "description": "Controls how you are notified when a new shell prompt is detected. Requires shell integration."
+ },
+ "notifyOnActivityThreshold": {
+ "type": "integer",
+ "minimum": 0,
+ "default": 5,
+ "description": "Minimum number of seconds between consecutive activity notifications for this profile. Use this to suppress repeated notifications from chatty processes. The first notification after the pane has been silent always fires; subsequent notifications within this window are suppressed. Use 0 to always notify."
+ },
+ "notifyOnNextPromptThreshold": {
+ "type": "integer",
+ "minimum": 0,
+ "default": 5,
+ "description": "Suppress the next-prompt notification unless the just-finished command ran for at least this many seconds. Requires shell integration. Use 0 to always notify."
+ },
+ "autoDetectRunningCommand": {
+ "default": false,
+ "description": "Automatically detect when a command is running and show a progress indicator in the tab and taskbar.",
+ "type": "boolean"
+ },
"closeOnExit": {
"default": "automatic",
"description": "Sets how the profile reacts to termination or failure to launch. Possible values:\n -\"graceful\" (close when exit is typed or the process exits normally)\n -\"always\" (always close)\n -\"automatic\" (behave as \"graceful\" only for processes launched by terminal, behave as \"always\" otherwise)\n -\"never\" (never close).\ntrue and false are accepted as synonyms for \"graceful\" and \"never\" respectively.",
diff --git a/src/cascadia/TerminalApp/CommandPalette.xaml b/src/cascadia/TerminalApp/CommandPalette.xaml
index b933173c771..adc38087d8e 100644
--- a/src/cascadia/TerminalApp/CommandPalette.xaml
+++ b/src/cascadia/TerminalApp/CommandPalette.xaml
@@ -231,6 +231,12 @@
Glyph=""
Visibility="{x:Bind Item.(local:TabPaletteItem.TabStatus).BellIndicator, Mode=OneWay}" />
+
+
Title() : notifArgs.Title();
- tab->TabToastNotificationRequested.raise(title, notifArgs.Body(), sender);
+ const auto activeContent = tab->GetActiveContent();
+ const auto isActivePaneContent = activeContent && activeContent == sender;
+
+ if (!notifArgs.AlwaysNotify() &&
+ (!Feature_NotifyOnActivity::IsEnabled() ||
+ (isActivePaneContent && tab->_focusState != WUX::FocusState::Unfocused)))
+ {
+ co_return;
+ }
+
+ const auto style = notifArgs.Style();
+
+ if (WI_IsFlagSet(style, OutputNotificationStyle::Taskbar))
+ {
+ tab->TabRaiseVisualBell.raise();
+ }
+
+ if (WI_IsFlagSet(style, winrt::Microsoft::Terminal::Control::OutputNotificationStyle::Audible))
+ {
+ if (const auto termContent{ sender.try_as() })
+ {
+ termContent.PlayNotificationSound();
+ }
+ }
+
+ if (WI_IsFlagSet(style, winrt::Microsoft::Terminal::Control::OutputNotificationStyle::Tab))
+ {
+ tab->ShowActivityIndicator(true);
+
+ if (tab->_focusState != WUX::FocusState::Unfocused)
+ {
+ tab->ActivateActivityIndicatorTimer();
+ }
+ }
+
+ if (WI_IsFlagSet(style, winrt::Microsoft::Terminal::Control::OutputNotificationStyle::Notification))
+ {
+ const auto title = notifArgs.Title().empty() ? tab->Title() : notifArgs.Title();
+ tab->TabToastNotificationRequested.raise(title, notifArgs.Body(), sender);
+ }
}
});
@@ -1282,11 +1350,10 @@ namespace winrt::TerminalApp::implementation
const auto taskbarState = state.State();
// The progress of the control changed, but not necessarily the progress of the tab.
// Set the tab's progress ring to the active pane's progress
- if (taskbarState > 0)
+ if (taskbarState != winrt::Microsoft::Terminal::Control::TaskbarState::Clear)
{
- if (taskbarState == 3)
+ if (taskbarState == winrt::Microsoft::Terminal::Control::TaskbarState::Indeterminate)
{
- // 3 is the indeterminate state, set the progress ring as such
_tabStatus.IsProgressRingIndeterminate(true);
}
else
@@ -1462,6 +1529,10 @@ namespace winrt::TerminalApp::implementation
{
tab->ShowBellIndicator(false);
}
+ if (tab->_tabStatus.ActivityIndicator())
+ {
+ tab->ShowActivityIndicator(false);
+ }
}
});
diff --git a/src/cascadia/TerminalApp/Tab.h b/src/cascadia/TerminalApp/Tab.h
index 3675ca5b1e5..f21d37c1132 100644
--- a/src/cascadia/TerminalApp/Tab.h
+++ b/src/cascadia/TerminalApp/Tab.h
@@ -48,6 +48,9 @@ namespace winrt::TerminalApp::implementation
void ShowBellIndicator(const bool show);
void ActivateBellIndicatorTimer();
+ void ShowActivityIndicator(const bool show);
+ void ActivateActivityIndicatorTimer();
+
float CalcSnappedDimension(const bool widthOrHeight, const float dimension) const;
std::optional PreCalculateCanSplit(winrt::Microsoft::Terminal::Settings::Model::SplitDirection splitType,
const float splitSize,
@@ -216,6 +219,9 @@ namespace winrt::TerminalApp::implementation
SafeDispatcherTimer _bellIndicatorTimer;
void _BellIndicatorTimerTick(const Windows::Foundation::IInspectable& sender, const Windows::Foundation::IInspectable& e);
+ SafeDispatcherTimer _activityIndicatorTimer;
+ void _ActivityIndicatorTimerTick(const Windows::Foundation::IInspectable& sender, const Windows::Foundation::IInspectable& e);
+
void _UpdateHeaderControlMaxWidth(const winrt::Microsoft::Terminal::Settings::Model::WindowSettings& windowSettings);
void _CreateContextMenu();
diff --git a/src/cascadia/TerminalApp/TabHeaderControl.xaml b/src/cascadia/TerminalApp/TabHeaderControl.xaml
index d44d7a0c7d9..83fc04f7b86 100644
--- a/src/cascadia/TerminalApp/TabHeaderControl.xaml
+++ b/src/cascadia/TerminalApp/TabHeaderControl.xaml
@@ -32,6 +32,12 @@
FontSize="12"
Glyph=""
Visibility="{x:Bind TabStatus.BellIndicator, Mode=OneWay}" />
+
Dispatcher().RunAsync(winrt::Windows::UI::Core::CoreDispatcherPriority::Normal, [weakPage{ page->get_weak() }, weakTab, weakContent]() {
- if (const auto p{ weakPage.get() })
+ page->Dispatcher().RunAsync(winrt::Windows::UI::Core::CoreDispatcherPriority::Normal, [weakThis, weakTab, weakContent]() {
+ if (const auto p{ weakThis.get() })
{
if (const auto t{ weakTab.get() })
{
diff --git a/src/cascadia/TerminalApp/TaskbarState.cpp b/src/cascadia/TerminalApp/TaskbarState.cpp
index ef9c34a75d1..e996fcba4dd 100644
--- a/src/cascadia/TerminalApp/TaskbarState.cpp
+++ b/src/cascadia/TerminalApp/TaskbarState.cpp
@@ -9,27 +9,28 @@ namespace winrt::TerminalApp::implementation
{
// Default to unset, 0%.
TaskbarState::TaskbarState() :
- TaskbarState(0, 0) {};
+ TaskbarState(winrt::Microsoft::Terminal::Control::TaskbarState::Clear, 0) {};
- TaskbarState::TaskbarState(const uint64_t dispatchTypesState, const uint64_t progressParam) :
- _State{ dispatchTypesState },
+ TaskbarState::TaskbarState(const winrt::Microsoft::Terminal::Control::TaskbarState state, const uint64_t progressParam) :
+ _State{ state },
_Progress{ progressParam } {}
uint64_t TaskbarState::Priority() const
{
// This seemingly nonsensical ordering is from
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-setprogressstate#how-the-taskbar-button-chooses-the-progress-indicator-for-a-group
+ using TbState = winrt::Microsoft::Terminal::Control::TaskbarState;
switch (_State)
{
- case 0: // Clear = 0,
+ case TbState::Clear:
return 5;
- case 1: // Set = 1,
+ case TbState::Set:
return 3;
- case 2: // Error = 2,
+ case TbState::Error:
return 1;
- case 3: // Indeterminate = 3,
+ case TbState::Indeterminate:
return 4;
- case 4: // Paused = 4
+ case TbState::Paused:
return 2;
}
// Here, return 6, to definitely be greater than all the other valid values.
diff --git a/src/cascadia/TerminalApp/TaskbarState.h b/src/cascadia/TerminalApp/TaskbarState.h
index 36100eeec79..84b22793e83 100644
--- a/src/cascadia/TerminalApp/TaskbarState.h
+++ b/src/cascadia/TerminalApp/TaskbarState.h
@@ -16,13 +16,13 @@ namespace winrt::TerminalApp::implementation
{
public:
TaskbarState();
- TaskbarState(const uint64_t dispatchTypesState, const uint64_t progress);
+ TaskbarState(const winrt::Microsoft::Terminal::Control::TaskbarState state, const uint64_t progress);
static int ComparePriority(const winrt::TerminalApp::TaskbarState& lhs, const winrt::TerminalApp::TaskbarState& rhs);
uint64_t Priority() const;
- WINRT_PROPERTY(uint64_t, State, 0);
+ WINRT_PROPERTY(winrt::Microsoft::Terminal::Control::TaskbarState, State, winrt::Microsoft::Terminal::Control::TaskbarState::Clear);
WINRT_PROPERTY(uint64_t, Progress, 0);
};
}
diff --git a/src/cascadia/TerminalApp/TaskbarState.idl b/src/cascadia/TerminalApp/TaskbarState.idl
index 159242a17b2..9734e5b609a 100644
--- a/src/cascadia/TerminalApp/TaskbarState.idl
+++ b/src/cascadia/TerminalApp/TaskbarState.idl
@@ -6,9 +6,9 @@ namespace TerminalApp
[default_interface] runtimeclass TaskbarState
{
TaskbarState();
- TaskbarState(UInt64 dispatchTypesState, UInt64 progress);
+ TaskbarState(Microsoft.Terminal.Control.TaskbarState state, UInt64 progress);
- UInt64 State{ get; };
+ Microsoft.Terminal.Control.TaskbarState State{ get; };
UInt64 Progress{ get; };
UInt64 Priority { get; };
}
diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.cpp b/src/cascadia/TerminalApp/TerminalPaneContent.cpp
index bdb72c941d9..6bebe5e344d 100644
--- a/src/cascadia/TerminalApp/TerminalPaneContent.cpp
+++ b/src/cascadia/TerminalApp/TerminalPaneContent.cpp
@@ -10,6 +10,7 @@
#include "../../types/inc/utils.hpp"
#include "BellEventArgs.g.cpp"
+#include "NotificationEventArgs.g.cpp"
#include "TerminalPaneContent.g.cpp"
using namespace winrt::Windows::Foundation;
@@ -34,6 +35,7 @@ namespace winrt::TerminalApp::implementation
{
_controlEvents._ConnectionStateChanged = _control.ConnectionStateChanged(winrt::auto_revoke, { this, &TerminalPaneContent::_controlConnectionStateChangedHandler });
_controlEvents._WarningBell = _control.WarningBell(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlWarningBellHandler });
+ _controlEvents._PromptStarted = _control.PromptStarted(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlPromptStartedHandler });
_controlEvents._CloseTerminalRequested = _control.CloseTerminalRequested(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_closeTerminalRequestedHandler });
_controlEvents._RestartTerminalRequested = _control.RestartTerminalRequested(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_restartTerminalRequestedHandler });
@@ -42,6 +44,8 @@ namespace winrt::TerminalApp::implementation
_controlEvents._SetTaskbarProgress = _control.SetTaskbarProgress(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlSetTaskbarProgress });
_controlEvents._ReadOnlyChanged = _control.ReadOnlyChanged(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlReadOnlyChanged });
_controlEvents._FocusFollowMouseRequested = _control.FocusFollowMouseRequested(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlFocusFollowMouseRequested });
+ _controlEvents._OutputStarted = _control.OutputStarted(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlOutputStartedHandler });
+ _controlEvents._OutputBurstEnded = _control.OutputIdle(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlOutputBurstEndedHandler });
_controlEvents._ShowNotification = _control.ShowNotification(winrt::auto_revoke, { get_weak(), &TerminalPaneContent::_controlShowNotification });
}
void TerminalPaneContent::_removeControlEvents()
@@ -162,6 +166,16 @@ namespace winrt::TerminalApp::implementation
{
TaskbarProgressChanged.raise(*this, nullptr);
}
+
+ winrt::Microsoft::Terminal::Control::TaskbarState TerminalPaneContent::TaskbarState()
+ {
+ return _control.TaskbarState();
+ }
+
+ uint64_t TerminalPaneContent::TaskbarProgress()
+ {
+ return _control.TaskbarProgress();
+ }
void TerminalPaneContent::_controlReadOnlyChanged(const IInspectable&, const IInspectable&)
{
ReadOnlyChanged.raise(*this, nullptr);
@@ -173,7 +187,7 @@ namespace winrt::TerminalApp::implementation
void TerminalPaneContent::_controlShowNotification(const IInspectable& /*sender*/, const ShowNotificationEventArgs& args)
{
- NotificationRequested.raise(*this, winrt::make(args.Title(), args.Body()));
+ NotificationRequested.raise(*this, winrt::make(OutputNotificationStyle::Notification, true /*alwaysNotify*/, args.Title(), args.Body()));
}
// Method Description:
@@ -255,6 +269,26 @@ namespace winrt::TerminalApp::implementation
// has the 'visual' flag set
// Arguments:
// -
+ void TerminalPaneContent::PlayNotificationSound()
+ {
+ if (_profile)
+ {
+ auto sounds{ _profile.BellSound() };
+ if (sounds && sounds.Size() > 0)
+ {
+ // Sound paths are resolved and validated by CascadiaSettings
+ // before we reach this point.
+ auto soundPath{ sounds.GetAt(rand() % sounds.Size()).Resolved() };
+ PlaySoundW(soundPath.c_str(), nullptr, SND_FILENAME | SND_ASYNC | SND_SENTRY | SND_NODEFAULT);
+ }
+ else
+ {
+ const auto soundAlias = reinterpret_cast(SND_ALIAS_SYSTEMHAND);
+ PlaySoundW(soundAlias, nullptr, SND_ALIAS_ID | SND_ASYNC | SND_SENTRY);
+ }
+ }
+ }
+
void TerminalPaneContent::_controlWarningBellHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/,
const winrt::Windows::Foundation::IInspectable& /*eventArgs*/)
{
@@ -266,19 +300,7 @@ namespace winrt::TerminalApp::implementation
if (WI_IsFlagSet(_profile.BellStyle(), winrt::Microsoft::Terminal::Settings::Model::BellStyle::Audible))
{
// Audible is set, play the sound
- auto sounds{ _profile.BellSound() };
- if (sounds && sounds.Size() > 0)
- {
- // Sound paths are resolved and validated by CascadiaSettings
- // before we reach this point.
- auto soundPath{ sounds.GetAt(rand() % sounds.Size()).Resolved() };
- PlaySoundW(soundPath.c_str(), nullptr, SND_FILENAME | SND_ASYNC | SND_SENTRY | SND_NODEFAULT);
- }
- else
- {
- const auto soundAlias = reinterpret_cast(SND_ALIAS_SYSTEMHAND);
- PlaySoundW(soundAlias, nullptr, SND_ALIAS_ID | SND_ASYNC | SND_SENTRY);
- }
+ PlayNotificationSound();
}
if (WI_IsFlagSet(_profile.BellStyle(), winrt::Microsoft::Terminal::Settings::Model::BellStyle::Window))
@@ -295,6 +317,67 @@ namespace winrt::TerminalApp::implementation
}
}
+ void TerminalPaneContent::_controlPromptStartedHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/,
+ const winrt::Windows::Foundation::IInspectable& /*eventArgs*/)
+ {
+ if (_profile)
+ {
+ const auto notifyStyle = _profile.NotifyOnNextPrompt();
+ if (notifyStyle != OutputNotificationStyle::None)
+ {
+ if (const auto thresholdInSeconds = _profile.NotifyOnNextPromptThreshold(); thresholdInSeconds > 0)
+ {
+ if (_lastOutputStartedAt == 0)
+ {
+ return;
+ }
+ if (const auto elapsedMs = GetTickCount64() - _lastOutputStartedAt; elapsedMs < (static_cast(thresholdInSeconds) * 1000))
+ {
+ _lastOutputStartedAt = 0;
+ return;
+ }
+ }
+ _lastOutputStartedAt = 0;
+
+ NotificationRequested.raise(*this,
+ *winrt::make_self(notifyStyle, false));
+ }
+ }
+ }
+
+ void TerminalPaneContent::_controlOutputStartedHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/,
+ const winrt::Windows::Foundation::IInspectable& /*eventArgs*/)
+ {
+ _lastOutputStartedAt = GetTickCount64();
+ }
+
+ // The underlying TermControl::OutputIdle event is fired on the trailing
+ // edge of a 100ms-debounced output burst (see ControlCore::Initialize).
+ // When "notifyOnActivity" is enabled, we get one event per burst of
+ // output, which naturally coalesces a stream of output into a single notification.
+ void TerminalPaneContent::_controlOutputBurstEndedHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/,
+ const winrt::Windows::Foundation::IInspectable& /*eventArgs*/)
+ {
+ if (_profile)
+ {
+ const auto notifyStyle = _profile.NotifyOnActivity();
+ if (notifyStyle != OutputNotificationStyle::None)
+ {
+ const auto now = GetTickCount64();
+ const auto thresholdSeconds = _profile.NotifyOnActivityThreshold();
+ if (thresholdSeconds > 0 &&
+ _lastActivityNotificationAt != 0 &&
+ (now - _lastActivityNotificationAt) < (static_cast(thresholdSeconds) * 1000))
+ {
+ return;
+ }
+ _lastActivityNotificationAt = now;
+
+ NotificationRequested.raise(*this,
+ *winrt::make_self(notifyStyle, false));
+ }
+ }
+ }
void TerminalPaneContent::_closeTerminalRequestedHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/,
const winrt::Windows::Foundation::IInspectable& /*args*/)
{
diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.h b/src/cascadia/TerminalApp/TerminalPaneContent.h
index b04d4de9955..71f02b9580d 100644
--- a/src/cascadia/TerminalApp/TerminalPaneContent.h
+++ b/src/cascadia/TerminalApp/TerminalPaneContent.h
@@ -24,9 +24,11 @@ namespace winrt::TerminalApp::implementation
struct NotificationEventArgs : public NotificationEventArgsT
{
public:
- NotificationEventArgs(const winrt::hstring& title = {}, const winrt::hstring& body = {}) :
- Title(title), Body(body) {}
+ NotificationEventArgs(winrt::Microsoft::Terminal::Control::OutputNotificationStyle style, bool alwaysNotify = true, const winrt::hstring& title = {}, const winrt::hstring& body = {}) :
+ Style(style), AlwaysNotify(alwaysNotify), Title(title), Body(body) {}
+ til::property Style;
+ til::property AlwaysNotify;
til::property Title;
til::property Body;
};
@@ -49,6 +51,7 @@ namespace winrt::TerminalApp::implementation
const winrt::Microsoft::Terminal::Settings::Model::WindowSettings& windowSettings);
void MarkAsDefterm();
+ void PlayNotificationSound();
winrt::Microsoft::Terminal::Settings::Model::Profile GetProfile() const
{
@@ -56,8 +59,8 @@ namespace winrt::TerminalApp::implementation
}
winrt::hstring Title() { return _control.Title(); }
- uint64_t TaskbarState() { return _control.TaskbarState(); }
- uint64_t TaskbarProgress() { return _control.TaskbarProgress(); }
+ winrt::Microsoft::Terminal::Control::TaskbarState TaskbarState();
+ uint64_t TaskbarProgress();
bool ReadOnly() { return _control.ReadOnly(); }
winrt::hstring Icon() const;
Windows::Foundation::IReference TabColor() const noexcept;
@@ -77,10 +80,18 @@ namespace winrt::TerminalApp::implementation
std::shared_ptr _cache{};
bool _isDefTermSession{ false };
+ // Tracks the GetTickCount64() for NotifyOnActivityThreshold
+ // and NotifyOnNextPromptThreshold respectively.
+ uint64_t _lastActivityNotificationAt{ 0 };
+ uint64_t _lastOutputStartedAt{ 0 };
+
struct ControlEventTokens
{
winrt::Microsoft::Terminal::Control::TermControl::ConnectionStateChanged_revoker _ConnectionStateChanged;
winrt::Microsoft::Terminal::Control::TermControl::WarningBell_revoker _WarningBell;
+ winrt::Microsoft::Terminal::Control::TermControl::PromptStarted_revoker _PromptStarted;
+ winrt::Microsoft::Terminal::Control::TermControl::OutputStarted_revoker _OutputStarted;
+ winrt::Microsoft::Terminal::Control::TermControl::OutputIdle_revoker _OutputBurstEnded;
winrt::Microsoft::Terminal::Control::TermControl::CloseTerminalRequested_revoker _CloseTerminalRequested;
winrt::Microsoft::Terminal::Control::TermControl::RestartTerminalRequested_revoker _RestartTerminalRequested;
@@ -98,6 +109,9 @@ namespace winrt::TerminalApp::implementation
safe_void_coroutine _controlConnectionStateChangedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
void _controlWarningBellHandler(const winrt::Windows::Foundation::IInspectable& sender,
const winrt::Windows::Foundation::IInspectable& e);
+ void _controlPromptStartedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& eventArgs);
+ void _controlOutputStartedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& eventArgs);
+ void _controlOutputBurstEndedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& eventArgs);
void _controlReadOnlyChangedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& e);
void _controlTitleChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args);
diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.idl b/src/cascadia/TerminalApp/TerminalPaneContent.idl
index 53dcf4c3379..36a1612c181 100644
--- a/src/cascadia/TerminalApp/TerminalPaneContent.idl
+++ b/src/cascadia/TerminalApp/TerminalPaneContent.idl
@@ -11,6 +11,7 @@ namespace TerminalApp
Microsoft.Terminal.Control.TermControl GetTermControl();
void MarkAsDefterm();
+ void PlayNotificationSound();
Microsoft.Terminal.Settings.Model.Profile GetProfile();
diff --git a/src/cascadia/TerminalApp/TerminalTabStatus.h b/src/cascadia/TerminalApp/TerminalTabStatus.h
index 8d1d015193b..81166b89ae5 100644
--- a/src/cascadia/TerminalApp/TerminalTabStatus.h
+++ b/src/cascadia/TerminalApp/TerminalTabStatus.h
@@ -17,6 +17,7 @@ namespace winrt::TerminalApp::implementation
WINRT_OBSERVABLE_PROPERTY(bool, IsProgressRingActive, PropertyChanged.raise);
WINRT_OBSERVABLE_PROPERTY(bool, IsProgressRingIndeterminate, PropertyChanged.raise);
WINRT_OBSERVABLE_PROPERTY(bool, BellIndicator, PropertyChanged.raise);
+ WINRT_OBSERVABLE_PROPERTY(bool, ActivityIndicator, PropertyChanged.raise);
WINRT_OBSERVABLE_PROPERTY(bool, IsReadOnlyActive, PropertyChanged.raise);
WINRT_OBSERVABLE_PROPERTY(uint32_t, ProgressValue, PropertyChanged.raise);
WINRT_OBSERVABLE_PROPERTY(bool, IsInputBroadcastActive, PropertyChanged.raise);
diff --git a/src/cascadia/TerminalApp/TerminalTabStatus.idl b/src/cascadia/TerminalApp/TerminalTabStatus.idl
index d5664c76c6c..f91199a632b 100644
--- a/src/cascadia/TerminalApp/TerminalTabStatus.idl
+++ b/src/cascadia/TerminalApp/TerminalTabStatus.idl
@@ -12,6 +12,7 @@ namespace TerminalApp
Boolean IsProgressRingActive { get; set; };
Boolean IsProgressRingIndeterminate { get; set; };
Boolean BellIndicator { get; set; };
+ Boolean ActivityIndicator { get; set; };
UInt32 ProgressValue { get; set; };
Boolean IsReadOnlyActive { get; set; };
Boolean IsInputBroadcastActive { get; set; };
diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp
index d9c1561f5ac..a93822430f9 100644
--- a/src/cascadia/TerminalControl/ControlCore.cpp
+++ b/src/cascadia/TerminalControl/ControlCore.cpp
@@ -138,6 +138,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
auto pfnSearchMissingCommand = [this](auto&& PH1, auto&& PH2) { _terminalSearchMissingCommand(std::forward(PH1), std::forward(PH2)); };
_terminal->SetSearchMissingCommandCallback(pfnSearchMissingCommand);
+ auto pfnPromptStarted = [this] { _terminalPromptStarted(); };
+ _terminal->SetPromptStartedCallback(pfnPromptStarted);
+
+ auto pfnOutputStarted = [this] { _terminalOutputStarted(); };
+ _terminal->SetOutputStartedCallback(pfnOutputStarted);
+
auto pfnShowNotification = [this](auto&& PH1, auto&& PH2) { _terminalShowNotification(std::forward(PH1), std::forward(PH2)); };
_terminal->SetShowNotificationCallback(pfnShowNotification);
@@ -974,6 +980,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_hasUnfocusedAppearance = static_cast(newAppearance);
_unfocusedAppearance = _hasUnfocusedAppearance ? newAppearance : settings;
+ // Cache the auto-detect setting in an atomic so the off-thread output/prompt
+ // callbacks can read it without synchronizing with _settings. If the effective
+ // taskbar state changes (because a command is currently active and the setting
+ // toggled), notify listeners.
+ const auto nowEnabled = Feature_NotifyOnActivity::IsEnabled() && _settings.AutoDetectRunningCommand();
+ const auto wasEnabled = _autoDetectCommandActivity.exchange(nowEnabled, std::memory_order_relaxed);
+ if (wasEnabled != nowEnabled && _commandActive.load(std::memory_order_relaxed))
+ {
+ TaskbarProgressChanged.raise(*this, nullptr);
+ }
+
{
const auto lock = _terminal->LockForWriting();
@@ -1638,10 +1655,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// - Gets the internal taskbar state value
// Return Value:
// - The taskbar state of this control
- const size_t ControlCore::TaskbarState() const noexcept
+ const Control::TaskbarState ControlCore::TaskbarState() const noexcept
{
const auto lock = _terminal->LockForReading();
- return _terminal->GetTaskbarState();
+ const auto vtState = static_cast(_terminal->GetTaskbarState());
+ if (vtState == Control::TaskbarState::Clear &&
+ _autoDetectCommandActivity.load(std::memory_order_relaxed) &&
+ _commandActive.load(std::memory_order_relaxed))
+ {
+ return Control::TaskbarState::Indeterminate;
+ }
+ return vtState;
}
// Method Description:
@@ -1686,6 +1710,26 @@ namespace winrt::Microsoft::Terminal::Control::implementation
WarningBell.raise(*this, nullptr);
}
+ void ControlCore::_terminalPromptStarted()
+ {
+ if (_commandActive.exchange(false, std::memory_order_relaxed) &&
+ _autoDetectCommandActivity.load(std::memory_order_relaxed))
+ {
+ TaskbarProgressChanged.raise(*this, nullptr);
+ }
+ PromptStarted.raise(*this, nullptr);
+ }
+
+ void ControlCore::_terminalOutputStarted()
+ {
+ if (!_commandActive.exchange(true, std::memory_order_relaxed) &&
+ _autoDetectCommandActivity.load(std::memory_order_relaxed))
+ {
+ TaskbarProgressChanged.raise(*this, nullptr);
+ }
+ OutputStarted.raise(*this, nullptr);
+ }
+
// Method Description:
// - Called for the Terminal's TitleChanged callback. This will re-raise
// a new winrt TypedEvent that can be listened to.
diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h
index b860f52d829..f7145ca45c6 100644
--- a/src/cascadia/TerminalControl/ControlCore.h
+++ b/src/cascadia/TerminalControl/ControlCore.h
@@ -166,7 +166,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void OpenCWD();
#pragma region ICoreState
- const size_t TaskbarState() const noexcept;
+ const Control::TaskbarState TaskbarState() const noexcept;
const size_t TaskbarProgress() const noexcept;
hstring Title();
@@ -289,6 +289,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
til::typed_event TitleChanged;
til::typed_event WriteToClipboard;
til::typed_event<> WarningBell;
+ til::typed_event<> PromptStarted;
+ til::typed_event<> OutputStarted;
til::typed_event<> TabColorChanged;
til::typed_event<> BackgroundColorChanged;
til::typed_event ScrollPositionChanged;
@@ -338,6 +340,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
#pragma region TerminalCoreCallbacks
void _terminalWarningBell();
+ void _terminalPromptStarted();
+ void _terminalOutputStarted();
void _terminalTitleChanged(std::wstring_view wstr);
void _terminalScrollPositionChanged(const int viewTop,
const int viewHeight,
@@ -436,6 +440,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
std::optional _lastHoveredCell;
::Microsoft::Terminal::Core::Terminal::HyperlinkInfo _lastHoveredLink;
std::atomic _initializedTerminal{ false };
+ std::atomic _autoDetectCommandActivity{ false };
+ std::atomic _commandActive{ false };
bool _isReadOnly{ false };
bool _closing{ false };
diff --git a/src/cascadia/TerminalControl/IControlSettings.idl b/src/cascadia/TerminalControl/IControlSettings.idl
index 97c75f1ab07..99f829ca90c 100644
--- a/src/cascadia/TerminalControl/IControlSettings.idl
+++ b/src/cascadia/TerminalControl/IControlSettings.idl
@@ -29,6 +29,30 @@ namespace Microsoft.Terminal.Control
MinGW,
};
+ [flags]
+ enum OutputNotificationStyle
+ {
+ None = 0,
+ Taskbar = 0x1,
+ Audible = 0x2,
+ Tab = 0x4,
+ Notification = 0x8,
+ All = 0xffffffff
+ };
+
+ // Mirrors Microsoft::Console::VirtualTerminal::DispatchTypes::TaskbarState
+ // (which is shared with conhost and lives outside the WinRT projection).
+ // Values must remain numerically identical so the conversion at the
+ // ControlCore boundary is a 1:1 cast.
+ enum TaskbarState
+ {
+ Clear = 0,
+ Set = 1,
+ Error = 2,
+ Indeterminate = 3,
+ Paused = 4,
+ };
+
// Class Description:
// TerminalSettings encapsulates all settings that control the
// TermControl's behavior. In these settings there is both the entirety
@@ -79,6 +103,12 @@ namespace Microsoft.Terminal.Control
PathTranslationStyle PathTranslationStyle { get; };
String DragDropDelimiter { get; };
+ OutputNotificationStyle NotifyOnActivity { get; };
+ OutputNotificationStyle NotifyOnNextPrompt { get; };
+ Int32 NotifyOnActivityThreshold { get; };
+ Int32 NotifyOnNextPromptThreshold { get; };
+ Boolean AutoDetectRunningCommand { get; };
+
// NOTE! When adding something here, make sure to update ControlProperties.h too!
};
}
diff --git a/src/cascadia/TerminalControl/ICoreState.idl b/src/cascadia/TerminalControl/ICoreState.idl
index 48a8e4a43c8..bc0a88e9347 100644
--- a/src/cascadia/TerminalControl/ICoreState.idl
+++ b/src/cascadia/TerminalControl/ICoreState.idl
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
+import "IControlSettings.idl";
+
namespace Microsoft.Terminal.Control
{
enum MarkCategory
@@ -31,7 +33,7 @@ namespace Microsoft.Terminal.Control
interface ICoreState
{
String Title { get; };
- UInt64 TaskbarState { get; };
+ Microsoft.Terminal.Control.TaskbarState TaskbarState { get; };
UInt64 TaskbarProgress { get; };
String WorkingDirectory { get; };
diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp
index 0f3ba0e705e..75890a438e4 100644
--- a/src/cascadia/TerminalControl/TermControl.cpp
+++ b/src/cascadia/TerminalControl/TermControl.cpp
@@ -413,6 +413,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// attached content before we set up the throttled func, and that'll A/V
_revokers.coreScrollPositionChanged = _core->ScrollPositionChanged(winrt::auto_revoke, { get_weak(), &TermControl::_ScrollPositionChanged });
_revokers.WarningBell = _core->WarningBell(winrt::auto_revoke, { get_weak(), &TermControl::_coreWarningBell });
+ _revokers.PromptStarted = _core->PromptStarted(winrt::auto_revoke, { get_weak(), &TermControl::_corePromptStarted });
+ _revokers.OutputStarted = _core->OutputStarted(winrt::auto_revoke, { get_weak(), &TermControl::_coreOutputStarted });
_ApplyUISettings();
@@ -3257,7 +3259,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// - Gets the internal taskbar state value
// Return Value:
// - The taskbar state of this control
- const uint64_t TermControl::TaskbarState() const noexcept
+ const Control::TaskbarState TermControl::TaskbarState() const noexcept
{
return _core->TaskbarState();
}
@@ -3627,6 +3629,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_playWarningBell->Run();
}
+ void TermControl::_corePromptStarted(const IInspectable& /*sender*/, const IInspectable& /*args*/)
+ {
+ PromptStarted.raise(*this, nullptr);
+ }
+
+ void TermControl::_coreOutputStarted(const IInspectable& /*sender*/, const IInspectable& /*args*/)
+ {
+ OutputStarted.raise(*this, nullptr);
+ }
+
hstring TermControl::ReadEntireBuffer() const
{
return _core->ReadEntireBuffer();
@@ -3744,6 +3756,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void TermControl::_coreOutputIdle(const IInspectable& /*sender*/, const IInspectable& /*args*/)
{
_refreshSearch();
+ OutputIdle.raise(*this, nullptr);
}
void TermControl::OwningHwnd(uint64_t owner)
diff --git a/src/cascadia/TerminalControl/TermControl.h b/src/cascadia/TerminalControl/TermControl.h
index 71af8d691a1..d0fccd1fd5c 100644
--- a/src/cascadia/TerminalControl/TermControl.h
+++ b/src/cascadia/TerminalControl/TermControl.h
@@ -92,7 +92,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void ColorSelection(Control::SelectionColor fg, Control::SelectionColor bg, Core::MatchMode matchMode);
#pragma region ICoreState
- const uint64_t TaskbarState() const noexcept;
+ const Control::TaskbarState TaskbarState() const noexcept;
const uint64_t TaskbarProgress() const noexcept;
hstring Title();
@@ -218,6 +218,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
til::typed_event FocusFollowMouseRequested;
til::typed_event Initialized;
til::typed_event<> WarningBell;
+ til::typed_event<> PromptStarted;
+ til::typed_event<> OutputStarted;
+ til::typed_event<> OutputIdle;
til::typed_event KeySent;
til::typed_event CharSent;
til::typed_event StringSent;
@@ -421,6 +424,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void _coreTransparencyChanged(IInspectable sender, Control::TransparencyChangedEventArgs args);
void _coreRaisedNotice(const IInspectable& s, const Control::NoticeEventArgs& args);
void _coreWarningBell(const IInspectable& sender, const IInspectable& args);
+ void _corePromptStarted(const IInspectable& sender, const IInspectable& args);
+ void _coreOutputStarted(const IInspectable& sender, const IInspectable& args);
void _coreOutputIdle(const IInspectable& sender, const IInspectable& args);
winrt::Windows::Foundation::Point _toPosInDips(const Core::Point terminalCellPos);
@@ -444,6 +449,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
til::event_revoker coreScrollPositionChanged;
til::event_revoker WarningBell;
+ til::event_revoker PromptStarted;
+ til::event_revoker OutputStarted;
til::event_revoker RendererEnteredErrorState;
til::event_revoker BackgroundColorChanged;
til::event_revoker FontSizeChanged;
diff --git a/src/cascadia/TerminalControl/TermControl.idl b/src/cascadia/TerminalControl/TermControl.idl
index 4c51342c3a1..d6dabae34c9 100644
--- a/src/cascadia/TerminalControl/TermControl.idl
+++ b/src/cascadia/TerminalControl/TermControl.idl
@@ -88,6 +88,9 @@ namespace Microsoft.Terminal.Control
event Windows.Foundation.TypedEventHandler