aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
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(),
}
}
}