From ba9f2af5d8aab3fb44f0f0dd32ea7c9e9621b2a3 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Mon, 15 Nov 2021 08:13:47 +0100 Subject: [PATCH] New move-focused-to command --- NEWS.md | 4 +++- src/cmds.rs | 52 ++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/NEWS.md b/NEWS.md index ead5e18..5bdc473 100644 --- a/NEWS.md +++ b/NEWS.md @@ -19,7 +19,9 @@ swayr v0.10.0 the selected workspace/container or the selected window. - New command: `swap-focused-with` swaps the currently focused window or container with the one selected from the menu program. - +- New command: `move-focused-to` moves the currently focused container or + window to the selected one. Non-matching input will create a new workspace + of that name and move the focused container or window there. swayr v0.9.0 diff --git a/src/cmds.rs b/src/cmds.rs index c978a6a..ebe00b5 100644 --- a/src/cmds.rs +++ b/src/cmds.rs @@ -119,6 +119,9 @@ 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 + /// workspace, container, or window. + MoveFocusedTo, /// Swap the currently focused window or container with the selected /// container or window. SwapFocusedWith, @@ -232,6 +235,13 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) { SwayrCommand::QuitWorkspaceContainerOrWindow => { quit_workspace_container_or_window(&*props.read().unwrap()) } + SwayrCommand::MoveFocusedToWorkspace => { + move_focused_to_workspace(&*props.read().unwrap()) + } + SwayrCommand::MoveFocusedTo => move_focused_to(&*props.read().unwrap()), + SwayrCommand::SwapFocusedWith => { + swap_focused_with(&*props.read().unwrap()) + } SwayrCommand::NextWindow { windows } => focus_window_in_direction( Direction::Forward, windows, @@ -318,13 +328,6 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) { &*props.read().unwrap(), ) } - SwayrCommand::MoveFocusedToWorkspace => { - move_focused_to_workspace(&*props.read().unwrap()) - } - SwayrCommand::SwapFocusedWith => { - swap_focused_with(&*props.read().unwrap()) - } - SwayrCommand::TileWorkspace { floating } => { tile_current_workspace(floating, false) } @@ -342,6 +345,7 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) { let mut cmds = vec![ SwayrCommand::ExecuteSwaymsgCommand, SwayrCommand::MoveFocusedToWorkspace, + SwayrCommand::SwapFocusedWith, SwayrCommand::QuitWindow, SwayrCommand::QuitWorkspaceOrWindow, SwayrCommand::SwitchWindow, @@ -596,8 +600,25 @@ fn move_focused_to_workspace_1(ws_name: &str) { } } -fn move_focused_to_container_1(id: i64) { - run_sway_command(&["move", "container", "to", &format!("{}", id)]); +fn move_focused_to_container_or_window(id: i64) { + run_sway_command(&[ + &format!("[con_id=\"{}\"]", id), + "mark", + "--add", + "__SWAYR_MOVE_TARGET__", + ]); + run_sway_command(&[ + "move", + "container", + "to", + "mark", + "__SWAYR_MOVE_TARGET__", + ]); + run_sway_command(&[ + &format!("[con_id\"{}\"]", id), + "unmark", + "__SWAYR_MOVE_TARGET__", + ]); } fn select_and_move_focused_to(prompt: &str, choices: &[t::DisplayNode]) { @@ -610,7 +631,9 @@ fn select_and_move_focused_to(prompt: &str, choices: &[t::DisplayNode]) { move_focused_to_workspace_1(tn.node.get_name()) } } - t::Type::Container => move_focused_to_container_1(tn.node.id), + t::Type::Container | t::Type::Window => { + move_focused_to_container_or_window(tn.node.id) + } t => eprintln!("Cannot move focused to {:?}", t), }, Err(input) => { @@ -629,6 +652,15 @@ pub fn move_focused_to_workspace(extra_props: &HashMap) { ); } +pub fn move_focused_to(extra_props: &HashMap) { + let root = get_tree(true); + 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(), + ); +} + pub fn swap_focused_with(extra_props: &HashMap) { let root = get_tree(true); let tree = t::get_tree(&root, extra_props);