From ff1c64f7d54020a923c19ab72e09ee290bdd2b94 Mon Sep 17 00:00:00 2001 From: Zaheen Jamil Date: Fri, 1 Sep 2023 23:22:21 -0700 Subject: [PATCH 1/2] Add force-poll command --- CHANGELOG.md | 1 + crates/eww/src/app.rs | 12 +++++++++++- crates/eww/src/opts.rs | 5 +++++ crates/eww/src/script_var_handler.rs | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b8ad175d..022e109f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ All notable changes to eww will be listed here, starting at changes since versio - Add trigonometric functions (`sin`, `cos`, `tan`, `cot`) and degree/radian conversions (`degtorad`, `radtodeg`) (By: end-4) - Add `substring` function to simplexpr - Add `--duration` flag to `eww open` +- Add `force-poll` command (By: ZaheenJ) ## [0.4.0] (04.09.2022) diff --git a/crates/eww/src/app.rs b/crates/eww/src/app.rs index 3b306be7d..7659847d1 100644 --- a/crates/eww/src/app.rs +++ b/crates/eww/src/app.rs @@ -5,7 +5,7 @@ use crate::{ error_handling_ctx, gtk::prelude::{ContainerExt, CssProviderExt, GtkWindowExt, MonitorExt, StyleContextExt, WidgetExt}, paths::EwwPaths, - script_var_handler::ScriptVarHandlerHandle, + script_var_handler::{run_poll_once, ScriptVarHandlerHandle}, state::scope_graph::{ScopeGraph, ScopeIndex}, *, }; @@ -41,6 +41,7 @@ use yuck::{ pub enum DaemonCommand { NoOp, UpdateVars(Vec<(VarName, DynVal)>), + ForcePoll(Vec), ReloadConfigAndCss(DaemonResponseSender), OpenInspector, OpenMany { @@ -148,6 +149,15 @@ impl App { self.update_global_variable(var_name, new_value); } } + DaemonCommand::ForcePoll(vars) => { + for var in vars { + if let ScriptVarDefinition::Poll(poll_var) = self.eww_config.get_script_var(&var)? { + self.update_global_variable(var, run_poll_once(poll_var)?); + } else { + Err(anyhow!(format!("No poll var named '{}' exists", var)))? + } + } + } DaemonCommand::ReloadConfigAndCss(sender) => { let mut errors = Vec::new(); diff --git a/crates/eww/src/opts.rs b/crates/eww/src/opts.rs index 75d08c3ba..94f8b888b 100644 --- a/crates/eww/src/opts.rs +++ b/crates/eww/src/opts.rs @@ -91,6 +91,10 @@ pub enum ActionWithServer { mappings: Vec<(VarName, DynVal)>, }, + /// Manually tells polling variables to update + #[clap(name = "force-poll", alias = "fp")] + ForcePoll { vars: Vec }, + /// Open the GTK debugger #[command(name = "inspector", alias = "debugger")] OpenInspector, @@ -210,6 +214,7 @@ impl ActionWithServer { pub fn into_daemon_command(self) -> (app::DaemonCommand, Option) { let command = match self { ActionWithServer::Update { mappings } => app::DaemonCommand::UpdateVars(mappings), + ActionWithServer::ForcePoll { vars } => app::DaemonCommand::ForcePoll(vars), 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 0847b72be..af5718a5c 100644 --- a/crates/eww/src/script_var_handler.rs +++ b/crates/eww/src/script_var_handler.rs @@ -192,7 +192,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()))) From be4d3e65d38d68d2ae7e549729e225653ac70f46 Mon Sep 17 00:00:00 2001 From: Zaheen Jamil Date: Sat, 2 Sep 2023 03:47:04 -0700 Subject: [PATCH 2/2] Added force-poll to docs --- docs/src/configuration.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/src/configuration.md b/docs/src/configuration.md index d7f62c891..ec07e38fe 100644 --- a/docs/src/configuration.md +++ b/docs/src/configuration.md @@ -191,6 +191,8 @@ They may also be useful to have buttons within eww change what is shown within y ``` A polling variable is a variable which runs a provided shell-script repeatedly, in a given interval. +You can also manually poll it by running `eww force-poll foo`. +This is very useful for information like volume or brightness which change with a keypress but you may still want to update regularly. This may be the most commonly used type of variable. They are useful to access any quickly retrieved value repeatedly,