scratchpad windows aren't considered in next-/prev-window

fixes #1
timeout_old
Tassilo Horn 4 years ago
parent 8c396ff27d
commit fdcb1a0bf4
  1. 17
      src/cmds.rs
  2. 26
      src/con.rs
  3. 6
      src/ipc.rs

@ -91,7 +91,7 @@ pub fn switch_to_urgent_or_lru_window(
extra_props: Option<&HashMap<i64, ipc::ExtraProps>>, extra_props: Option<&HashMap<i64, ipc::ExtraProps>>,
) { ) {
let root = get_tree(); let root = get_tree();
let windows = con::get_windows(&root, extra_props); let windows = con::get_windows(&root, true, extra_props);
if let Some(win) = windows if let Some(win) = windows
.iter() .iter()
.find(|w| w.is_urgent()) .find(|w| w.is_urgent())
@ -106,7 +106,7 @@ pub fn switch_to_urgent_or_lru_window(
pub fn switch_window(extra_props: Option<&HashMap<i64, ipc::ExtraProps>>) { pub fn switch_window(extra_props: Option<&HashMap<i64, ipc::ExtraProps>>) {
let root = get_tree(); let root = get_tree();
let windows = con::get_windows(&root, extra_props); let windows = con::get_windows(&root, true, extra_props);
if let Some(window) = con::select_window("Switch to window", &windows) { if let Some(window) = con::select_window("Switch to window", &windows) {
focus_window_by_id(window.get_id()) focus_window_by_id(window.get_id())
@ -123,7 +123,7 @@ pub fn focus_next_window_in_direction(
extra_props: Option<&HashMap<i64, ipc::ExtraProps>>, extra_props: Option<&HashMap<i64, ipc::ExtraProps>>,
) { ) {
let root = get_tree(); let root = get_tree();
let windows = con::get_windows(&root, None); let windows = con::get_windows(&root, false, None);
if windows.len() < 2 { if windows.len() < 2 {
return; return;
@ -131,10 +131,11 @@ pub fn focus_next_window_in_direction(
let pred: Box<dyn Fn(&con::Window) -> bool> = let pred: Box<dyn Fn(&con::Window) -> bool> =
if windows.iter().find(|w| w.is_focused()).is_none() { if windows.iter().find(|w| w.is_focused()).is_none() {
let last_focused_win_id = con::get_windows(&root, extra_props) let last_focused_win_id =
.get(0) con::get_windows(&root, false, extra_props)
.unwrap() .get(0)
.get_id(); .unwrap()
.get_id();
Box::new(move |w| w.get_id() == last_focused_win_id) Box::new(move |w| w.get_id() == last_focused_win_id)
} else { } else {
Box::new(|w: &con::Window| w.is_focused()) Box::new(|w: &con::Window| w.is_focused())
@ -187,7 +188,7 @@ pub fn switch_workspace_or_window(
pub fn quit_window(extra_props: Option<&HashMap<i64, ipc::ExtraProps>>) { pub fn quit_window(extra_props: Option<&HashMap<i64, ipc::ExtraProps>>) {
let root = get_tree(); let root = get_tree();
let windows = con::get_windows(&root, extra_props); let windows = con::get_windows(&root, true, extra_props);
if let Some(window) = con::select_window("Quit window", &windows) { if let Some(window) = con::select_window("Quit window", &windows) {
quit_window_by_id(window.get_id()) quit_window_by_id(window.get_id())

@ -109,10 +109,15 @@ impl<'a> fmt::Display for Window<'a> {
fn build_windows<'a>( fn build_windows<'a>(
root: &'a r::Node, root: &'a r::Node,
include_scratchpad_windows: bool,
extra_props: Option<&HashMap<i64, ipc::ExtraProps>>, extra_props: Option<&HashMap<i64, ipc::ExtraProps>>,
) -> Vec<Window<'a>> { ) -> Vec<Window<'a>> {
let mut v = vec![]; let mut v = vec![];
for workspace in root.workspaces() { for workspace in root.workspaces() {
if !include_scratchpad_windows && workspace.is_scratchpad() {
continue;
}
for n in workspace.windows() { for n in workspace.windows() {
v.push(Window { v.push(Window {
node: &n, node: &n,
@ -126,10 +131,15 @@ fn build_windows<'a>(
fn build_workspaces<'a>( fn build_workspaces<'a>(
root: &'a r::Node, root: &'a r::Node,
include_scratchpad: bool,
extra_props: Option<&HashMap<i64, ipc::ExtraProps>>, extra_props: Option<&HashMap<i64, ipc::ExtraProps>>,
) -> Vec<Workspace<'a>> { ) -> Vec<Workspace<'a>> {
let mut v = vec![]; let mut v = vec![];
for workspace in root.workspaces() { for workspace in root.workspaces() {
if !include_scratchpad && workspace.is_scratchpad() {
continue;
}
let mut wins: Vec<Window> = workspace let mut wins: Vec<Window> = workspace
.windows() .windows()
.iter() .iter()
@ -154,10 +164,11 @@ fn build_workspaces<'a>(
/// Gets all application windows of the tree. /// Gets all application windows of the tree.
pub fn get_windows<'a>( pub fn get_windows<'a>(
root: &'a r::Node, root: &'a r::Node,
include_scratchpad_windows: bool,
extra_props: Option<&HashMap<i64, ipc::ExtraProps>>, extra_props: Option<&HashMap<i64, ipc::ExtraProps>>,
) -> Vec<Window<'a>> { ) -> Vec<Window<'a>> {
let extra_props_given = extra_props.is_some(); let extra_props_given = extra_props.is_some();
let mut wins = build_windows(root, extra_props); let mut wins = build_windows(root, include_scratchpad_windows, extra_props);
if extra_props_given { if extra_props_given {
wins.sort(); wins.sort();
} }
@ -170,15 +181,8 @@ pub fn get_workspaces<'a>(
include_scratchpad: bool, include_scratchpad: bool,
extra_props: Option<&HashMap<i64, ipc::ExtraProps>>, extra_props: Option<&HashMap<i64, ipc::ExtraProps>>,
) -> Vec<Workspace<'a>> { ) -> Vec<Workspace<'a>> {
let workspaces = build_workspaces(root, extra_props); let mut workspaces =
let mut workspaces = if include_scratchpad { build_workspaces(root, include_scratchpad, extra_props);
workspaces
} else {
workspaces
.into_iter()
.filter(|ws| !ws.is_scratchpad())
.collect()
};
workspaces.rotate_left(1); workspaces.rotate_left(1);
workspaces workspaces
} }
@ -252,7 +256,7 @@ impl Workspace<'_> {
} }
pub fn is_scratchpad(&self) -> bool { pub fn is_scratchpad(&self) -> bool {
self.get_name().eq("__i3_scratch") self.node.is_scratchpad()
} }
} }

@ -50,6 +50,8 @@ pub trait NodeMethods {
/// Returns all nodes being workspaces. /// Returns all nodes being workspaces.
fn workspaces(&self) -> Vec<&r::Node>; fn workspaces(&self) -> Vec<&r::Node>;
fn is_scratchpad(&self) -> bool;
} }
impl NodeMethods for r::Node { impl NodeMethods for r::Node {
@ -72,6 +74,10 @@ impl NodeMethods for r::Node {
.filter(|n| n.node_type == r::NodeType::Workspace) .filter(|n| n.node_type == r::NodeType::Workspace)
.collect() .collect()
} }
fn is_scratchpad(&self) -> bool {
self.name.is_some() && self.name.as_ref().unwrap().eq("__i3_scratch")
}
} }
#[derive(Clap, Debug, Deserialize, Serialize)] #[derive(Clap, Debug, Deserialize, Serialize)]

Loading…
Cancel
Save