Add magic variables again

This commit is contained in:
elkowar 2021-07-26 22:41:20 +02:00
parent af38b09d5a
commit de8c79bc7d
No known key found for this signature in database
GPG key ID: E321AD71B1D1F27F
3 changed files with 68 additions and 4 deletions

View file

@ -21,7 +21,8 @@ pub struct EwwConfig {
impl EwwConfig { impl EwwConfig {
pub fn read_from_file(files: &mut YuckFiles, path: impl AsRef<Path>) -> Result<Self> { pub fn read_from_file(files: &mut YuckFiles, path: impl AsRef<Path>) -> Result<Self> {
let config = Config::generate_from_main_file(files, path)?; 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 { Ok(EwwConfig {
windows: window_definitions windows: window_definitions
.into_iter() .into_iter()

View file

@ -165,9 +165,9 @@ impl SimplExpr {
BinOp::NotEquals => DynVal::from(a != b), BinOp::NotEquals => DynVal::from(a != b),
BinOp::And => DynVal::from(a.as_bool()? && b.as_bool()?), BinOp::And => DynVal::from(a.as_bool()? && b.as_bool()?),
BinOp::Or => DynVal::from(a.as_bool()? || b.as_bool()?), BinOp::Or => DynVal::from(a.as_bool()? || b.as_bool()?),
BinOp::Plus => match a.as_f64() { BinOp::Plus => match (a.as_f64(), b.as_f64()) {
Ok(num) => DynVal::from(num + b.as_f64()?), (Ok(a), Ok(b)) => DynVal::from(a + b),
Err(_) => DynVal::from(format!("{}{}", a.as_string()?, b.as_string()?)), _ => DynVal::from(format!("{}{}", a.as_string()?, b.as_string()?)),
}, },
BinOp::Minus => DynVal::from(a.as_f64()? - b.as_f64()?), BinOp::Minus => DynVal::from(a.as_f64()? - b.as_f64()?),
BinOp::Times => DynVal::from(a.as_f64()? * b.as_f64()?), BinOp::Times => DynVal::from(a.as_f64()? * b.as_f64()?),

63
examples/eww-bar/eww.yuck Normal file
View file

@ -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))