Some refinements

timeout_old
Tassilo Horn 4 years ago
parent aef14305f8
commit d7be7cecbb
  1. 3
      src/client.rs
  2. 37
      src/con.rs
  3. 2
      src/demon.rs

@ -17,8 +17,7 @@ pub fn switch_window() {
pub fn switch_workspace() { pub fn switch_workspace() {
let root = con::get_tree(); let root = con::get_tree();
let mut workspaces = con::get_workspaces(&root, false); let workspaces = con::get_workspaces(&root, false);
workspaces.sort();
if let Some(workspace) = if let Some(workspace) =
con::select_workspace("Switch to workspace", &workspaces) con::select_workspace("Switch to workspace", &workspaces)

@ -137,15 +137,9 @@ fn build_windows(
fn build_workspaces( fn build_workspaces(
root: &ipc::Node, root: &ipc::Node,
mut con_props: HashMap<ipc::Id, ipc::ConProps>, mut con_props: HashMap<ipc::Id, ipc::ConProps>,
include_scratchpad: bool,
) -> Vec<Workspace> { ) -> Vec<Workspace> {
let mut v = vec![]; let mut v = vec![];
for workspace in root.workspaces() { for workspace in root.workspaces() {
if !include_scratchpad
&& workspace.name.as_ref().unwrap().eq("__i3_scratch")
{
continue;
}
v.push(Workspace { v.push(Workspace {
node: &workspace, node: &workspace,
con_props: con_props.remove(&workspace.id), 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::<Vec<&str>>()
);
workspaces.rotate_left(1);
println!(
"Rotated WS: {:?}",
workspaces
.iter()
.map(Workspace::get_name)
.collect::<Vec<&str>>()
);
workspaces
} }
#[test] #[test]
@ -241,6 +260,10 @@ impl Workspace<'_> {
pub fn get_id(&self) -> &ipc::Id { pub fn get_id(&self) -> &ipc::Id {
&self.node.id &self.node.id
} }
pub fn is_scratchpad(&self) -> bool {
self.get_name().eq("__i3_scratch")
}
} }
impl PartialEq for Workspace<'_> { impl PartialEq for Workspace<'_> {

@ -22,7 +22,7 @@ pub fn monitor_window_events(
.stdout(proc::Stdio::piped()) .stdout(proc::Stdio::piped())
.spawn() .spawn()
.expect("Failed to subscribe to window events"); .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::<ipc::ConEvent>(); let stream = Deserializer::from_reader(stdout).into_iter::<ipc::ConEvent>();
for res in stream { for res in stream {
match res { match res {

Loading…
Cancel
Save