diff options
| author | Lukas Fink <lukas.fink1@gmail.com> | 2025-08-17 14:13:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-17 12:13:34 +0000 |
| commit | 7201a6ae062ea6e12045d7b11dfa5fc5b7056a79 (patch) | |
| tree | a792f40416fd8cf2b38733c4fd54bce69c5bcecc | |
| parent | 84377a45a8a8574323f3f18706aab88be4d8fab1 (diff) | |
| download | r-alacritty-7201a6ae062ea6e12045d7b11dfa5fc5b7056a79.tar.gz r-alacritty-7201a6ae062ea6e12045d7b11dfa5fc5b7056a79.tar.bz2 r-alacritty-7201a6ae062ea6e12045d7b11dfa5fc5b7056a79.zip | |
Add cooldown to bell command execution
Closes #8655.
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | alacritty/src/event.rs | 14 | ||||
| -rw-r--r-- | alacritty/src/window_context.rs | 4 |
3 files changed, 18 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2054e25c..6fcb3f26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ Notable changes to the `alacritty_terminal` crate are documented in its - Search matching a wrapping fullwidth character in the last column - Crash when `AppleFontSmoothing` option is not present on macOS - Origin mode (DECOM) not moving cursor to the origin point +- Unresponsiveness when spamming the bell character with a bell command enabled ## 0.15.1 diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs index e604ae81..0ff3c6fd 100644 --- a/alacritty/src/event.rs +++ b/alacritty/src/event.rs @@ -77,6 +77,9 @@ const MAX_SEARCH_HISTORY_SIZE: usize = 255; /// Touch zoom speed. const TOUCH_ZOOM_FACTOR: f32 = 0.01; +/// Cooldown between invocations of the bell command. +const BELL_CMD_COOLDOWN: Duration = Duration::from_millis(100); + /// The event processor. /// /// Stores some state from received events and dispatches actions when they are @@ -663,6 +666,7 @@ pub struct ActionContext<'a, N, T> { pub message_buffer: &'a mut MessageBuffer, pub config: &'a UiConfig, pub cursor_blink_timed_out: &'a mut bool, + pub prev_bell_cmd: &'a mut Option<Instant>, #[cfg(target_os = "macos")] pub event_loop: &'a ActiveEventLoop, pub event_proxy: &'a EventLoopProxy<Event>, @@ -1881,7 +1885,15 @@ impl input::Processor<EventProxy, ActionContext<'_, Notifier, EventProxy>> { // Execute bell command. if let Some(bell_command) = &self.ctx.config.bell.command { - self.ctx.spawn_daemon(bell_command.program(), bell_command.args()); + if self + .ctx + .prev_bell_cmd + .is_none_or(|i| i.elapsed() >= BELL_CMD_COOLDOWN) + { + self.ctx.spawn_daemon(bell_command.program(), bell_command.args()); + + *self.ctx.prev_bell_cmd = Some(Instant::now()); + } } }, TerminalEvent::ClipboardStore(clipboard_type, content) => { diff --git a/alacritty/src/window_context.rs b/alacritty/src/window_context.rs index 5bfeef83..2784a7e0 100644 --- a/alacritty/src/window_context.rs +++ b/alacritty/src/window_context.rs @@ -8,6 +8,7 @@ use std::mem; use std::os::unix::io::{AsRawFd, RawFd}; use std::rc::Rc; use std::sync::Arc; +use std::time::Instant; use glutin::config::Config as GlutinConfig; use glutin::display::GetGlDisplay; @@ -51,6 +52,7 @@ pub struct WindowContext { event_queue: Vec<WinitEvent<Event>>, terminal: Arc<FairMutex<Term<EventProxy>>>, cursor_blink_timed_out: bool, + prev_bell_cmd: Option<Instant>, modifiers: Modifiers, inline_search_state: InlineSearchState, search_state: SearchState, @@ -240,6 +242,7 @@ impl WindowContext { config, notifier: Notifier(loop_tx), cursor_blink_timed_out: Default::default(), + prev_bell_cmd: Default::default(), inline_search_state: Default::default(), message_buffer: Default::default(), window_config: Default::default(), @@ -424,6 +427,7 @@ impl WindowContext { let context = ActionContext { cursor_blink_timed_out: &mut self.cursor_blink_timed_out, + prev_bell_cmd: &mut self.prev_bell_cmd, message_buffer: &mut self.message_buffer, inline_search_state: &mut self.inline_search_state, search_state: &mut self.search_state, |