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

Add force-poll command #910

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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 @@ -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)

Expand Down
12 changes: 11 additions & 1 deletion crates/eww/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
*,
};
Expand Down Expand Up @@ -41,6 +41,7 @@ use yuck::{
pub enum DaemonCommand {
NoOp,
UpdateVars(Vec<(VarName, DynVal)>),
ForcePoll(Vec<VarName>),
ReloadConfigAndCss(DaemonResponseSender),
OpenInspector,
OpenMany {
Expand Down Expand Up @@ -148,6 +149,15 @@ impl<B: DisplayBackend> App<B> {
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();

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

/// Open the GTK debugger
#[command(name = "inspector", alias = "debugger")]
OpenInspector,
Expand Down Expand Up @@ -210,6 +214,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::ForcePoll { vars } => app::DaemonCommand::ForcePoll(vars),
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 @@ -192,7 +192,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
2 changes: 2 additions & 0 deletions docs/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down