begin implementing scratchpad functionality

This commit is contained in:
Penelope Gwen 2026-01-19 18:10:48 -08:00
parent 96991b6ff1
commit 1bdab513b6

55
src/lib/scratchpad.rs Normal file
View file

@ -0,0 +1,55 @@
use log::debug;
use serde_json::Value;
use swayipc::{Node, NodeType};
use crate::lib::get_sway_connection;
fn search_node(node: Node, indent: String, search_type: NodeType) -> Vec<Node> {
let mut node_vec: Vec<Node> = vec![];
println!("{}{:?}: {} - {:?} ({} nodes)", indent, node.node_type, node.name.unwrap_or_default(), node.scratchpad_state, node.nodes.len()+node.floating_nodes.len());
for n in node.nodes {
for nn in search_node(n, indent.clone()+"--", search_type) {
node_vec.push(nn);
}
/* match search_node(n, indent.clone()+"--", search_type) {
Some(n) => node_vec.push(n),
None => todo!(),
} */
};
for f in node.floating_nodes {
for ff in search_node(f, indent.clone()+"--", search_type) {
node_vec.push(ff);
}
/* match search_node(f, indent.clone()+"--", search_type) {
Some(_) => todo!(),
None => todo!(),
} */
};
node_vec
}
pub fn get_scratchpad_info() -> Value {
let tree = get_sway_connection().get_tree().expect("todo");
// search_node(tree, "-".to_string());
for output in tree.nodes {
println!("{:?}",output.node_type);
for workspace in output.nodes {
println!("{:?}",workspace.node_type);
for node in workspace.nodes {
let con_nodes = search_node(node, "--".to_string(), NodeType::Con);
println!("con_nodes: {:?}", con_nodes.len())
}
for floating_node in workspace.floating_nodes {
let floating_nodes = search_node(floating_node, "--".to_string(), NodeType::Con);
println!("floating_nodes: {:?}", floating_nodes.len())
}
}
}
//let outputs = tree.nodes.iter()//.filter(|x|x.node_type.eq(&swayipc::NodeType::Output));//.expect("todo"); //(|x|x.t .clone().unwrap().eq("__i3")).expect("todo").clone().find(|x|x.node_type.eq(&swayipc::NodeType::Workspace));
//for w in outputs {
// let workspace = w.f
//}
//let workspaces = outputs.nodes.iter().find(|x|x.node_type.eq(&swayipc::NodeType::Workspace)).expect("todo");
//println!("{:#?}",workspaces);
Value::Null
}