summaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/config/window.rs
blob: 351bef10bf9d6d5321808d6ad7dc05879c71ebc7 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use crate::config::{failure_default, option_explicit_none, from_string_or_deserialize, Delta, FromString};
use crate::index::{Column, Line};
use crate::window::DEFAULT_NAME;

#[serde(default)]
#[derive(Deserialize, Debug, Clone, Default, PartialEq, Eq)]
pub struct WindowConfig {
    /// Initial dimensions
    #[serde(deserialize_with = "failure_default")]
    pub dimensions: Dimensions,

    /// Initial position
    #[serde(deserialize_with = "failure_default")]
    pub position: Option<Delta<i32>>,

    /// Pixel padding
    #[serde(deserialize_with = "failure_default")]
    pub padding: Delta<u8>,

    /// Draw the window with title bar / borders
    #[serde(deserialize_with = "failure_default")]
    pub decorations: Decorations,

    /// Spread out additional padding evenly
    #[serde(deserialize_with = "failure_default")]
    pub dynamic_padding: bool,

    /// Startup mode
    #[serde(deserialize_with = "failure_default")]
    startup_mode: StartupMode,

    /// Window title
    #[serde(deserialize_with = "failure_default")]
    pub title: Option<String>,

    /// Window class
    #[serde(deserialize_with = "from_string_or_deserialize")]
    pub class: Class,

    /// GTK theme variant
    #[serde(deserialize_with = "option_explicit_none")]
    pub gtk_theme_variant: Option<String>,

    /// TODO: DEPRECATED
    #[serde(deserialize_with = "failure_default")]
    pub start_maximized: Option<bool>,
}

impl WindowConfig {
    pub fn startup_mode(&self) -> StartupMode {
        match self.start_maximized {
            Some(true) => StartupMode::Maximized,
            _ => self.startup_mode,
        }
    }
}

#[derive(Debug, Deserialize, Copy, Clone, PartialEq, Eq)]
pub enum StartupMode {
    Windowed,
    Maximized,
    Fullscreen,
    #[cfg(target_os = "macos")]
    SimpleFullscreen,
}

impl Default for StartupMode {
    fn default() -> StartupMode {
        StartupMode::Windowed
    }
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize)]
pub enum Decorations {
    #[serde(rename = "full")]
    Full,
    #[cfg(target_os = "macos")]
    #[serde(rename = "transparent")]
    Transparent,
    #[cfg(target_os = "macos")]
    #[serde(rename = "buttonless")]
    Buttonless,
    #[serde(rename = "none")]
    None,
}

impl Default for Decorations {
    fn default() -> Decorations {
        Decorations::Full
    }
}

/// Window Dimensions
///
/// Newtype to avoid passing values incorrectly
#[serde(default)]
#[derive(Default, Debug, Copy, Clone, Deserialize, PartialEq, Eq)]
pub struct Dimensions {
    /// Window width in character columns
    #[serde(deserialize_with = "failure_default")]
    columns: Column,

    /// Window Height in character lines
    #[serde(deserialize_with = "failure_default")]
    lines: Line,
}

impl Dimensions {
    pub fn new(columns: Column, lines: Line) -> Self {
        Dimensions { columns, lines }
    }

    /// Get lines
    #[inline]
    pub fn lines_u32(&self) -> u32 {
        self.lines.0 as u32
    }

    /// Get columns
    #[inline]
    pub fn columns_u32(&self) -> u32 {
        self.columns.0 as u32
    }
}

/// Window class hint
#[serde(default)]
#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct Class {
    pub instance: String,
    pub general: String
}

impl Default for Class {
    fn default() -> Self {
        Class { instance: DEFAULT_NAME.into(), general: DEFAULT_NAME.into() }
    }
}

impl FromString for Class {
    fn from(value: String) -> Self {
        Class { instance: value, general: DEFAULT_NAME.into() }
    }
}