Skip to content

Commit

Permalink
Merge pull request #1251 from Ne02ptzero/master
Browse files Browse the repository at this point in the history
feat: Enable window alert on terminal bells
  • Loading branch information
Yaraslaut committed Oct 11, 2023
2 parents b22f34d + 40281d1 commit 73e6c75
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 12 deletions.
11 changes: 8 additions & 3 deletions docs/configuration/profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,18 @@ profiles:


### `bell`
Configuration option permits adjusting the sound of `BEL` (also `\a` or `0x07`) to `off` or `default` or sound generated by a file located at `path`.

Configuration section permits tuning the behavior of the terminal bell.

``` yaml
profiles:
profile_name:
bell: "default"
bell:
sound: "default"
alert: false
```

:octicons-horizontal-rule-16: ==sound== This option determines the sound of `BEL` (also `\a` or `0x07`) to `off` or `default` or sound generated by a file located at `path`. <br />
:octicons-horizontal-rule-16: ==alert== This option determines whether or not a window alert will be raised each time a bell is ringed. Useful for tiling window managers like i3 or sway.


### `wm_class`
Expand Down
1 change: 1 addition & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<li>Adds config entry `profile.*.size_indicator_on_resize` to control size indicator on resize and makes resize indicator small.</li>
<li>Adds OpenSelection action, and honor case in the configuration bindings</li>
<li>Adds open resource (URL, local file) feature also to vi mode.</li>
<li>Adds configurable window alerts on terminal bells.</li>
</ul>
</description>
</release>
Expand Down
8 changes: 6 additions & 2 deletions src/contour/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1805,16 +1805,20 @@ namespace
terminalProfile.syncWindowTitleWithHostWritableStatusDisplay = boolValue;

strValue = "default";
if (tryLoadChildRelative(usedKeys, profile, basePath, "bell", strValue, logger))
if (tryLoadChildRelative(usedKeys, profile, basePath, "bell.sound", strValue, logger))
{
if (!strValue.empty())
{
if (strValue != "off" && strValue != "default")
strValue = "file:" + strValue;
terminalProfile.bell = strValue;
terminalProfile.bell.sound = strValue;
}
}

boolValue = false;
if (tryLoadChildRelative(usedKeys, profile, basePath, "bell.alert", boolValue, logger))
terminalProfile.bell.alert = boolValue;

if (auto value = profile["slow_scrolling_time"])
{
usedKeys.emplace(basePath + ".slow_scrolling_time");
Expand Down
6 changes: 5 additions & 1 deletion src/contour/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@ struct TerminalProfile
vtrasterizer::Decorator hover = vtrasterizer::Decorator::Underline;
} hyperlinkDecoration;

std::string bell = "default";
struct
{
std::string sound = "default";
bool alert = true;
} bell;

// Set of DEC modes that are frozen and cannot be changed by the application.
std::map<vtbackend::DECMode, bool> frozenModes;
Expand Down
2 changes: 1 addition & 1 deletion src/contour/ContourGuiApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ int ContourGuiApp::terminalGuiAction()
// Spawn initial window.
newWindow();

if (auto const& bell = config().profile().bell; bell == "off")
if (auto const& bell = config().profile().bell.sound; bell == "off")
{
if (auto* bellAudioOutput = _qmlEngine->rootObjects().first()->findChild<QObject*>("BellAudioOutput");
bellAudioOutput)
Expand Down
3 changes: 3 additions & 0 deletions src/contour/TerminalSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ void TerminalSession::terminate()
void TerminalSession::bell()
{
emit onBell();

if (_profile.bell.alert)
emit onAlert();
}

void TerminalSession::bufferChanged(vtbackend::ScreenType type)
Expand Down
1 change: 1 addition & 0 deletions src/contour/TerminalSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ class TerminalSession: public QAbstractItemModel, public vtbackend::Terminal::Ev
void isScrollbarVisibleChanged();
void opacityChanged();
void onBell();
void onAlert();
void requestPermissionForFontChange();
void requestPermissionForBufferCapture();
void requestPermissionForShowHostWritableStatusLine();
Expand Down
14 changes: 9 additions & 5 deletions src/contour/contour.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,15 @@ profiles:
# whether or not to put the window into maximized mode.
maximized: false

# There is no sound for BEL character if set to "off".
# If set to "default" BEL character sound will be default sound.
# If set to path to a file then BEL sound will use that file. Example
# bell: "/home/user/Music/bell.wav"
bell: "default"
bell:
# There is no sound for BEL character if set to "off".
# If set to "default" BEL character sound will be default sound.
# If set to path to a file then BEL sound will use that file. Example
# sound: "/home/user/Music/bell.wav"
sound: "default"

# If this boolean is true, a window alert will be raised with each bell
alert: true

# Defines the class part of the WM_CLASS property of the window.
wm_class: "contour"
Expand Down
7 changes: 7 additions & 0 deletions src/contour/ui.template/Terminal.qml.in
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ ContourTerminal
bellSoundEffect.play()
}

function doAlert() {
Window.window.alert(0);
}

function updateFontSize() {
sizeWidgetText.font.pointSize = vtWidget.session.fontSize
}
Expand All @@ -206,6 +210,9 @@ ContourTerminal
// Connect bell control code with an actual sound effect.
vt.onBell.connect(playBell);

// Connect alert control of the window
vt.onAlert.connect(doAlert);

// Link showNotification signal.
vt.onShowNotification.connect(vtWidget.showNotification);

Expand Down

0 comments on commit 73e6c75

Please sign in to comment.