elkowar / eww

ElKowars wacky widgets

Home Page:https://elkowar.github.io/eww

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FEATURE] Run Command to Initialize `deflisten` Variables

hftsai256 opened this issue · comments

Description of the requested feature

I'm making a "script" based on Hyprland's IPC: the main idea is to push workspace information in JSON format over DBus on every update. Eww, on the other end, it will listen to signals on specific addresses:

(deflisten hypr_workspaces
  "dpeek -i org.hypryuck -p /monitors -m workspaces")

(dpeek is my own DBus listener to print stripped messages to stdout)

This model works quite well most of the time, except for initialization. Currently, I'm relying on the openlayer>>gtk-layer-shell event from Hyprland to write initial workspace information on DBus. I wonder if Eww can automatically fetch the initial value or run an init command that triggers the listening stream to emit some info. For example, I have a DBus method call on org.hypryuck/rpc/query that will trigger the script to write updated information, and I was attempting to invoke the call command through a dummy variable:

(defpoll runinit :initial true :interval "86400s"
  "dpoke -i org.hypryuck -p /rpc -m query -t method_call")

This, however, only works if I use this variable somewhere. Sneaking the command into another variable could serve as a dirty workaround:

(defpoll year :initial 1970
              :interval "3600s"
  "dpoke -i org.hypryuck -p /rpc -m query -t method_call >/dev/null; date '+%Y'")

Proposed configuration syntax

Perhaps we may have a trigger command for deflisten variables?

(deflisten hypr_workspaces 
  :trigger "dpoke -i org.hypryuck -p /rpc -m query -t method_call"
  "dpeek -i org.hypryuck -p /monitors -m workspaces")

Additional context

My Eww configuration

I have sorted out a (relatively neat?) solution. I can define a DBus method call that will return the JSON string, and define a long polling variable in Eww:

(defpoll hypr_workspaces :initial "{}"
                         :interval "86400s"
  "dpoke -i org.hypryuck -p /query -t call -m workspaces")

and whenever I need to update this variable, just call eww update hypr_workspaces={...} directly.