From d49a286c30fa99035680238c5e6785337e3a9a28 Mon Sep 17 00:00:00 2001 From: Midnight Exigent <36641328+midnightexigent@users.noreply.github.com> Date: Sun, 27 Feb 2022 00:49:56 +0100 Subject: [PATCH] Rebase attempt --- .../yuck/src/config/backend_window_options.rs | 6 +-- crates/yuck/src/config/window_definition.rs | 49 +++++++++++++++++-- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/crates/yuck/src/config/backend_window_options.rs b/crates/yuck/src/config/backend_window_options.rs index 85d233cdd..9d6106c5a 100644 --- a/crates/yuck/src/config/backend_window_options.rs +++ b/crates/yuck/src/config/backend_window_options.rs @@ -27,7 +27,7 @@ mod backend { } impl BackendWindowOptions { - pub fn from_attrs(attrs: &mut Attributes) -> AstResult { + pub(crate) fn from_attrs(attrs: &mut Attributes, preset: Option) -> AstResult { let struts = attrs.ast_optional("reserve")?; let window_type = attrs.primitive_optional("windowtype")?; Ok(Self { @@ -111,7 +111,7 @@ mod backend { pub focusable: bool, } impl BackendWindowOptions { - pub fn from_attrs(attrs: &mut Attributes) -> AstResult { + pub(crate) fn from_attrs(attrs: &mut Attributes, preset: Option) -> AstResult { Ok(Self { exclusive: attrs.primitive_optional("exclusive")?.unwrap_or(false), focusable: attrs.primitive_optional("focusable")?.unwrap_or(false), @@ -126,7 +126,7 @@ mod backend { #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)] pub struct BackendWindowOptions; impl BackendWindowOptions { - pub fn from_attrs(attrs: &mut Attributes) -> AstResult { + pub(crate) fn from_attrs(attrs: &mut Attributes, preset: Option) -> AstResult { Ok(Self) } } diff --git a/crates/yuck/src/config/window_definition.rs b/crates/yuck/src/config/window_definition.rs index e4a7bebda..e38993960 100644 --- a/crates/yuck/src/config/window_definition.rs +++ b/crates/yuck/src/config/window_definition.rs @@ -15,6 +15,31 @@ use eww_shared_util::{AttrName, Span, VarName}; use super::{backend_window_options::BackendWindowOptions, widget_use::WidgetUse, window_geometry::WindowGeometry}; +#[non_exhaustive] +#[derive(Debug, Clone, serde::Serialize, PartialEq, Eq)] +enum WindowDefinitionPreset { + #[non_exhaustive] + Bar {}, + #[non_exhaustive] + Background {}, + #[non_exhaustive] + Float {}, + #[non_exhaustive] + Normal {}, +} +impl FromAstElementContent for WindowDefinitionPreset { + const ELEMENT_NAME: &'static str = "defwindowpreset"; + + fn from_tail>(span: Span, iter: AstIterator) -> AstResult { + todo!() + } +} +impl WindowDefinitionPreset { + fn to_window_definition(&self) -> WindowDefinition { + todo!() + } +} + #[derive(Debug, Clone, serde::Serialize, PartialEq, Eq)] pub struct WindowDefinition { pub name: String, @@ -32,12 +57,26 @@ impl FromAstElementContent for WindowDefinition { fn from_tail>(span: Span, mut iter: AstIterator) -> AstResult { let (_, name) = iter.expect_symbol()?; let mut attrs = iter.expect_key_values()?; - let monitor_number = attrs.primitive_optional("monitor")?; - let resizable = attrs.primitive_optional("resizable")?.unwrap_or(true); - let stacking = attrs.primitive_optional("stacking")?.unwrap_or(WindowStacking::Foreground); - let geometry = attrs.ast_optional("geometry")?; - let backend_options = BackendWindowOptions::from_attrs(&mut attrs)?; + + let preset = attrs.ast_optional::("preset")?.map(|preset| preset.to_window_definition()); + let preset_ref = preset.as_ref(); + + let monitor_number = attrs.primitive_optional("monitor")?.or_else(|| preset_ref.and_then(|preset| preset.monitor_number)); + + let resizable = + attrs.primitive_optional("resizable")?.or_else(|| preset_ref.map(|preset| preset.resizable)).unwrap_or(true); + + let stacking = attrs + .primitive_optional("stacking")? + .or_else(|| preset_ref.map(|preset| preset.stacking)) + .unwrap_or(WindowStacking::Foreground); + + let geometry = attrs.ast_optional("geometry")?.or_else(|| preset_ref.and_then(|preset| preset.geometry)); + + let backend_options = BackendWindowOptions::from_attrs(&mut attrs, preset.map(|preset| preset.backend_options))?; + let widget = iter.expect_any().and_then(WidgetUse::from_ast)?; + iter.expect_done()?; Ok(Self { name, monitor_number, resizable, widget, stacking, geometry, backend_options }) }