mirror of
https://gitlab.com/hyask/swaysome.git
synced 2026-01-28 02:17:18 +01:00
Allow moving focused container across outputs
This commit is contained in:
parent
776bf3aaf0
commit
e2f59801d0
3 changed files with 50 additions and 2 deletions
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "swaysome"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
authors = ["Skia <skia@hya.sk>"]
|
||||
edition = "2018"
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,12 @@ bindsym $mod+Shift+8 exec "swaysome move 8"
|
|||
bindsym $mod+Shift+9 exec "swaysome move 9"
|
||||
bindsym $mod+Shift+0 exec "swaysome move 0"
|
||||
|
||||
# Move focused container to next output
|
||||
bindsym $mod+o exec "swaysome next_output"
|
||||
|
||||
# Move focused container to previous output
|
||||
bindsym $mod+Shift+o exec "swaysome prev_output"
|
||||
|
||||
# Init workspaces for every screen
|
||||
exec "swaysome init"
|
||||
```
|
||||
|
|
|
|||
44
src/main.rs
44
src/main.rs
|
|
@ -195,6 +195,46 @@ fn focus_to_workspace(stream: &UnixStream, workspace_name: &String) {
|
|||
check_success(&stream);
|
||||
}
|
||||
|
||||
fn move_container_to_next_output(stream: &UnixStream) {
|
||||
move_container_to_next_or_prev_output(&stream, false);
|
||||
}
|
||||
|
||||
fn move_container_to_prev_output(stream: &UnixStream) {
|
||||
move_container_to_next_or_prev_output(&stream, true);
|
||||
}
|
||||
|
||||
fn move_container_to_next_or_prev_output(stream: &UnixStream, go_to_prev: bool) {
|
||||
let outputs = get_outputs(&stream);
|
||||
let focused_output_index = match outputs.iter().position(|x| x.focused) {
|
||||
Some(i) => i,
|
||||
None => panic!("WTF! No focused output???"),
|
||||
};
|
||||
|
||||
let target_output;
|
||||
if go_to_prev {
|
||||
target_output = &outputs[(focused_output_index - 1 + &outputs.len()) % &outputs.len()];
|
||||
} else {
|
||||
target_output = &outputs[(focused_output_index + 1) % &outputs.len()];
|
||||
}
|
||||
|
||||
let workspaces = get_workspaces(&stream);
|
||||
let target_workspace = workspaces.iter()
|
||||
.filter(|x| x.output == target_output.name && x.visible)
|
||||
.next().unwrap();
|
||||
|
||||
// Move container to target workspace
|
||||
let mut cmd: String = "move container to workspace ".to_string();
|
||||
cmd.push_str(&target_workspace.name);
|
||||
send_msg(&stream, RUN_COMMAND, &cmd);
|
||||
check_success(&stream);
|
||||
|
||||
// Focus that workspace to follow the container
|
||||
let mut cmd: String = "workspace ".to_string();
|
||||
cmd.push_str(&target_workspace.name);
|
||||
send_msg(&stream, RUN_COMMAND, &cmd);
|
||||
check_success(&stream);
|
||||
}
|
||||
|
||||
fn init_workspaces(stream: &UnixStream) {
|
||||
let outputs = get_outputs(&stream);
|
||||
|
||||
|
|
@ -214,12 +254,14 @@ fn main() {
|
|||
let args: Vec<String> = env::args().map(|x| x.to_string())
|
||||
.collect();
|
||||
|
||||
let mut stream = get_stream();
|
||||
let stream = get_stream();
|
||||
|
||||
match args[1].as_str() {
|
||||
"init" => init_workspaces(&stream),
|
||||
"move" => move_container_to_workspace(&stream, &args[2]),
|
||||
"focus" => focus_to_workspace(&stream, &args[2]),
|
||||
"next_output" => move_container_to_next_output(&stream),
|
||||
"prev_output" => move_container_to_prev_output(&stream),
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue