From b4dae6c2a3ed843865d5bbd10f25ea5086167e1e Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 1 Feb 2023 14:54:13 -0700 Subject: [PATCH] allow window_decorations to work with config_builder We need to manually convert to string, as the default ToDynamic impl encodes the underlying bits value from the bitfield and that doesn't round trip with the try_from String impl --- wezterm-input-types/src/lib.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/wezterm-input-types/src/lib.rs b/wezterm-input-types/src/lib.rs index cb4e56503..012e58fbf 100644 --- a/wezterm-input-types/src/lib.rs +++ b/wezterm-input-types/src/lib.rs @@ -1271,7 +1271,7 @@ impl KeyEvent { bitflags! { #[derive(Deserialize, Serialize, FromDynamic, ToDynamic)] #[serde(try_from = "String")] - #[dynamic(try_from = "String")] + #[dynamic(try_from = "String", into = "String")] pub struct WindowDecorations: u8 { const TITLE = 1; const RESIZE = 2; @@ -1283,6 +1283,28 @@ bitflags! { } } +impl Into for &WindowDecorations { + fn into(self) -> String { + let mut s = vec![]; + if self.contains(WindowDecorations::TITLE) { + s.push("TITLE"); + } + if self.contains(WindowDecorations::RESIZE) { + s.push("RESIZE"); + } + if self.contains(WindowDecorations::MACOS_FORCE_ENABLE_SHADOW) { + s.push("MACOS_FORCE_ENABLE_SHADOW"); + } else if self.contains(WindowDecorations::MACOS_FORCE_DISABLE_SHADOW) { + s.push("MACOS_FORCE_DISABLE_SHADOW"); + } + if s.is_empty() { + "NONE".to_string() + } else { + s.join("|") + } + } +} + impl TryFrom for WindowDecorations { type Error = String; fn try_from(s: String) -> std::result::Result {