refactor & begin implementing scratchpad

This commit is contained in:
Penelope Gwen 2026-01-20 17:43:43 -08:00
parent 1bdab513b6
commit 7ac6cac663
8 changed files with 60 additions and 49 deletions

2
Cargo.lock generated
View file

@ -1783,7 +1783,7 @@ dependencies = [
[[package]]
name = "sway-de-utils"
version = "0.1.1"
version = "0.1.2"
dependencies = [
"clap",
"confy",

View file

@ -1,6 +1,6 @@
[package]
name = "sway-de-utils"
version = "0.1.1"
version = "0.1.2"
authors = ["Penelope Gwen <support@pogmom.me>"]
edition = "2024"
license-file = "LICENSE.md"

6
debian/changelog vendored
View file

@ -1,3 +1,9 @@
sway-de-utils (0.1.2-1) unstable; urgency=medium
* partial implementation of sdu sway get scratchpad
-- Penelope Gwen <support@pogmom.me> Tue, 20 Jan 2026 00:28:36 -0800
sway-de-utils (0.1.1-1) unstable; urgency=medium
* increase information provided by sdu sway get workspaces

View file

@ -41,5 +41,6 @@ pub async fn watch(profiles_config: Vec<Profile>,info: ProfileGetCommand,watch_p
let main = wx.main();
wx.config.pathset([watch_path]);
let _ = main.await.into_diagnostic();
//todo: handle this return properly
Ok(())
}

View file

@ -68,20 +68,20 @@ pub fn profile_fn(profile_command: &ProfileCommand, profiles_config: Vec<Profile
},
Some(ProfileSwitchCommand::Next) => match next(profiles_config, preserve_keyboard_order) {
Ok(_) => {
let _: () = debug!("Successfully switched to next profile");
debug!("Successfully switched to next profile");
Ok(())
},
Err(e) => Err(e),
},
Some(ProfileSwitchCommand::Prev) => match previous(profiles_config, preserve_keyboard_order) {
Ok(_) => {
let _: () = debug!("successfully switched to previous profile");
debug!("successfully switched to previous profile");
Ok(())
},
Err(e) => Err(e),
},
None => {
let _: () = for profile in profiles_config {
for profile in profiles_config {
println!("{} {}", profile.icon, profile.name);
};
Ok(())

View file

@ -1,55 +1,59 @@
use log::debug;
use serde_json::Value;
use swayipc::{Node, NodeType};
use serde_json::{Value, json};
use swayipc::{Node, ScratchpadState};
use crate::lib::get_sway_connection;
fn search_node(node: Node, indent: String, search_type: NodeType) -> Vec<Node> {
fn search_node(node: Node) -> 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!(),
} */
};
// println!("Name: {:?}",node.name);
if node.scratchpad_state.eq(&Some(ScratchpadState::Fresh)) {
node_vec.push(node);
} else {
for node in node.nodes {
let node_vec_recurse = search_node(node);
for n in node_vec_recurse {
node_vec.push(n);
}
};
for floating_node in node.floating_nodes {
let node_vec_recurse = search_node(floating_node);
for n in node_vec_recurse {
node_vec.push(n);
}
};
}
node_vec
}
/*fn get_window_icon(window: Node) -> PathBuf {
let search_name = match window.app_id {
Some(ref s) => s,
None => match window.window_properties {
Some(_) => todo!(),
None => todo!(),
},
};
println!("{:?}",window.app_id);
println!("{:?}",window.window_properties.unwrap().class);
PathBuf::new()
}*/
pub fn get_scratchpad_info() -> Value {
let tree = get_sway_connection().get_tree().expect("todo");
// search_node(tree, "-".to_string());
let mut scratchpad_vec: Vec<Node> = vec![];
// $20 says this is NOT the best way to recursively check all nodes for
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())
}
for node_list in [workspace.nodes,workspace.floating_nodes] {
for node in node_list {
let sp_nodes = search_node(node);
for n in sp_nodes {
scratchpad_vec.push(n);
}
}
};
}
}
//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
json!(scratchpad_vec)
}

View file

@ -27,7 +27,7 @@ pub fn sway_fn( sway_command: &SwayCommand, window_icons: &[WindowIcon], profile
let _: () = if monitor.unwrap_or_default() {
let event_monitors = match requested_info {
SwayGetCommand::Workspaces => vec![EventType::Workspace],
SwayGetCommand::Scratchpad => todo!(),
SwayGetCommand::Scratchpad => vec![EventType::Window],
SwayGetCommand::Window | SwayGetCommand::Full => vec![EventType::Window,EventType::Workspace],
};
sway_ipc::monitor_events(event_monitors, requested_info, window_icons, profile_list, kb_order);

View file

@ -1,6 +1,6 @@
use {
crate::{
config::{Profile, WindowIcon}, lib::{cli::SwayGetCommand, windows::get_window_info, workspaces::get_workspace_info}, utils::SDUError
config::{Profile, WindowIcon}, lib::{cli::SwayGetCommand, get_scratchpad_info, windows::get_window_info, workspaces::get_workspace_info}, utils::SDUError
}, log::debug, serde_json::{Value, json}, std::time::Instant, swayipc::{
Connection,
EventType
@ -45,7 +45,7 @@ pub fn monitor_events(event_type: Vec<EventType>, get_command: &SwayGetCommand,
SwayGetCommand::Window => get_window_info(window_icons),
SwayGetCommand::Workspaces => get_workspace_info(profile_list.clone(), kb_order),
SwayGetCommand::Full => get_sway_info(window_icons, profile_list.clone(), kb_order),
SwayGetCommand::Scratchpad => todo!(),
SwayGetCommand::Scratchpad => get_scratchpad_info(),
}
},
_ => unreachable!(),