Make move-focused-to handle moving to outputs

timeout_old
Tassilo Horn 3 years ago
parent b6fc87901a
commit 7cad04ccff
  1. 3
      NEWS.md
  2. 16
      src/cmds.rs
  3. 23
      src/tree.rs

@ -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.

@ -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<i64, t::ExtraProps>) {
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(),
);
}

@ -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<DisplayNode> {
let outputs = self.sorted_nodes_of_type(Type::Output);
let v: Rc<RefCell<Vec<&s::Node>>> = 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<DisplayNode> {
let workspaces = self.sorted_nodes_of_type(Type::Workspace);
let v: Rc<RefCell<Vec<&s::Node>>> = 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
}
}
}
}

Loading…
Cancel
Save