Implement eww get command (#319)

This commit is contained in:
Pedro Burgos 2021-11-05 12:37:37 +01:00 committed by GitHub
parent 955271bbd5
commit 45badb7f38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 5 deletions

View file

@ -53,6 +53,10 @@ pub enum DaemonCommand {
all: bool,
sender: DaemonResponseSender,
},
GetVar {
name: String,
sender: DaemonResponseSender,
},
PrintDebug(DaemonResponseSender),
PrintWindows(DaemonResponseSender),
}
@ -176,6 +180,13 @@ impl App {
};
sender.send_success(output)?
}
DaemonCommand::GetVar { name, sender } => {
let vars = self.eww_state.get_variables();
match vars.get(name.as_str()) {
Some(x) => sender.send_success(x.to_string())?,
None => sender.send_failure(format!("Variable not found \"{}\"", name))?,
}
}
DaemonCommand::PrintWindows(sender) => {
let output = self
.eww_config

View file

@ -13,7 +13,7 @@ extern crate gtk;
extern crate gtk_layer_shell as gtk_layer_shell;
use anyhow::*;
use daemon_response::DaemonResponseReceiver;
use daemon_response::{DaemonResponse, DaemonResponseReceiver};
use opts::ActionWithServer;
use std::{
os::unix::net,
@ -145,7 +145,13 @@ fn handle_server_command(paths: &EwwPaths, action: &ActionWithServer, connect_at
log::debug!("Connected to Eww server ({}).", &paths.get_ipc_socket_file().display());
let response = client::do_server_call(&mut stream, action).context("Error while forwarding command to server")?;
if let Some(response) = response {
println!("{}", response);
match response {
DaemonResponse::Success(x) => println!("{}", x),
DaemonResponse::Failure(x) => {
eprintln!("{}", x);
bail!("Error, server command failed");
}
}
}
Ok(())
}

View file

@ -81,11 +81,11 @@ pub enum ActionWithServer {
mappings: Vec<(VarName, DynVal)>,
},
// Open the GTK debugger
/// Open the GTK debugger
#[structopt(name = "inspector", alias = "debugger")]
OpenInspector,
/// open a window
/// Open a window
#[structopt(name = "open", alias = "o")]
OpenWindow {
/// Name of the window you want to open.
@ -131,7 +131,7 @@ pub enum ActionWithServer {
#[structopt(name = "reload", alias = "r")]
Reload,
/// kill the eww daemon
/// Kill the eww daemon
#[structopt(name = "kill", alias = "k")]
KillServer,
@ -147,6 +147,10 @@ pub enum ActionWithServer {
all: bool,
},
/// Get the value of a variable if defined
#[structopt(name = "get")]
GetVar { name: String },
/// Print the names of all configured windows. Windows with a * in front of them are currently opened.
#[structopt(name = "windows")]
ShowWindows,
@ -219,6 +223,9 @@ impl ActionWithServer {
ActionWithServer::ShowState { all } => {
return with_response_channel(|sender| app::DaemonCommand::PrintState { all, sender })
}
ActionWithServer::GetVar { name } => {
return with_response_channel(|sender| app::DaemonCommand::GetVar { name, sender })
}
ActionWithServer::ShowDebug => return with_response_channel(app::DaemonCommand::PrintDebug),
};
(command, None)