Skip to content

Commit 9b839e2

Browse files
committed
Add a setting for sending a notification on BEL
1 parent aeb531f commit 9b839e2

12 files changed

Lines changed: 43 additions & 8 deletions

File tree

doc/cascadia/profiles.schema.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
"enum": [
6161
"audible",
6262
"window",
63-
"taskbar"
63+
"taskbar",
64+
"notification"
6465
]
6566
}
6667
},
@@ -70,6 +71,7 @@
7071
"audible",
7172
"taskbar",
7273
"window",
74+
"notification",
7375
"all",
7476
"none"
7577
]

src/cascadia/TerminalApp/IPaneContent.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace TerminalApp
1414
runtimeclass BellEventArgs
1515
{
1616
Boolean FlashTaskbar { get; };
17+
Boolean SendNotification { get; };
1718
};
1819

1920
runtimeclass NotificationEventArgs

src/cascadia/TerminalApp/Tab.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,14 @@ namespace winrt::TerminalApp::implementation
11481148
tab->TabRaiseVisualBell.raise();
11491149
}
11501150

1151+
// Send a desktop toast notification if requested, but only if
1152+
// the pane isn't already in the belled state. This prevents
1153+
// sending repeated toasts for repeated BEL characters.
1154+
if (bellArgs.SendNotification() && !tab->_tabStatus.BellIndicator())
1155+
{
1156+
tab->TabToastNotificationRequested.raise(tab->Title(), L"", tab->TabViewIndex());
1157+
}
1158+
11511159
// Show the bell indicator in the tab header
11521160
tab->ShowBellIndicator(true);
11531161

src/cascadia/TerminalApp/TerminalPaneContent.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,11 @@ namespace winrt::TerminalApp::implementation
291291
_control.BellLightOn();
292292
}
293293

294-
// raise the event with the bool value corresponding to the taskbar flag
294+
// raise the event with the bool values corresponding to the taskbar and notification flags
295295
BellRequested.raise(*this,
296-
*winrt::make_self<TerminalApp::implementation::BellEventArgs>(WI_IsFlagSet(_profile.BellStyle(), BellStyle::Taskbar)));
296+
*winrt::make_self<TerminalApp::implementation::BellEventArgs>(
297+
WI_IsFlagSet(_profile.BellStyle(), BellStyle::Taskbar),
298+
WI_IsFlagSet(_profile.BellStyle(), BellStyle::Notification)));
297299
}
298300
}
299301
}

src/cascadia/TerminalApp/TerminalPaneContent.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ namespace winrt::TerminalApp::implementation
1414
struct BellEventArgs : public BellEventArgsT<BellEventArgs>
1515
{
1616
public:
17-
BellEventArgs(bool flashTaskbar) :
18-
FlashTaskbar(flashTaskbar) {}
17+
BellEventArgs(bool flashTaskbar, bool sendNotification) :
18+
FlashTaskbar(flashTaskbar), SendNotification(sendNotification) {}
1919

2020
til::property<bool> FlashTaskbar;
21+
til::property<bool> SendNotification;
2122
};
2223

2324
struct NotificationEventArgs : public NotificationEventArgsT<NotificationEventArgs>

src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
574574
hstring ProfileViewModel::BellStylePreview() const
575575
{
576576
const auto bellStyle = BellStyle();
577-
if (WI_AreAllFlagsSet(bellStyle, BellStyle::Audible | BellStyle::Window | BellStyle::Taskbar))
577+
if (WI_AreAllFlagsSet(bellStyle, BellStyle::Audible | BellStyle::Window | BellStyle::Taskbar | BellStyle::Notification))
578578
{
579579
return RS_(L"Profile_BellStyleAll/Content");
580580
}
@@ -584,7 +584,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
584584
}
585585

