~tsdh/public-inbox

swayr: Implement window stealing v1 PROPOSED

Rouven Czerwinski: 1
 Implement window stealing

 1 files changed, 29 insertions(+), 0 deletions(-)
#868583 arch.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~tsdh/public-inbox/patches/36359/mbox | git am -3
Learn more about email & git

[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.
---
 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,
    /// 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(_) => {
            ()
        }
    }
}

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));
}

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,