From 7cad04ccff071f24c68bcf9aa4b9c8cfdffabbca Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Thu, 25 Nov 2021 22:06:44 +0100 Subject: [PATCH] Make move-focused-to handle moving to outputs --- NEWS.md | 3 +++ src/cmds.rs | 16 +++++++++++++--- src/tree.rs | 23 ++++++++++++++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 6c3b82f..0e8457c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,9 @@ swayr v0.11.0 there's a new `format.output_format` spec. - New command: `configure-outputs` lets you repeatedly issue output commands until you abort the menu program. +- `move-focused-to` now also supports outputs, i.e., you can move the currently + focused container to some output which means it's moved to the workspace + currently active on that output. - Formats can now include a `{output_name}` placeholder which is replaced by the name of the output containing the shown workspace, container or window. diff --git a/src/cmds.rs b/src/cmds.rs index 6da737c..e84d450 100644 --- a/src/cmds.rs +++ b/src/cmds.rs @@ -138,7 +138,7 @@ pub enum SwayrCommand { /// Move the currently focused window or container to the selected /// workspace. MoveFocusedToWorkspace, - /// Move the currently focused window or container to the selected + /// Move the currently focused window or container to the selected output, /// workspace, container or window. MoveFocusedTo, /// Swap the currently focused window or container with the selected @@ -653,9 +653,19 @@ fn move_focused_to_container_or_window(id: i64) { fn select_and_move_focused_to(prompt: &str, choices: &[t::DisplayNode]) { match util::select_from_menu(prompt, choices) { Ok(tn) => match tn.node.get_type() { + t::Type::Output => { + if tn.node.is_scratchpad() { + run_sway_command_1("move container to scratchpad") + } else { + run_sway_command(&[ + "move container to output", + &tn.node.get_name(), + ]) + } + } t::Type::Workspace => { if tn.node.is_scratchpad() { - run_sway_command(&["move", "container", "to", "scratchpad"]) + run_sway_command_1("move container to scratchpad") } else { move_focused_to_workspace_1(tn.node.get_name()) } @@ -686,7 +696,7 @@ pub fn move_focused_to(extra_props: &HashMap) { let tree = t::get_tree(&root, extra_props); select_and_move_focused_to( "Move focused container to workspace or container", - &tree.get_workspaces_containers_and_windows(), + &tree.get_outputs_workspaces_containers_and_windows(), ); } diff --git a/src/tree.rs b/src/tree.rs index cd7a4e0..02b7f49 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -174,9 +174,9 @@ pub struct Tree<'a> { #[derive(Copy, Clone, PartialEq, Eq)] enum IndentLevel { - Fixed(u32), + Fixed(usize), WorkspacesZeroWindowsOne, - TreeDepth(u8), + TreeDepth(usize), } pub struct DisplayNode<'a> { @@ -344,6 +344,19 @@ impl<'a> Tree<'a> { } } + pub fn get_outputs_workspaces_containers_and_windows( + &self, + ) -> Vec { + let outputs = self.sorted_nodes_of_type(Type::Output); + let v: Rc>> = Rc::new(RefCell::new(vec![])); + for o in outputs { + self.push_subtree_sorted(o, Rc::clone(&v)); + } + + let x = self.as_display_nodes(&*v.borrow(), IndentLevel::TreeDepth(1)); + x + } + pub fn get_workspaces_containers_and_windows(&self) -> Vec { let workspaces = self.sorted_nodes_of_type(Type::Workspace); let v: Rc>> = Rc::new(RefCell::new(vec![])); @@ -550,7 +563,11 @@ impl DisplayFormat for DisplayNode<'_> { depth += 1; node = p; } - depth - offset as usize + if offset > depth { + 0 + } else { + depth - offset as usize + } } } }