aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src/config/mouse.rs
blob: 2aa7557c7dbfdf40284b7021d8791fca05f505c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::time::Duration;

use glutin::event::ModifiersState;

use alacritty_config_derive::ConfigDeserialize;
use alacritty_terminal::config::Program;

use crate::config::bindings::ModsWrapper;

#[derive(ConfigDeserialize, Default, Clone, Debug, PartialEq, Eq)]
pub struct Mouse {
    pub double_click: ClickHandler,
    pub triple_click: ClickHandler,
    pub hide_when_typing: bool,
    pub url: Url,
}

#[derive(ConfigDeserialize, Clone, Debug, PartialEq, Eq)]
pub struct Url {
    /// Program for opening links.
    pub launcher: Option<Program>,

    /// Modifier used to open links.
    modifiers: ModsWrapper,
}

impl Url {
    pub fn mods(&self) -> ModifiersState {
        self.modifiers.into_inner()
    }
}

impl Default for Url {
    fn default() -> Url {
        Url {
            #[cfg(not(any(target_os = "macos", windows)))]
            launcher: Some(Program::Just(String::from("xdg-open"))),
            #[cfg(target_os = "macos")]
            launcher: Some(Program::Just(String::from("open"))),
            #[cfg(windows)]
            launcher: Some(Program::WithArgs {
                program: String::from("cmd"),
                args: vec!["/c".to_string(), "start".to_string(), "".to_string()],
            }),
            modifiers: Default::default(),
        }
    }
}

#[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)
    }
}