diff --git a/crates/eww/src/config/eww_config.rs b/crates/eww/src/config/eww_config.rs index 0e766b8..b44f102 100644 --- a/crates/eww/src/config/eww_config.rs +++ b/crates/eww/src/config/eww_config.rs @@ -21,7 +21,8 @@ pub struct EwwConfig { impl EwwConfig { pub fn read_from_file(files: &mut YuckFiles, path: impl AsRef) -> Result { let config = Config::generate_from_main_file(files, path)?; - let Config { widget_definitions, window_definitions, var_definitions, script_vars } = config; + let Config { widget_definitions, window_definitions, var_definitions, mut script_vars } = config; + script_vars.extend(crate::config::inbuilt::get_inbuilt_vars()); Ok(EwwConfig { windows: window_definitions .into_iter() diff --git a/crates/simplexpr/src/eval.rs b/crates/simplexpr/src/eval.rs index 4b710f8..5ee736e 100644 --- a/crates/simplexpr/src/eval.rs +++ b/crates/simplexpr/src/eval.rs @@ -165,9 +165,9 @@ impl SimplExpr { BinOp::NotEquals => DynVal::from(a != b), BinOp::And => DynVal::from(a.as_bool()? && b.as_bool()?), BinOp::Or => DynVal::from(a.as_bool()? || b.as_bool()?), - BinOp::Plus => match a.as_f64() { - Ok(num) => DynVal::from(num + b.as_f64()?), - Err(_) => DynVal::from(format!("{}{}", a.as_string()?, b.as_string()?)), + BinOp::Plus => match (a.as_f64(), b.as_f64()) { + (Ok(a), Ok(b)) => DynVal::from(a + b), + _ => DynVal::from(format!("{}{}", a.as_string()?, b.as_string()?)), }, BinOp::Minus => DynVal::from(a.as_f64()? - b.as_f64()?), BinOp::Times => DynVal::from(a.as_f64()? * b.as_f64()?), diff --git a/examples/eww-bar/eww.yuck b/examples/eww-bar/eww.yuck new file mode 100644 index 0000000..8b203ed --- /dev/null +++ b/examples/eww-bar/eww.yuck @@ -0,0 +1,63 @@ +(defwidget bar [] + (box :orientation "h" :hexpand true + (workspaces) + (music) + (sidestuff))) + +(defwidget sidestuff [] + (box :class "sidestuff" :orientation "h" :space-evenly false :halign "end" + (slider-vol) + (slider-ram) + (time))) + +(defwidget workspaces [] + (box :class "workspaces" :orientation "h" :space-evenly true :halign "start" + (button :onclick "wmctrl -s 0" 1) + (button :onclick "wmctrl -s 1" 2) + (button :onclick "wmctrl -s 2" 3) + (button :onclick "wmctrl -s 3" 4) + (button :onclick "wmctrl -s 4" 5) + (button :onclick "wmctrl -s 5" 6) + (button :onclick "wmctrl -s 6" 7) + (button :onclick "wmctrl -s 7" 8) + (button :onclick "wmctrl -s 8" 9))) + +(defwidget music [] + (box :class "music" :orientation "h" :space-evenly false :halign "center" + ;{ " " + music})) + {music})) + +(defwidget slider-vol [] + (box :class "slider-vol" :orientation "h" :space-evenly "false" + (box :class "label-vol" "" + (scale :min 0 :max 101 :value volume :onchange "amixer -D pulse sset Master {}%")))) + +(defwidget slider-ram [] + (box :orientation "h" :class "slider-ram" :space-evenly false + (box :class "label-ram" "" + (scale :min 0 :max 101 :active false :value EWW_RAM)))) + + +(defwidget time [] + (box :class "time" + {hour + ":" + min + " " + month + " " + number_day + ", " + year_full})) + + +(defpoll music :interval "5s" "playerctl metadata --format '{{ artist }} - {{ title }}' || true") +(defpoll volume :interval "16s" "scripts/getvol") + +(defpoll number_day :interval "5h" "date '+%d'") +(defpoll month :interval "10h" "date '+%b'") +(defpoll min :interval "10s" "date '+%M'") +(defpoll hour :interval "1m" "date '+%H'") +(defpoll year_full :interval "15h" "date '+%Y'") + +(deflisten battery-remaining "/sys/class/power_supply/BAT0/capacity") + +(defwindow bar + :screen 0 + :focusable true + :windowtype "dock" + :geometry (geometry :x "0%" :y "0%" :width "100%" :height "4%") + :reserve (struts :side "top" :distance "4%") + (bar))