Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Implement Preset for Window Configuration #219

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/yuck/src/config/backend_window_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod backend {
}

impl BackendWindowOptions {
pub fn from_attrs(attrs: &mut Attributes) -> AstResult<Self> {
pub(crate) fn from_attrs(attrs: &mut Attributes, preset: Option<Self>) -> AstResult<Self> {
let struts = attrs.ast_optional("reserve")?;
let window_type = attrs.primitive_optional("windowtype")?;
Ok(Self {
Expand Down Expand Up @@ -111,7 +111,7 @@ mod backend {
pub focusable: bool,
}
impl BackendWindowOptions {
pub fn from_attrs(attrs: &mut Attributes) -> AstResult<Self> {
pub(crate) fn from_attrs(attrs: &mut Attributes, preset: Option<Self>) -> AstResult<Self> {
Ok(Self {
exclusive: attrs.primitive_optional("exclusive")?.unwrap_or(false),
focusable: attrs.primitive_optional("focusable")?.unwrap_or(false),
Expand All @@ -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<Self> {
pub(crate) fn from_attrs(attrs: &mut Attributes, preset: Option<Self>) -> AstResult<Self> {
Ok(Self)
}
}
Expand Down
49 changes: 44 additions & 5 deletions crates/yuck/src/config/window_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<I: Iterator<Item = Ast>>(span: Span, iter: AstIterator<I>) -> AstResult<Self> {
todo!()
}
}
impl WindowDefinitionPreset {
fn to_window_definition(&self) -> WindowDefinition {
todo!()
}
}

#[derive(Debug, Clone, serde::Serialize, PartialEq, Eq)]
pub struct WindowDefinition {
pub name: String,
Expand All @@ -32,12 +57,26 @@ impl FromAstElementContent for WindowDefinition {
fn from_tail<I: Iterator<Item = Ast>>(span: Span, mut iter: AstIterator<I>) -> AstResult<Self> {
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::<WindowDefinitionPreset>("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 })
}
Expand Down