Skip to content

Commit c6decc8

Browse files
authored
feat: add subcommand to force-poll variable (#1227)
* feat: add subcommand for force-polling variable * docs: document the new `eww poll` subcommand
1 parent e7b9568 commit c6decc8

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ All notable changes to eww will be listed here, starting at changes since versio
1919
- `get_locale` now follows POSIX standard for locale selection (By: mirhahn, w-lfchen)
2020

2121
### Features
22+
- Add `eww poll` subcommand to force-poll a variable (By: kiana-S)
2223
- Add OnDemand support for focusable on wayland (By: GallowsDove)
2324
- Add jq `raw-output` support (By: RomanHargrave)
2425
- Update rust toolchain to 1.81.0 (By: w-lfchen)

crates/eww/src/app.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use yuck::{
4545
pub enum DaemonCommand {
4646
NoOp,
4747
UpdateVars(Vec<(VarName, DynVal)>),
48+
PollVars(Vec<VarName>),
4849
ReloadConfigAndCss(DaemonResponseSender),
4950
OpenInspector,
5051
OpenMany {
@@ -167,6 +168,11 @@ impl<B: DisplayBackend> App<B> {
167168
self.update_global_variable(var_name, new_value);
168169
}
169170
}
171+
DaemonCommand::PollVars(names) => {
172+
for var_name in names {
173+
self.force_poll_variable(var_name);
174+
}
175+
}
170176
DaemonCommand::ReloadConfigAndCss(sender) => {
171177
let mut errors = Vec::new();
172178

@@ -336,6 +342,23 @@ impl<B: DisplayBackend> App<B> {
336342
}
337343
}
338344

345+
fn force_poll_variable(&mut self, name: VarName) {
346+
match self.eww_config.get_script_var(&name) {
347+
Err(err) => error_handling_ctx::print_error(err),
348+
Ok(var) => {
349+
if let ScriptVarDefinition::Poll(poll_var) = var {
350+
log::debug!("force-polling var {}", &name);
351+
match script_var_handler::run_poll_once(&poll_var) {
352+
Err(err) => error_handling_ctx::print_error(err),
353+
Ok(value) => self.update_global_variable(name, value),
354+
}
355+
} else {
356+
error_handling_ctx::print_error(anyhow!("Script var '{}' is not polling", name))
357+
}
358+
}
359+
}
360+
}
361+
339362
/// Close a window and do all the required cleanups in the scope_graph and script_var_handler
340363
fn close_window(&mut self, instance_id: &str) -> Result<()> {
341364
if let Some(old_abort_send) = self.window_close_timer_abort_senders.remove(instance_id) {

crates/eww/src/opts.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ pub enum ActionWithServer {
9898
mappings: Vec<(VarName, DynVal)>,
9999
},
100100

101+
/// Update a polling variable using its script.
102+
///
103+
/// This will force the variable to be updated even if its
104+
/// automatic polling is disabled.
105+
#[command(name = "poll")]
106+
Poll {
107+
/// Variables to be polled
108+
names: Vec<VarName>,
109+
},
110+
101111
/// Open the GTK debugger
102112
#[command(name = "inspector", alias = "debugger")]
103113
OpenInspector,
@@ -254,6 +264,7 @@ impl ActionWithServer {
254264
pub fn into_daemon_command(self) -> (app::DaemonCommand, Option<daemon_response::DaemonResponseReceiver>) {
255265
let command = match self {
256266
ActionWithServer::Update { mappings } => app::DaemonCommand::UpdateVars(mappings),
267+
ActionWithServer::Poll { names } => app::DaemonCommand::PollVars(names),
257268
ActionWithServer::OpenInspector => app::DaemonCommand::OpenInspector,
258269

259270
ActionWithServer::KillServer => app::DaemonCommand::KillServer,

crates/eww/src/script_var_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl PollVarHandler {
196196
}
197197
}
198198

199-
fn run_poll_once(var: &PollScriptVar) -> Result<DynVal> {
199+
pub fn run_poll_once(var: &PollScriptVar) -> Result<DynVal> {
200200
match &var.command {
201201
VarSource::Shell(span, command) => {
202202
script_var::run_command(command).map_err(|e| anyhow!(create_script_var_failed_warn(*span, &var.name, &e.to_string())))

docs/src/configuration.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ and thus are the perfect choice for showing your time, date, as well as other bi
209209
You can also specify an initial-value. This should prevent eww from waiting for the result of a given command during startup, thus
210210
making the startup time faster.
211211

212+
To externally update a polling variable, `eww update` can be used like with basic variables to assign a value.
213+
You can also call `eww poll` to poll the variable outside of its usual interval, or even while it isn't running at all.
214+
212215
**Listening variables (`deflisten`)**
213216

214217
```lisp

0 commit comments

Comments
 (0)