Remove mouse double_click/triple_click options

Fixes #6962.
This commit is contained in:
Sonu Bardai 2023-06-29 18:47:54 +05:30 committed by GitHub
parent 9fcdb059bf
commit df00be25c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 41 deletions

View File

@ -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

View File

@ -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.

View File

@ -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>);

View File

@ -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! {

View File

@ -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.