aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src/config/mouse.rs
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2019-10-05 02:29:26 +0200
committerGitHub <noreply@github.com>2019-10-05 02:29:26 +0200
commit729eef0c933831bccfeac6a355bdb410787fbe5f (patch)
tree35cdf2e6427ad18bc53efbab4cab34a0af2054d7 /alacritty/src/config/mouse.rs
parentb0c6fdff763f7271506d26d7e768e6377fdc691b (diff)
downloadr-alacritty-729eef0c933831bccfeac6a355bdb410787fbe5f.tar.gz
r-alacritty-729eef0c933831bccfeac6a355bdb410787fbe5f.tar.bz2
r-alacritty-729eef0c933831bccfeac6a355bdb410787fbe5f.zip
Update to winit/glutin EventLoop 2.0
This takes the latest glutin master to port Alacritty to the EventLoop 2.0 rework. This changes a big part of the event loop handling by pushing the event loop in a separate thread from the renderer and running both in parallel. Fixes #2796. Fixes #2694. Fixes #2643. Fixes #2625. Fixes #2618. Fixes #2601. Fixes #2564. Fixes #2456. Fixes #2438. Fixes #2334. Fixes #2254. Fixes #2217. Fixes #1789. Fixes #1750. Fixes #1125.
Diffstat (limited to 'alacritty/src/config/mouse.rs')
-rw-r--r--alacritty/src/config/mouse.rs115
1 files changed, 115 insertions, 0 deletions
diff --git a/alacritty/src/config/mouse.rs b/alacritty/src/config/mouse.rs
new file mode 100644
index 00000000..b7832b4a
--- /dev/null
+++ b/alacritty/src/config/mouse.rs
@@ -0,0 +1,115 @@
+use std::time::Duration;
+
+use glutin::event::ModifiersState;
+use log::error;
+use serde::{Deserialize, Deserializer};
+
+use alacritty_terminal::config::{failure_default, LOG_TARGET_CONFIG};
+
+use crate::config::bindings::{CommandWrapper, ModsWrapper};
+
+#[serde(default)]
+#[derive(Default, Clone, Debug, Deserialize, PartialEq, Eq)]
+pub struct Mouse {
+ #[serde(deserialize_with = "failure_default")]
+ pub double_click: ClickHandler,
+ #[serde(deserialize_with = "failure_default")]
+ pub triple_click: ClickHandler,
+ #[serde(deserialize_with = "failure_default")]
+ pub hide_when_typing: bool,
+ #[serde(deserialize_with = "failure_default")]
+ pub url: Url,
+}
+
+#[serde(default)]
+#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
+pub struct Url {
+ // Program for opening links
+ #[serde(deserialize_with = "deserialize_launcher")]
+ pub launcher: Option<CommandWrapper>,
+
+ // Modifier used to open links
+ #[serde(deserialize_with = "failure_default")]
+ modifiers: ModsWrapper,
+}
+
+impl Url {
+ pub fn mods(&self) -> ModifiersState {
+ self.modifiers.into_inner()
+ }
+}
+
+fn deserialize_launcher<'a, D>(
+ deserializer: D,
+) -> ::std::result::Result<Option<CommandWrapper>, D::Error>
+where
+ D: Deserializer<'a>,
+{
+ let default = Url::default().launcher;
+
+ // Deserialize to generic value
+ let val = serde_yaml::Value::deserialize(deserializer)?;
+
+ // Accept `None` to disable the launcher
+ if val.as_str().filter(|v| v.to_lowercase() == "none").is_some() {
+ return Ok(None);
+ }
+
+ match <Option<CommandWrapper>>::deserialize(val) {
+ Ok(launcher) => Ok(launcher),
+ Err(err) => {
+ error!(
+ target: LOG_TARGET_CONFIG,
+ "Problem with config: {}; using {}",
+ err,
+ default.clone().unwrap().program()
+ );
+ Ok(default)
+ },
+ }
+}
+
+impl Default for Url {
+ fn default() -> Url {
+ Url {
+ #[cfg(not(any(target_os = "macos", windows)))]
+ launcher: Some(CommandWrapper::Just(String::from("xdg-open"))),
+ #[cfg(target_os = "macos")]
+ launcher: Some(CommandWrapper::Just(String::from("open"))),
+ #[cfg(windows)]
+ launcher: Some(CommandWrapper::Just(String::from("explorer"))),
+ modifiers: Default::default(),
+ }
+ }
+}
+
+#[serde(default)]
+#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
+pub struct ClickHandler {
+ #[serde(deserialize_with = "deserialize_duration_ms")]
+ pub threshold: Duration,
+}
+
+impl Default for ClickHandler {
+ fn default() -> Self {
+ ClickHandler { threshold: default_threshold_ms() }
+ }
+}
+
+fn default_threshold_ms() -> Duration {
+ Duration::from_millis(300)
+}
+
+fn deserialize_duration_ms<'a, D>(deserializer: D) -> ::std::result::Result<Duration, D::Error>
+where
+ D: Deserializer<'a>,
+{
+ let value = serde_yaml::Value::deserialize(deserializer)?;
+ match u64::deserialize(value) {
+ Ok(threshold_ms) => Ok(Duration::from_millis(threshold_ms)),
+ Err(err) => {
+ error!(target: LOG_TARGET_CONFIG, "Problem with config: {}; using default value", err);
+ Ok(default_threshold_ms())
+ },
+ }
+}