From d7be7cecbb9fe7c3ee6acbc59e98e0fd5698410b Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Sat, 23 Jan 2021 21:12:03 +0100 Subject: [PATCH] Some refinements --- src/client.rs | 3 +-- src/con.rs | 37 ++++++++++++++++++++++++++++++------- src/demon.rs | 2 +- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/client.rs b/src/client.rs index 5fb9ece..9bc34df 100644 --- a/src/client.rs +++ b/src/client.rs @@ -17,8 +17,7 @@ pub fn switch_window() { pub fn switch_workspace() { let root = con::get_tree(); - let mut workspaces = con::get_workspaces(&root, false); - workspaces.sort(); + let workspaces = con::get_workspaces(&root, false); if let Some(workspace) = con::select_workspace("Switch to workspace", &workspaces) diff --git a/src/con.rs b/src/con.rs index 84b8dca..60995ec 100644 --- a/src/con.rs +++ b/src/con.rs @@ -137,15 +137,9 @@ fn build_windows( fn build_workspaces( root: &ipc::Node, mut con_props: HashMap, - include_scratchpad: bool, ) -> Vec { let mut v = vec![]; for workspace in root.workspaces() { - if !include_scratchpad - && workspace.name.as_ref().unwrap().eq("__i3_scratch") - { - continue; - } v.push(Workspace { node: &workspace, con_props: con_props.remove(&workspace.id), @@ -198,7 +192,32 @@ pub fn get_workspaces( } }; - build_workspaces(root, con_props.unwrap_or_default(), include_scratchpad) + let workspaces = build_workspaces(root, con_props.unwrap_or_default()); + let mut workspaces = if include_scratchpad { + workspaces + } else { + workspaces + .into_iter() + .filter(|ws| !ws.is_scratchpad()) + .collect() + }; + workspaces.sort(); + println!( + "Sorted WS: {:?}", + workspaces + .iter() + .map(Workspace::get_name) + .collect::>() + ); + workspaces.rotate_left(1); + println!( + "Rotated WS: {:?}", + workspaces + .iter() + .map(Workspace::get_name) + .collect::>() + ); + workspaces } #[test] @@ -241,6 +260,10 @@ impl Workspace<'_> { pub fn get_id(&self) -> &ipc::Id { &self.node.id } + + pub fn is_scratchpad(&self) -> bool { + self.get_name().eq("__i3_scratch") + } } impl PartialEq for Workspace<'_> { diff --git a/src/demon.rs b/src/demon.rs index b556cb4..20f9b77 100644 --- a/src/demon.rs +++ b/src/demon.rs @@ -22,7 +22,7 @@ pub fn monitor_window_events( .stdout(proc::Stdio::piped()) .spawn() .expect("Failed to subscribe to window events"); - let stdout: std::process::ChildStdout = child.stdout.unwrap(); + let stdout: proc::ChildStdout = child.stdout.unwrap(); let stream = Deserializer::from_reader(stdout).into_iter::(); for res in stream { match res {