summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--alacritty/src/config/mod.rs2
-rw-r--r--alacritty/src/config/mouse.rs21
-rw-r--r--alacritty/src/input.rs54
-rw-r--r--extra/man/alacritty.5.scd12
5 files changed, 49 insertions, 41 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 82407195..f18f8adb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Config option `background_opacity`, use `window.background_opacity`
- Config option `colors.search.bar`, use `colors.footer_bar` instead
- Config option `mouse.url`, use the `hints` config section
+- Config options `mouse.double_click` and `mouse.triple_click`
## 0.12.1
diff --git a/alacritty/src/config/mod.rs b/alacritty/src/config/mod.rs
index 87ca0716..9221050b 100644
--- a/alacritty/src/config/mod.rs
+++ b/alacritty/src/config/mod.rs
@@ -29,7 +29,7 @@ pub use crate::config::bindings::{
Action, Binding, BindingMode, Key, MouseAction, SearchAction, ViAction,
};
#[cfg(test)]
-pub use crate::config::mouse::{ClickHandler, Mouse};
+pub use crate::config::mouse::Mouse;
pub use crate::config::ui_config::UiConfig;
/// Maximum number of depth for the configuration file imports.
diff --git a/alacritty/src/config/mouse.rs b/alacritty/src/config/mouse.rs
index b6556a2c..4afd7446 100644
--- a/alacritty/src/config/mouse.rs
+++ b/alacritty/src/config/mouse.rs
@@ -1,5 +1,3 @@
-use std::time::Duration;
-
use serde::{Deserialize, Deserializer};
use alacritty_config_derive::{ConfigDeserialize, SerdeReplace};
@@ -9,29 +7,10 @@ use crate::config::ui_config;
#[derive(ConfigDeserialize, Default, Clone, Debug, PartialEq, Eq)]
pub struct Mouse {
- pub double_click: ClickHandler,
- pub triple_click: ClickHandler,
pub hide_when_typing: bool,
pub bindings: MouseBindings,
}
-#[derive(ConfigDeserialize, Clone, Debug, PartialEq, Eq)]
-pub struct ClickHandler {
- threshold: u16,
-}
-
-impl Default for ClickHandler {
- fn default() -> Self {
- Self { threshold: 300 }
- }
-}
-
-impl ClickHandler {
- pub fn threshold(&self) -> Duration {
- Duration::from_millis(self.threshold as u64)
- }
-}
-
#[derive(SerdeReplace, Clone, Debug, PartialEq, Eq)]
pub struct MouseBindings(pub Vec<MouseBinding>);
diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs
index 935fc046..a9925088 100644
--- a/alacritty/src/input.rs
+++ b/alacritty/src/input.rs
@@ -63,6 +63,9 @@ const TOUCH_SCROLL_FACTOR: f64 = 0.35;
/// Distance before a touch input is considered a drag.
const MAX_TAP_DISTANCE: f64 = 20.;
+/// Threshold used for double_click/triple_click.
+const CLICK_THRESHOLD: Duration = Duration::from_millis(300);
+
/// Processes input from winit.
///
/// An escape sequence may be emitted in case specific keys or key combinations
@@ -555,19 +558,14 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
self.ctx.mouse_mut().last_click_timestamp = now;
// Update multi-click state.
- let mouse_config = &self.ctx.config().mouse;
self.ctx.mouse_mut().click_state = match self.ctx.mouse().click_state {
// Reset click state if button has changed.
_ if button != self.ctx.mouse().last_click_button => {
self.ctx.mouse_mut().last_click_button = button;
ClickState::Click
},
- ClickState::Click if elapsed < mouse_config.double_click.threshold() => {
- ClickState::DoubleClick
- },
- ClickState::DoubleClick if elapsed < mouse_config.triple_click.threshold() => {
- ClickState::TripleClick
- },
+ ClickState::Click if elapsed < CLICK_THRESHOLD => ClickState::DoubleClick,
+ ClickState::DoubleClick if elapsed < CLICK_THRESHOLD => ClickState::TripleClick,
_ => ClickState::Click,
};
@@ -1294,6 +1292,7 @@ mod tests {
initial_button: $initial_button:expr,
input: $input:expr,
end_state: $end_state:expr,
+ input_delay: $input_delay:expr,
} => {
#[test]
fn $name() {
@@ -1314,6 +1313,7 @@ mod tests {
let mut mouse = Mouse {
click_state: $initial_state,
last_click_button: $initial_button,
+ last_click_timestamp: Instant::now() - $input_delay,
..Mouse::default()
};
@@ -1384,6 +1384,7 @@ mod tests {
window_id: unsafe { WindowId::dummy() },
},
end_state: ClickState::Click,
+ input_delay: Duration::ZERO,
}
test_clickstate! {
@@ -1400,6 +1401,7 @@ mod tests {
window_id: unsafe { WindowId::dummy() },
},
end_state: ClickState::Click,
+ input_delay: Duration::ZERO,
}
test_clickstate! {
@@ -1416,6 +1418,7 @@ mod tests {
window_id: unsafe { WindowId::dummy() },
},
end_state: ClickState::Click,
+ input_delay: Duration::ZERO,
}
test_clickstate! {
@@ -1432,6 +1435,24 @@ mod tests {
window_id: unsafe { WindowId::dummy() },
},
end_state: ClickState::DoubleClick,
+ input_delay: Duration::ZERO,
+ }
+
+ test_clickstate! {
+ name: double_click_failed,
+ initial_state: ClickState::Click,
+ initial_button: MouseButton::Left,
+ input: WinitEvent::WindowEvent {
+ event: WindowEvent::MouseInput {
+ state: ElementState::Pressed,
+ button: MouseButton::Left,
+ device_id: unsafe { DeviceId::dummy() },
+ modifiers: ModifiersState::default(),
+ },
+ window_id: unsafe { WindowId::dummy() },
+ },
+ end_state: ClickState::Click,
+ input_delay: CLICK_THRESHOLD,
}
test_clickstate! {
@@ -1448,6 +1469,24 @@ mod tests {
window_id: unsafe { WindowId::dummy() },
},
end_state: ClickState::TripleClick,
+ input_delay: Duration::ZERO,
+ }
+
+ test_clickstate! {
+ name: triple_click_failed,
+ initial_state: ClickState::DoubleClick,
+ initial_button: MouseButton::Left,
+ input: WinitEvent::WindowEvent {
+ event: WindowEvent::MouseInput {
+ state: ElementState::Pressed,
+ button: MouseButton::Left,
+ device_id: unsafe { DeviceId::dummy() },
+ modifiers: ModifiersState::default(),
+ },
+ window_id: unsafe { WindowId::dummy() },
+ },
+ end_state: ClickState::Click,
+ input_delay: CLICK_THRESHOLD,
}
test_clickstate! {
@@ -1464,6 +1503,7 @@ mod tests {
window_id: unsafe { WindowId::dummy() },
},
end_state: ClickState::Click,
+ input_delay: Duration::ZERO,
}
test_process_binding! {
diff --git a/extra/man/alacritty.5.scd b/extra/man/alacritty.5.scd
index 5aecd510..10252611 100644
--- a/extra/man/alacritty.5.scd
+++ b/extra/man/alacritty.5.scd
@@ -538,18 +538,6 @@ Windows: _"powershell"_
This section documents the *[mouse]* table of the configuration file.
-*double_click* { threshold = <integer> }
-
- Set maximum time between double-clicks in milliseconds.
-
- Default: _300_
-
-*triple_click* { threshold = <integer> }
-
- Set maximum time between triple-clicks in milliseconds.
-
- Default: _300_
-
*hide_when_typing* <boolean>
When this is _true_, the cursor is temporarily hidden when typing.