Skip to content

Commit

Permalink
add audible_bell config option
Browse files Browse the repository at this point in the history
This allows using the system beep sound, currently only on macos.

refs: #3
  • Loading branch information
wez committed Sep 26, 2021
1 parent 9be8f92 commit 72cb110
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 2 deletions.
13 changes: 13 additions & 0 deletions config/src/bell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ pub struct VisualBell {
pub fade_out_function: EasingFunction,
}
impl_lua_conversion!(VisualBell);

#[derive(Debug, Deserialize, Serialize, Clone)]
pub enum AudibleBell {
SystemBeep,
Disabled,
}
impl_lua_conversion!(AudibleBell);

impl Default for AudibleBell {
fn default() -> AudibleBell {
Self::SystemBeep
}
}
3 changes: 3 additions & 0 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,9 @@ pub struct Config {

#[serde(default)]
pub visual_bell: VisualBell,

#[serde(default)]
pub audible_bell: AudibleBell,
}
impl_lua_conversion!(Config);

Expand Down
2 changes: 1 addition & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ As features stabilize some brief notes about them will accumulate here.
* Fixed: italic fonts weren't always recognized as being italic, resulting in italic variants being used instead of the non-italic variants in some cases! [#1162](https://github.com/wez/wezterm/issues/1162)
* New: [bell](config/lua/window-events/bell.md) event allows you to trigger lua code when the bell is run. [#3](https://github.com/wez/wezterm/issues/3)
* Fixed: Ask freetype for cell metrics in bitmap-only fonts, rather than simply taking the bitmap width. [#1165](https://github.com/wez/wezterm/issues/1165)
* New: [visual_bell](config/lua/config/visual_bell.md) configuration option
* New: [visual_bell](config/lua/config/visual_bell.md) and [audible_bell](config/lua/config/audible_bell.md) configuration options
* New: [wezterm.action_callback](config/lua/wezterm/action_callback.md) function to make it easier to use custom events. Thanks to [@bew](https://github.com/bew)! [#1151](https://github.com/wez/wezterm/pull/1151)

### 20210814-124438-54e29167
Expand Down
17 changes: 17 additions & 0 deletions docs/config/lua/config/audible_bell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# audible_bell

*Since: nightly builds only*

When the BEL ascii sequence is sent to a pane, the bell is "rung" in that pane.

You may choose to configure the `audible_bell` option to change the sound
that wezterm makes when the bell rings.

The follow are possible values:

* `"SystemBeep"` - perform the system beep or alert sound. This is the default. On some systems, it may not produce a beep sound.
* `"Disabled"` - don't make a sound


See also [visual_bell](visual_bell.md).

2 changes: 2 additions & 0 deletions docs/config/lua/config/visual_bell.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ return {
},
}
```

See also [audible_bell](audible_bell.md).
10 changes: 9 additions & 1 deletion wezterm-gui/src/termwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use config::keyassignment::{
ClipboardCopyDestination, ClipboardPasteSource, InputMap, KeyAssignment, SpawnCommand,
};
use config::{
configuration, ConfigHandle, GradientOrientation, TermConfig, WindowCloseConfirmation,
configuration, AudibleBell, ConfigHandle, GradientOrientation, TermConfig,
WindowCloseConfirmation,
};
use luahelper::impl_lua_conversion;
use mlua::FromLua;
Expand Down Expand Up @@ -808,6 +809,13 @@ impl TermWindow {
alert: Alert::Bell,
pane_id,
} => {
match self.config.audible_bell {
AudibleBell::SystemBeep => {
Connection::get().expect("on main thread").beep();
}
AudibleBell::Disabled => {}
}

log::info!("Ding! (this is the bell) in pane {}", pane_id);
self.emit_window_event("bell", Some(pane_id));

Expand Down
3 changes: 3 additions & 0 deletions window/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ pub trait ConnectionOps {
/// This actions hides all of the windows of the application and switches
/// focus away from it.
fn hide_application(&self) {}

/// Perform the system beep/notification sound
fn beep(&self) {}
}
10 changes: 10 additions & 0 deletions window/src/os/macos/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,14 @@ impl ConnectionOps for Connection {
let () = msg_send![self.ns_app, hide: self.ns_app];
}
}

fn beep(&self) {
unsafe {
NSBeep();
}
}
}

extern "C" {
fn NSBeep();
}

0 comments on commit 72cb110

Please sign in to comment.