mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
parent
9fcdb059bf
commit
df00be25c6
5 changed files with 49 additions and 41 deletions
|
@ -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 `background_opacity`, use `window.background_opacity`
|
||||||
- Config option `colors.search.bar`, use `colors.footer_bar` instead
|
- Config option `colors.search.bar`, use `colors.footer_bar` instead
|
||||||
- Config option `mouse.url`, use the `hints` config section
|
- Config option `mouse.url`, use the `hints` config section
|
||||||
|
- Config options `mouse.double_click` and `mouse.triple_click`
|
||||||
|
|
||||||
## 0.12.1
|
## 0.12.1
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub use crate::config::bindings::{
|
||||||
Action, Binding, BindingMode, Key, MouseAction, SearchAction, ViAction,
|
Action, Binding, BindingMode, Key, MouseAction, SearchAction, ViAction,
|
||||||
};
|
};
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub use crate::config::mouse::{ClickHandler, Mouse};
|
pub use crate::config::mouse::Mouse;
|
||||||
pub use crate::config::ui_config::UiConfig;
|
pub use crate::config::ui_config::UiConfig;
|
||||||
|
|
||||||
/// Maximum number of depth for the configuration file imports.
|
/// Maximum number of depth for the configuration file imports.
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
|
|
||||||
use alacritty_config_derive::{ConfigDeserialize, SerdeReplace};
|
use alacritty_config_derive::{ConfigDeserialize, SerdeReplace};
|
||||||
|
@ -9,29 +7,10 @@ use crate::config::ui_config;
|
||||||
|
|
||||||
#[derive(ConfigDeserialize, Default, Clone, Debug, PartialEq, Eq)]
|
#[derive(ConfigDeserialize, Default, Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Mouse {
|
pub struct Mouse {
|
||||||
pub double_click: ClickHandler,
|
|
||||||
pub triple_click: ClickHandler,
|
|
||||||
pub hide_when_typing: bool,
|
pub hide_when_typing: bool,
|
||||||
pub bindings: MouseBindings,
|
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)]
|
#[derive(SerdeReplace, Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct MouseBindings(pub Vec<MouseBinding>);
|
pub struct MouseBindings(pub Vec<MouseBinding>);
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,9 @@ const TOUCH_SCROLL_FACTOR: f64 = 0.35;
|
||||||
/// Distance before a touch input is considered a drag.
|
/// Distance before a touch input is considered a drag.
|
||||||
const MAX_TAP_DISTANCE: f64 = 20.;
|
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.
|
/// Processes input from winit.
|
||||||
///
|
///
|
||||||
/// An escape sequence may be emitted in case specific keys or key combinations
|
/// 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;
|
self.ctx.mouse_mut().last_click_timestamp = now;
|
||||||
|
|
||||||
// Update multi-click state.
|
// Update multi-click state.
|
||||||
let mouse_config = &self.ctx.config().mouse;
|
|
||||||
self.ctx.mouse_mut().click_state = match self.ctx.mouse().click_state {
|
self.ctx.mouse_mut().click_state = match self.ctx.mouse().click_state {
|
||||||
// Reset click state if button has changed.
|
// Reset click state if button has changed.
|
||||||
_ if button != self.ctx.mouse().last_click_button => {
|
_ if button != self.ctx.mouse().last_click_button => {
|
||||||
self.ctx.mouse_mut().last_click_button = button;
|
self.ctx.mouse_mut().last_click_button = button;
|
||||||
ClickState::Click
|
ClickState::Click
|
||||||
},
|
},
|
||||||
ClickState::Click if elapsed < mouse_config.double_click.threshold() => {
|
ClickState::Click if elapsed < CLICK_THRESHOLD => ClickState::DoubleClick,
|
||||||
ClickState::DoubleClick
|
ClickState::DoubleClick if elapsed < CLICK_THRESHOLD => ClickState::TripleClick,
|
||||||
},
|
|
||||||
ClickState::DoubleClick if elapsed < mouse_config.triple_click.threshold() => {
|
|
||||||
ClickState::TripleClick
|
|
||||||
},
|
|
||||||
_ => ClickState::Click,
|
_ => ClickState::Click,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1294,6 +1292,7 @@ mod tests {
|
||||||
initial_button: $initial_button:expr,
|
initial_button: $initial_button:expr,
|
||||||
input: $input:expr,
|
input: $input:expr,
|
||||||
end_state: $end_state:expr,
|
end_state: $end_state:expr,
|
||||||
|
input_delay: $input_delay:expr,
|
||||||
} => {
|
} => {
|
||||||
#[test]
|
#[test]
|
||||||
fn $name() {
|
fn $name() {
|
||||||
|
@ -1314,6 +1313,7 @@ mod tests {
|
||||||
let mut mouse = Mouse {
|
let mut mouse = Mouse {
|
||||||
click_state: $initial_state,
|
click_state: $initial_state,
|
||||||
last_click_button: $initial_button,
|
last_click_button: $initial_button,
|
||||||
|
last_click_timestamp: Instant::now() - $input_delay,
|
||||||
..Mouse::default()
|
..Mouse::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1384,6 +1384,7 @@ mod tests {
|
||||||
window_id: unsafe { WindowId::dummy() },
|
window_id: unsafe { WindowId::dummy() },
|
||||||
},
|
},
|
||||||
end_state: ClickState::Click,
|
end_state: ClickState::Click,
|
||||||
|
input_delay: Duration::ZERO,
|
||||||
}
|
}
|
||||||
|
|
||||||
test_clickstate! {
|
test_clickstate! {
|
||||||
|
@ -1400,6 +1401,7 @@ mod tests {
|
||||||
window_id: unsafe { WindowId::dummy() },
|
window_id: unsafe { WindowId::dummy() },
|
||||||
},
|
},
|
||||||
end_state: ClickState::Click,
|
end_state: ClickState::Click,
|
||||||
|
input_delay: Duration::ZERO,
|
||||||
}
|
}
|
||||||
|
|
||||||
test_clickstate! {
|
test_clickstate! {
|
||||||
|
@ -1416,6 +1418,7 @@ mod tests {
|
||||||
window_id: unsafe { WindowId::dummy() },
|
window_id: unsafe { WindowId::dummy() },
|
||||||
},
|
},
|
||||||
end_state: ClickState::Click,
|
end_state: ClickState::Click,
|
||||||
|
input_delay: Duration::ZERO,
|
||||||
}
|
}
|
||||||
|
|
||||||
test_clickstate! {
|
test_clickstate! {
|
||||||
|
@ -1432,6 +1435,24 @@ mod tests {
|
||||||
window_id: unsafe { WindowId::dummy() },
|
window_id: unsafe { WindowId::dummy() },
|
||||||
},
|
},
|
||||||
end_state: ClickState::DoubleClick,
|
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! {
|
test_clickstate! {
|
||||||
|
@ -1448,6 +1469,24 @@ mod tests {
|
||||||
window_id: unsafe { WindowId::dummy() },
|
window_id: unsafe { WindowId::dummy() },
|
||||||
},
|
},
|
||||||
end_state: ClickState::TripleClick,
|
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! {
|
test_clickstate! {
|
||||||
|
@ -1464,6 +1503,7 @@ mod tests {
|
||||||
window_id: unsafe { WindowId::dummy() },
|
window_id: unsafe { WindowId::dummy() },
|
||||||
},
|
},
|
||||||
end_state: ClickState::Click,
|
end_state: ClickState::Click,
|
||||||
|
input_delay: Duration::ZERO,
|
||||||
}
|
}
|
||||||
|
|
||||||
test_process_binding! {
|
test_process_binding! {
|
||||||
|
|
|
@ -538,18 +538,6 @@ Windows: _"powershell"_
|
||||||
|
|
||||||
This section documents the *[mouse]* table of the configuration file.
|
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>
|
*hide_when_typing* <boolean>
|
||||||
|
|
||||||
When this is _true_, the cursor is temporarily hidden when typing.
|
When this is _true_, the cursor is temporarily hidden when typing.
|
||||||
|
|
Loading…
Reference in a new issue