[PATCH swayr] Implement window stealing
Export this patch
This allows the user to steal a window from another workspace into the
current workspace. Very useful to get an open document which you know is
on some workspace, but needs to be moved into the current one.
Very good, I'll take it. :-)
Please add the new command to the README.md and have a look at the
nitpicks below.
---
swayr/src/cmds.rs | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/swayr/src/cmds.rs b/swayr/src/cmds.rs
index 090b77a..6d9c19d 100644
--- a/swayr/src/cmds.rs
+++ b/swayr/src/cmds.rs
@@ -150,6 +150,8 @@ pub enum SwayrCommand {
},
/// Focus the selected window.
SwitchWindow,
+ /// Steal the selected window from another workspace into this workspace
+ StealWindow,
Please add a period at the end of the sentence.
/// Switch to the selected workspace.
SwitchWorkspace,
/// Switch to the selected workspace.
@@ -440,6 +442,7 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) {
)
}
SwayrCommand::SwitchWindow => switch_window(fdata),
+ SwayrCommand::StealWindow => steal_window(fdata),
SwayrCommand::SwitchWorkspace => switch_workspace(fdata),
SwayrCommand::SwitchOutput => switch_output(),
SwayrCommand::SwitchWorkspaceOrWindow => {
@@ -580,6 +583,7 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) {
SwayrCommand::SwapFocusedWith,
SwayrCommand::QuitWorkspaceOrWindow,
SwayrCommand::SwitchWindow,
+ SwayrCommand::StealWindow,
SwayrCommand::SwitchWorkspace,
SwayrCommand::SwitchOutput,
SwayrCommand::SwitchWorkspaceOrWindow,
@@ -648,6 +652,11 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) {
*last_command = args.cmd.clone();
}
+ fn steal_window_by_id(id: i64) -> i64 {
+ run_sway_command(&[format!("[con_id={}]", id).as_str(), "move to workspace current"]);
+ id
+ }
+
fn focus_window_by_id(id: i64) -> i64 {
run_sway_command(&[format!("[con_id={}]", id).as_str(), "focus"]);
id
@@ -887,12 +896,32 @@ fn select_and_focus(prompt: &str, choices: &[t::DisplayNode]) {
}
}
+ fn select_and_steal(prompt: &str, choices: &[t::DisplayNode]) {
+ match util::select_from_menu(prompt, choices) {
+ Ok(tn) => match tn.node.get_type() {
+ ipc::Type::Window | ipc::Type::Container => {
+ steal_window_by_id(tn.node.id);
+ },
+ _ => { () }
+ },
+ Err(_) => {
+ ()
+ }
+ }
+ }
Above in select_and_steal you allow windows and containers (good!) but
below in steal_window you only offer windows to be selected. Maybe add
a second command steal_window_or_container where both can be selected.
Also add some log output to the _ and Err(_) cases.
+
pub fn switch_window(fdata: &FocusData) {
let root = ipc::get_root_node(true);
let tree = t::get_tree(&root);
select_and_focus("Select window", &tree.get_windows(fdata));
}
+ pub fn steal_window(fdata: &FocusData) {
+ let root = ipc::get_root_node(true);
+ let tree = t::get_tree(&root);
+ select_and_steal("Select window", &tree.get_windows(fdata));
+ }
Thanks a lot,
Tassilo
+
pub fn switch_workspace(fdata: &FocusData) {
let root = ipc::get_root_node(false);
let tree = t::get_tree(&root);
--
2.38.0
swayr/patches/arch.yml: SUCCESS in 4m17s
[Implement window stealing][0] from [Rouven Czerwinski][1]
[0]: https://lists.sr.ht/~tsdh/public-inbox/patches/36359
[1]: mailto:rouven@czerwinskis.de
✓ #868583 SUCCESS swayr/patches/arch.yml https://builds.sr.ht/~tsdh/job/868583
Rouven Czerwinski <rouven@czerwinskis.de> writes:
Hi Rouven,