Skip to content

Commit

Permalink
Even more more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
elkowar committed Aug 16, 2023
1 parent 946bc1a commit 96829fe
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 31 deletions.
6 changes: 4 additions & 2 deletions crates/eww/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use gdk::Monitor;
use glib::ObjectExt;
use itertools::Itertools;
use once_cell::sync::Lazy;
use simplexpr::dynval::DynVal;
use simplexpr::{dynval::DynVal, SimplExpr};
use std::{
cell::RefCell,
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -380,11 +380,13 @@ impl<B: DisplayBackend> App<B> {

let root_index = self.scope_graph.borrow().root_index;

let scoped_vars_literal = initiator.get_scoped_vars().into_iter().map(|(k, v)| (k, SimplExpr::Literal(v))).collect();

let window_scope = self.scope_graph.borrow_mut().register_new_scope(
window_name.to_string(),
Some(root_index),
root_index,
initiator.get_scoped_vars(),
scoped_vars_literal,
)?;

let root_widget = crate::widgets::build_widget::build_gtk_widget(
Expand Down
18 changes: 7 additions & 11 deletions crates/eww/src/window_initiator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use eww_shared_util::{AttrName, VarName};
use simplexpr::{dynval::DynVal, SimplExpr};
use simplexpr::dynval::DynVal;
use std::collections::HashMap;
use yuck::config::{
backend_window_options::BackendWindowOptions,
Expand Down Expand Up @@ -29,28 +29,24 @@ impl WindowInitiator {
pub fn new(window_def: &WindowDefinition, args: &WindowArguments) -> Result<Self> {
let vars = args.get_local_window_variables(window_def)?;

let backend_options = window_def.backend_options.eval(&vars)?;
let geometry = match &window_def.geometry {
Some(geo) => Some(geo.eval(&vars)?.override_if_given(args.anchor, args.pos, args.size)),
None => None,
};
let monitor = if args.monitor.is_none() { window_def.eval_monitor(&vars)? } else { args.monitor.clone() };
let resizable = window_def.eval_resizable(&vars)?;
let stacking = window_def.eval_stacking(&vars)?;

Ok(WindowInitiator {
backend_options,
backend_options: window_def.backend_options.eval(&vars)?,
geometry,
id: args.instance_id.clone(),
local_variables: vars,
monitor,
name: window_def.name.clone(),
resizable,
stacking,
resizable: window_def.eval_resizable(&vars)?,
stacking: window_def.eval_stacking(&vars)?,
local_variables: vars,
})
}

pub fn get_scoped_vars(&self) -> HashMap<AttrName, SimplExpr> {
self.local_variables.iter().map(|(k, v)| (AttrName::from(k.clone()), SimplExpr::Literal(v.clone()))).collect()
pub fn get_scoped_vars(&self) -> HashMap<AttrName, DynVal> {
self.local_variables.iter().map(|(k, v)| (AttrName::from(k.clone()), v.clone())).collect()
}
}
2 changes: 2 additions & 0 deletions crates/yuck/src/config/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ impl Attributes {
}
}


/// Specification of an argument to a widget or window
#[derive(Debug, PartialEq, Eq, Clone, serde::Serialize)]
pub struct AttrSpec {
pub name: AttrName,
Expand Down
2 changes: 2 additions & 0 deletions crates/yuck/src/config/backend_window_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct X11BackendWindowOptions {
pub struts: X11StrutDefinition,
}

/// Unevaluated form of [`X11BackendWindowOptions`]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
pub struct X11BackendWindowOptionsDef {
pub sticky: Option<SimplExpr>,
Expand Down Expand Up @@ -111,6 +112,7 @@ pub struct WlBackendWindowOptions {
pub namespace: Option<String>,
}

/// Unevaluated form of [`WlBackendWindowOptions`]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
pub struct WlBackendWindowOptionsDef {
pub exclusive: Option<SimplExpr>,
Expand Down
20 changes: 2 additions & 18 deletions crates/yuck/src/config/widget_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,9 @@ use crate::{
from_ast::{FromAst, FromAstElementContent},
},
};
use eww_shared_util::{AttrName, Span, Spanned};
use eww_shared_util::{Span, Spanned};

use super::widget_use::WidgetUse;

#[derive(Debug, PartialEq, Eq, Clone, serde::Serialize)]
pub struct AttrSpec {
pub name: AttrName,
pub optional: bool,
pub span: Span,
}

impl FromAst for AttrSpec {
fn from_ast(e: Ast) -> DiagResult<Self> {
let span = e.span();
let symbol = e.as_symbol()?;
let (name, optional) = if let Some(name) = symbol.strip_prefix('?') { (name.to_string(), true) } else { (symbol, false) };
Ok(Self { name: AttrName(name), optional, span })
}
}
use super::{widget_use::WidgetUse, attributes::AttrSpec};

#[derive(Debug, PartialEq, Eq, Clone, serde::Serialize)]
pub struct WidgetDefinition {
Expand Down
3 changes: 3 additions & 0 deletions crates/yuck/src/config/window_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,23 @@ pub struct WindowDefinition {
}

impl WindowDefinition {
/// Evaluate the `monitor` field of the window definition
pub fn eval_monitor(&self, local_variables: &HashMap<VarName, DynVal>) -> Result<Option<MonitorIdentifier>, EvalError> {
Ok(match &self.monitor {
Some(monitor_expr) => Some(MonitorIdentifier::from_dynval(&monitor_expr.eval(local_variables)?)?),
None => None,
})
}

/// Evaluate the `resizable` field of the window definition
pub fn eval_resizable(&self, local_variables: &HashMap<VarName, DynVal>) -> Result<bool, EvalError> {
Ok(match &self.resizable {
Some(expr) => expr.eval(local_variables)?.as_bool()?,
None => true,
})
}

/// Evaluate the `stacking` field of the window definition
pub fn eval_stacking(
&self,
local_variables: &HashMap<VarName, DynVal>,
Expand Down

0 comments on commit 96829fe

Please sign in to comment.