586586
std::vector<hstring> resultList;
587-
resultList.reserve(3);
587+
resultList.reserve(4);
588588
if (WI_IsFlagSet(bellStyle, BellStyle::Audible))
589589
{
590590
resultList.emplace_back(RS_(L"Profile_BellStyleAudible/Content"));
@@ -597,6 +597,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
597597
{
598598
resultList.emplace_back(RS_(L"Profile_BellStyleTaskbar/Content"));
599599
}
600+
if (WI_IsFlagSet(bellStyle, BellStyle::Notification))
601+
{
602+
resultList.emplace_back(RS_(L"Profile_BellStyleNotification/Content"));
603+
}
600604

601605
// add in the commas
602606
hstring result{};
@@ -640,6 +644,13 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
640644
BellStyle(currentStyle);
641645
}
642646

647+
void ProfileViewModel::SetBellStyleNotification(winrt::Windows::Foundation::IReference<bool> on)
648+
{
649+
auto currentStyle = BellStyle();
650+
WI_UpdateFlag(currentStyle, Model::BellStyle::Notification, winrt::unbox_value<bool>(on));
651+
BellStyle(currentStyle);
652+
}
653+
643654
// Method Description:
644655
// - Construct _CurrentBellSounds by importing the _inherited_ value from the model
645656
// - Adds a PropertyChanged handler to each BellSoundViewModel to propagate changes to the model

src/cascadia/TerminalSettingsEditor/ProfileViewModel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
4646
void SetBellStyleAudible(winrt::Windows::Foundation::IReference<bool> on);
4747
void SetBellStyleWindow(winrt::Windows::Foundation::IReference<bool> on);
4848
void SetBellStyleTaskbar(winrt::Windows::Foundation::IReference<bool> on);
49+
void SetBellStyleNotification(winrt::Windows::Foundation::IReference<bool> on);
4950

5051
hstring BellSoundPreview();
5152
void RequestAddBellSound(hstring path);

src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace Microsoft.Terminal.Settings.Editor
4949
void SetBellStyleAudible(Windows.Foundation.IReference<Boolean> on);
5050
void SetBellStyleWindow(Windows.Foundation.IReference<Boolean> on);
5151
void SetBellStyleTaskbar(Windows.Foundation.IReference<Boolean> on);
52+
void SetBellStyleNotification(Windows.Foundation.IReference<Boolean> on);
5253

5354
String BellSoundPreview { get; };
5455
Windows.Foundation.Collections.IObservableVector<BellSoundViewModel> CurrentBellSounds { get; };

src/cascadia/TerminalSettingsEditor/Profiles_Advanced.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@
111111
IsChecked="{x:Bind Profile.IsBellStyleFlagSet(2), BindBack=Profile.SetBellStyleWindow, Mode=TwoWay}" />
112112
<CheckBox x:Uid="Profile_BellStyleTaskbar"
113113
IsChecked="{x:Bind Profile.IsBellStyleFlagSet(4), BindBack=Profile.SetBellStyleTaskbar, Mode=TwoWay}" />
114+
<CheckBox x:Uid="Profile_BellStyleNotification"
115+
IsChecked="{x:Bind Profile.IsBellStyleFlagSet(8), BindBack=Profile.SetBellStyleNotification, Mode=TwoWay}" />
114116
</StackPanel>
115117
</local:SettingContainer>
116118

src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,10 @@
15531553
<value>Flash window</value>
15541554
<comment>An option to choose from for the "bell style" setting. When selected, a visual notification is used to notify the user. In this case, the window is flashed.</comment>
15551555
</data>
1556+
<data name="Profile_BellStyleNotification.Content" xml:space="preserve">
1557+
<value>Send notification</value>
1558+
<comment>An option to choose from for the "bell style" setting. When selected, a Windows desktop notification (toast) is sent to notify the user.</comment>
1559+
</data>
15561560
<data name="ColorScheme_AddNewButton.Text" xml:space="preserve">
15571561
<value>Add new</value>
15581562
<comment>Button label that creates a new color scheme.</comment>

0 commit comments

Comments
 (0)