finishing up scratchpad info

This commit is contained in:
Penelope Gwen 2026-01-21 12:52:35 -08:00
parent 7ac6cac663
commit 41aeab7bda
4 changed files with 176 additions and 19 deletions

131
Cargo.lock generated
View file

@ -505,6 +505,15 @@ dependencies = [
"dirs-sys 0.3.7",
]
[[package]]
name = "dirs"
version = "5.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
dependencies = [
"dirs-sys 0.4.1",
]
[[package]]
name = "dirs"
version = "6.0.0"
@ -525,6 +534,18 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "dirs-sys"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
dependencies = [
"libc",
"option-ext",
"redox_users 0.4.6",
"windows-sys 0.48.0",
]
[[package]]
name = "dirs-sys"
version = "0.5.0"
@ -669,6 +690,30 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "freedesktop-file-parser"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1998b5ee36700463150124ac6d6d6128a5a4da453a6f6777a26810f05539f41"
dependencies = [
"freedesktop-icons",
"thiserror 2.0.16",
]
[[package]]
name = "freedesktop-icons"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95f87364ea709292a3b3f74014ce3ee78412c89807eea75a358c8e029b000994"
dependencies = [
"dirs 5.0.1",
"ini_core",
"once_cell",
"thiserror 1.0.69",
"tracing",
"xdg 2.5.2",
]
[[package]]
name = "fsevent-sys"
version = "4.1.0"
@ -900,6 +945,15 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "ini_core"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a467a31a9f439b5262fa99c17084537bff57f24703d5a09a2b5c9657ec73a61"
dependencies = [
"cfg-if 1.0.3",
]
[[package]]
name = "inotify"
version = "0.11.0"
@ -1788,7 +1842,10 @@ dependencies = [
"clap",
"confy",
"dialog",
"dirs 6.0.0",
"env_logger",
"freedesktop-file-parser",
"freedesktop-icons",
"hex",
"image",
"log",
@ -1803,7 +1860,7 @@ dependencies = [
"walkdir",
"watchexec",
"watchexec-events",
"xdg",
"xdg 3.0.0",
]
[[package]]
@ -2365,6 +2422,15 @@ dependencies = [
"windows-link",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets 0.48.5",
]
[[package]]
name = "windows-sys"
version = "0.59.0"
@ -2383,6 +2449,21 @@ dependencies = [
"windows-targets 0.53.3",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm 0.48.5",
"windows_aarch64_msvc 0.48.5",
"windows_i686_gnu 0.48.5",
"windows_i686_msvc 0.48.5",
"windows_x86_64_gnu 0.48.5",
"windows_x86_64_gnullvm 0.48.5",
"windows_x86_64_msvc 0.48.5",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
@ -2425,6 +2506,12 @@ dependencies = [
"windows-link",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
@ -2437,6 +2524,12 @@ version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
@ -2449,6 +2542,12 @@ version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
@ -2473,6 +2572,12 @@ version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
@ -2485,6 +2590,12 @@ version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
@ -2497,6 +2608,12 @@ version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
@ -2509,6 +2626,12 @@ version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
@ -2536,6 +2659,12 @@ version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
[[package]]
name = "xdg"
version = "2.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546"
[[package]]
name = "xdg"
version = "3.0.0"

View file

@ -14,7 +14,10 @@ path = "src/main.rs"
clap = { version = "4.5.45", features = ["derive"] }
confy = "1.0.0"
dialog = "0.3.0"
dirs = "6.0.0"
env_logger = "0.11.8"
freedesktop-file-parser = "0.3.1"
freedesktop-icons = "0.4.0"
hex = "0.4.3"
image = "0.25.8"
log = "0.4.28"
@ -33,4 +36,4 @@ xdg = "3.0.0"
[package.metadata.deb]
#conflicts = ["sway-profiles"]
changelog = "debian/changelog"
changelog = "debian/changelog"

View file

@ -1,11 +1,23 @@
use std::path::PathBuf;
use freedesktop_icons::lookup;
use serde_json::{Value, json};
use swayipc::{Node, ScratchpadState};
use crate::lib::get_sway_connection;
#[derive(serde::Serialize)]
pub struct ScratchpadInfo {
icon: PathBuf,
visible: bool,
name: Option<String>,
title: Option<String>,
window_id: i64
}
fn search_node(node: Node) -> Vec<Node> {
let mut node_vec: Vec<Node> = vec![];
// println!("Name: {:?}",node.name);
if node.scratchpad_state.eq(&Some(ScratchpadState::Fresh)) {
node_vec.push(node);
} else {
@ -25,31 +37,42 @@ fn search_node(node: Node) -> Vec<Node> {
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);
fn icon_lookup(name : &str, size: u16) -> Option<PathBuf> {lookup(name).with_cache().with_size(size).find()}
println!("{:?}",window.window_properties.unwrap().class);
PathBuf::new()
}*/
fn app_icon_lookup(name: &str) -> Option<PathBuf> {
//TODO better & faster icon searching
//let sizes: Vec<u16> = vec![512, 256, 128, 64, 24, 22, 16];
//sizes.into_iter().find_map(|s|icon_lookup(name, s))
lookup(name).with_cache().with_theme("breeze").find()
}
fn get_app_icon(window: Node) -> PathBuf {
app_icon_lookup(&window.sandbox_app_id.unwrap_or_default()).or(
match window.window_properties {
Some(w) => app_icon_lookup(&w.class.unwrap_or_default()),
None => app_icon_lookup(&window.app_id.unwrap_or_default()),
}
).unwrap_or("/usr/share/icons/breeze-dark/mimetypes/32/unknown.svg".into())
}
pub fn get_scratchpad_info() -> Value {
let tree = get_sway_connection().get_tree().expect("todo");
let mut scratchpad_vec: Vec<Node> = vec![];
// $20 says this is NOT the best way to recursively check all nodes for
let mut scratchpad_vec: Vec<ScratchpadInfo> = vec![];
// $20 says this is NOT the best way to recursively check all nodes but i'll fix it later
for output in tree.nodes {
for workspace in output.nodes {
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 app_icon = get_app_icon(n.clone());
let title = match n.window_properties.clone() {
Some(w) => w.class,
None => n.app_id,
};
let scratch_node: ScratchpadInfo = ScratchpadInfo { icon: app_icon, visible: n.visible.unwrap_or_default(), name: n.name, title: title, window_id: n.id };
scratchpad_vec.push(scratch_node);
}
}
};

View file

@ -11,6 +11,7 @@ use {
pub struct SwayInfo {
window_info: Value,
workspace_info: Value,
scratchpad_info: Value
}
pub fn get_sway_connection() -> Connection {
@ -31,7 +32,8 @@ pub fn run_sway_command(sway_connection: &mut Connection,payload: String) -> Res
pub fn get_sway_info(window_icons: &[WindowIcon], profile_list: Vec<Profile>, kb_order: bool) -> Value {
let window_info = get_window_info(window_icons);
let workspace_info = get_workspace_info(profile_list, kb_order);
let full_info = SwayInfo{ window_info, workspace_info };
let scratchpad_info = get_scratchpad_info();
let full_info = SwayInfo{ window_info, workspace_info, scratchpad_info };
json!(full_info)
}