aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorJoe Moon <joe@xoxomoon.com>2018-09-20 08:24:26 -0700
committerJoe Wilm <jwilm@users.noreply.github.com>2018-09-20 08:24:26 -0700
commit3b46859eceea39afb8bbc760235cc15de78d3ff3 (patch)
treef17d8b715a9ebb50dac94069f9647c5f09b34840 /src/config.rs
parent641f3291eb918afdc513daa89dbcabfcc202e077 (diff)
downloadalacritty-3b46859eceea39afb8bbc760235cc15de78d3ff3.tar.gz
alacritty-3b46859eceea39afb8bbc760235cc15de78d3ff3.zip
Improve window.decorations options: (#1241)
The decorations config was changed from a bool to an enum. `full` has taken the place of `true`, and `none`, has replaced `false`. On macOS, there are now options for `transparent` and `buttonless`. These options are explained in both the CHANGELOG and in the configuration files.
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs90
1 files changed, 86 insertions, 4 deletions
diff --git a/src/config.rs b/src/config.rs
index 6fad09f9..58e282d2 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -248,6 +248,89 @@ impl Default for Alpha {
}
}
+#[derive(Debug, Copy, Clone)]
+pub enum Decorations {
+ Full,
+ Transparent,
+ Buttonless,
+ None,
+}
+
+impl Default for Decorations {
+ fn default() -> Decorations {
+ Decorations::Full
+ }
+}
+
+impl<'de> Deserialize<'de> for Decorations {
+ fn deserialize<D>(deserializer: D) -> ::std::result::Result<Decorations, D::Error>
+ where D: de::Deserializer<'de>
+ {
+
+ struct DecorationsVisitor;
+
+ impl<'de> Visitor<'de> for DecorationsVisitor {
+ type Value = Decorations;
+
+ fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ f.write_str("Some subset of full|transparent|buttonless|none")
+ }
+
+ fn visit_bool<E>(self, value: bool) -> ::std::result::Result<Decorations, E>
+ where E: de::Error
+ {
+ if value {
+ eprintln!("deprecated decorations boolean value, use one of default|transparent|buttonless|none instead; Falling back to \"full\"");
+ Ok(Decorations::Full)
+ } else {
+ eprintln!("deprecated decorations boolean value, use one of default|transparent|buttonless|none instead; Falling back to \"none\"");
+ Ok(Decorations::None)
+ }
+ }
+
+ #[cfg(target_os = "macos")]
+ fn visit_str<E>(self, value: &str) -> ::std::result::Result<Decorations, E>
+ where E: de::Error
+ {
+ match value {
+ "transparent" => Ok(Decorations::Transparent),
+ "buttonless" => Ok(Decorations::Buttonless),
+ "none" => Ok(Decorations::None),
+ "full" => Ok(Decorations::Full),
+ _ => {
+ eprintln!("invalid decorations value: {}; Using default value", value);
+ Ok(Decorations::Full)
+ }
+ }
+ }
+
+ #[cfg(not(target_os = "macos"))]
+ fn visit_str<E>(self, value: &str) -> ::std::result::Result<Decorations, E>
+ where E: de::Error
+ {
+ match value {
+ "none" => Ok(Decorations::None),
+ "full" => Ok(Decorations::Full),
+ "transparent" => {
+ eprintln!("macos-only decorations value: {}; Using default value", value);
+ Ok(Decorations::Full)
+ },
+ "buttonless" => {
+ eprintln!("macos-only decorations value: {}; Using default value", value);
+ Ok(Decorations::Full)
+ }
+ _ => {
+ eprintln!("invalid decorations value: {}; Using default value", value);
+ Ok(Decorations::Full)
+ }
+ }
+ }
+ }
+
+ deserializer.deserialize_str(DecorationsVisitor)
+ }
+}
+
#[derive(Debug, Copy, Clone, Deserialize)]
pub struct WindowConfig {
/// Initial dimensions
@@ -259,8 +342,7 @@ pub struct WindowConfig {
padding: Delta<u8>,
/// Draw the window with title bar / borders
- #[serde(default, deserialize_with = "failure_default")]
- decorations: bool,
+ decorations: Decorations,
}
fn default_padding() -> Delta<u8> {
@@ -280,7 +362,7 @@ fn deserialize_padding<'a, D>(deserializer: D) -> ::std::result::Result<Delta<u8
}
impl WindowConfig {
- pub fn decorations(&self) -> bool {
+ pub fn decorations(&self) -> Decorations {
self.decorations
}
}
@@ -290,7 +372,7 @@ impl Default for WindowConfig {
WindowConfig{
dimensions: Default::default(),
padding: default_padding(),
- decorations: true,
+ decorations: Default::default(),
}
}
}