elkowar / eww

ElKowars wacky widgets
https://elkowar.github.io/eww
MIT License
9.11k stars 377 forks source link

[FEATURE] Reference variables in the definition of other variables #518

Open TornaxO7 opened 2 years ago

TornaxO7 commented 2 years ago

Checklist before submitting an issue

Description of the bug

I'd like to share the eww configs with two of my machines but each of them needs a little different setup (like size) so I'm trying to store some needed values in variabes which should be set during the startup of eww but somehow I can reuse some variables.

Reproducing the issue

Create ~/.config/eww/eww.yuck:

(defvar var true)
(defvar var2 {var ? 1 : 2})

(defwindow window []
  (label :text "hi"))

and execute eww open window. This should create the following error message:

error: Tried to reference variable `var`, but we cannot access variables here
  ┌─ /home/tornax/.config/eww/eww.yuck:2:15
  │
2 │ (defvar var2 {var ? 1 : 2})
  │               ───
  │
  → Expected format: `(defvar name "initial-value")`

Given SCSS File Doesnt Exist! /home/tornax/.config/eww/eww.scss

Caused by:
    No such file or directory (os error 2)

Expected behaviour

I expected to be able to use var in var2.

Additional context

No response

elkowar commented 2 years ago

Currently, it's not possible to refer to variables in the definition of other variables. This may be possible in the future, so I'll keep this open, but for now this is expected behavior

TornaxO7 commented 2 years ago

Oh, ok. Thank you for the information!

bfg-coding commented 1 year ago

Just to make sure this would also apply to deflisten right?

use case

(defvar path "/some/pre/determined/path")
(deflisten listener "script --needed-config ${path}/the/file")

this is throwing the error "we cannot access variable here"

natto1784 commented 1 year ago

bump

ArtemSmaznov commented 1 year ago

If possible it would be great if it would for windows as well (in addition to vars, polls, listens)

use case:

(defwindow bar1
  :monitor 1
  :windowtype "dock"
  :stacking "bg"
  :geometry (geometry :x "0%"
                      :y "0%"
                      ;; :width "100%"
                      :width "${1440 - trayer-width}"
                      :height "24px"
                      :anchor "top left")
  :reserve (struts :side "top"
                   :distance "24px")
  (centerbox :orientation "h"
             :class "bar"
             (leftside)
             ""
             (rightside-1)))
hvitoi commented 1 year ago

Another use-case is on a multi-monitor setup to open the bar on the currently focused monitor (I use a keybinding to open/close the bar)