diff --git a/CHANGELOG.md b/CHANGELOG.md index 3710363e..169dec01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ All notable changes to eww will be listed here, starting at changes since versio - Fix wayland monitor names support (By: dragonnn) ### Features +- Add `eww poll` subcommand to force-poll a variable (By: kiana-S) - Update rust toolchain to 1.81.0 (By: w-lfchen) - Add `:fill-svg` and `:preserve-aspect-ratio` properties to images (By: hypernova7, w-lfchen) - Add `:truncate` property to labels, disabled by default (except in cases where truncation would be enabled in version `0.5.0` and before) (By: Rayzeq). diff --git a/crates/eww/src/app.rs b/crates/eww/src/app.rs index 2da4ab2e..38a3f846 100644 --- a/crates/eww/src/app.rs +++ b/crates/eww/src/app.rs @@ -45,6 +45,7 @@ use yuck::{ pub enum DaemonCommand { NoOp, UpdateVars(Vec<(VarName, DynVal)>), + PollVars(Vec), ReloadConfigAndCss(DaemonResponseSender), OpenInspector, OpenMany { @@ -167,6 +168,11 @@ impl App { self.update_global_variable(var_name, new_value); } } + DaemonCommand::PollVars(names) => { + for var_name in names { + self.force_poll_variable(var_name); + } + } DaemonCommand::ReloadConfigAndCss(sender) => { let mut errors = Vec::new(); @@ -336,6 +342,23 @@ impl App { } } + fn force_poll_variable(&mut self, name: VarName) { + match self.eww_config.get_script_var(&name) { + Err(err) => error_handling_ctx::print_error(err), + Ok(var) => { + if let ScriptVarDefinition::Poll(poll_var) = var { + log::debug!("force-polling var {}", &name); + match script_var_handler::run_poll_once(&poll_var) { + Err(err) => error_handling_ctx::print_error(err), + Ok(value) => self.update_global_variable(name, value), + } + } else { + error_handling_ctx::print_error(anyhow!("Script var '{}' is not polling", name)) + } + } + } + } + /// Close a window and do all the required cleanups in the scope_graph and script_var_handler fn close_window(&mut self, instance_id: &str) -> Result<()> { if let Some(old_abort_send) = self.window_close_timer_abort_senders.remove(instance_id) { diff --git a/crates/eww/src/opts.rs b/crates/eww/src/opts.rs index b635a28b..fb010c62 100644 --- a/crates/eww/src/opts.rs +++ b/crates/eww/src/opts.rs @@ -98,6 +98,16 @@ pub enum ActionWithServer { mappings: Vec<(VarName, DynVal)>, }, + /// Update a polling variable using its script. + /// + /// This will force the variable to be updated even if its + /// automatic polling is disabled. + #[command(name = "poll")] + Poll { + /// Variables to be polled + names: Vec, + }, + /// Open the GTK debugger #[command(name = "inspector", alias = "debugger")] OpenInspector, @@ -254,6 +264,7 @@ impl ActionWithServer { pub fn into_daemon_command(self) -> (app::DaemonCommand, Option) { let command = match self { ActionWithServer::Update { mappings } => app::DaemonCommand::UpdateVars(mappings), + ActionWithServer::Poll { names } => app::DaemonCommand::PollVars(names), ActionWithServer::OpenInspector => app::DaemonCommand::OpenInspector, ActionWithServer::KillServer => app::DaemonCommand::KillServer, diff --git a/crates/eww/src/script_var_handler.rs b/crates/eww/src/script_var_handler.rs index 717d4d92..885bbb68 100644 --- a/crates/eww/src/script_var_handler.rs +++ b/crates/eww/src/script_var_handler.rs @@ -196,7 +196,7 @@ impl PollVarHandler { } } -fn run_poll_once(var: &PollScriptVar) -> Result { +pub fn run_poll_once(var: &PollScriptVar) -> Result { match &var.command { VarSource::Shell(span, command) => { script_var::run_command(command).map_err(|e| anyhow!(create_script_var_failed_warn(*span, &var.name, &e.to_string()))) diff --git a/docs/src/configuration.md b/docs/src/configuration.md index 78775e15..15685101 100644 --- a/docs/src/configuration.md +++ b/docs/src/configuration.md @@ -209,6 +209,9 @@ and thus are the perfect choice for showing your time, date, as well as other bi You can also specify an initial-value. This should prevent eww from waiting for the result of a given command during startup, thus making the startup time faster. +To externally update a polling variable, `eww update` can be used like with basic variables to assign a value. +You can also call `eww poll` to poll the variable outside of its usual interval, or even while it isn't running at all. + **Listening variables (`deflisten`)** ```lisp