Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add subcommand to force-poll variable #1227

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
23 changes: 23 additions & 0 deletions crates/eww/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use yuck::{
pub enum DaemonCommand {
NoOp,
UpdateVars(Vec<(VarName, DynVal)>),
PollVars(Vec<VarName>),
ReloadConfigAndCss(DaemonResponseSender),
OpenInspector,
OpenMany {
Expand Down Expand Up @@ -167,6 +168,11 @@ impl<B: DisplayBackend> App<B> {
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();

Expand Down Expand Up @@ -336,6 +342,23 @@ impl<B: DisplayBackend> App<B> {
}
}

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) {
Expand Down
11 changes: 11 additions & 0 deletions crates/eww/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<VarName>,
},

/// Open the GTK debugger
#[command(name = "inspector", alias = "debugger")]
OpenInspector,
Expand Down Expand Up @@ -254,6 +264,7 @@ impl ActionWithServer {
pub fn into_daemon_command(self) -> (app::DaemonCommand, Option<daemon_response::DaemonResponseReceiver>) {
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,
Expand Down
2 changes: 1 addition & 1 deletion crates/eww/src/script_var_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl PollVarHandler {
}
}

fn run_poll_once(var: &PollScriptVar) -> Result<DynVal> {
pub fn run_poll_once(var: &PollScriptVar) -> Result<DynVal> {
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())))
Expand Down
3 changes: 3 additions & 0 deletions docs/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down