reduce predicate overhead
This commit is contained in:
parent
9eb250b813
commit
d25ddb487e
1 changed files with 3 additions and 5 deletions
|
@ -61,20 +61,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>>{
|
|||
let cli = Cli::parse();
|
||||
let mut connection = Connection::new()?;
|
||||
|
||||
let predicate: Box<dyn Fn(&Node) -> bool> = match cli.use_field {
|
||||
UseField::Class => Box::new(|node: &Node| {
|
||||
let node = match cli.use_field {
|
||||
UseField::Class => find_node(&connection.get_tree()?, |node: &Node| {
|
||||
node.window_properties
|
||||
.as_ref()
|
||||
.and_then(|p| p.class.as_deref())
|
||||
== Some(&cli.identifier)
|
||||
}),
|
||||
UseField::AppId => Box::new(|node: &Node| {
|
||||
UseField::AppId => find_node(&connection.get_tree()?, |node: &Node| {
|
||||
node.app_id.as_deref() == Some(&cli.identifier)
|
||||
}),
|
||||
};
|
||||
|
||||
let node = find_node(&connection.get_tree()?, predicate.as_ref());
|
||||
|
||||
let sway_cmd = if let Some(node) = node {
|
||||
if node.focused {
|
||||
format!("[{}={}] move scratchpad", cli.use_field, cli.identifier)
|
||||
|
|
Loading…
Reference in a new issue