Finished workspace groups
This commit is contained in:
parent
286760ade6
commit
b6f81aa7bb
1 changed files with 82 additions and 31 deletions
113
src/main.rs
113
src/main.rs
|
|
@ -29,17 +29,17 @@ struct Cli {
|
||||||
|
|
||||||
#[derive(Subcommand, Debug)]
|
#[derive(Subcommand, Debug)]
|
||||||
enum Command {
|
enum Command {
|
||||||
#[clap(about = "Initialize the workspaces for all the outputs")]
|
#[clap(about = "Initialize the workspace groups for all the outputs")]
|
||||||
Init(InitAction),
|
Init(InitAction),
|
||||||
|
|
||||||
#[clap(about = "Move the focused container to another workspace on the same output")]
|
#[clap(about = "Move the focused container to another workspace on the same workspace group")]
|
||||||
Move(MoveAction),
|
Move(MoveAction),
|
||||||
|
|
||||||
#[clap(about = "Focus to another workspace on the same output")]
|
#[clap(about = "Focus to another workspace on the same workspace group")]
|
||||||
Focus(FocusAction),
|
Focus(FocusAction),
|
||||||
|
|
||||||
#[clap(about = "Focus to output")]
|
#[clap(about = "Focus to workspace group")]
|
||||||
FocusOutput(FocusAction),
|
FocusGroup(FocusAction),
|
||||||
|
|
||||||
#[clap(about = "Focus to another workspace on all the outputs")]
|
#[clap(about = "Focus to another workspace on all the outputs")]
|
||||||
FocusAllOutputs(FocusAction),
|
FocusAllOutputs(FocusAction),
|
||||||
|
|
@ -231,12 +231,7 @@ fn get_current_workspace(stream: &UnixStream) -> Workspace {
|
||||||
|
|
||||||
fn move_container_to_workspace(stream: &UnixStream, workspace_index: usize) {
|
fn move_container_to_workspace(stream: &UnixStream, workspace_index: usize) {
|
||||||
if workspace_index < 10 {
|
if workspace_index < 10 {
|
||||||
let mut cmd: String = "move container to workspace number ".to_string();
|
move_container_to_workspace_relative(stream, workspace_index);
|
||||||
let full_ws_name = format!("{}{}", get_current_output_index(stream), workspace_index)
|
|
||||||
.parse::<i32>()
|
|
||||||
.unwrap();
|
|
||||||
cmd.push_str(&full_ws_name.to_string());
|
|
||||||
send_command(stream, &cmd);
|
|
||||||
} else {
|
} else {
|
||||||
move_container_to_workspace_absolute(stream, workspace_index);
|
move_container_to_workspace_absolute(stream, workspace_index);
|
||||||
}
|
}
|
||||||
|
|
@ -324,14 +319,21 @@ fn move_container_to_workspace_absolute(stream: &UnixStream, workspace_index: us
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn move_container_to_workspace_relative(stream: &UnixStream, workspace_index: usize) {
|
||||||
|
let current_workspace_index: usize = get_current_workspace(stream).num;
|
||||||
|
let focused_output_index = current_workspace_index / 10;
|
||||||
|
|
||||||
|
let mut cmd: String = "move container to workspace number ".to_string();
|
||||||
|
let full_ws_name = format!("{}{}", focused_output_index, workspace_index)
|
||||||
|
.parse::<i32>()
|
||||||
|
.unwrap();
|
||||||
|
cmd.push_str(&full_ws_name.to_string());
|
||||||
|
send_command(stream, &cmd);
|
||||||
|
}
|
||||||
|
|
||||||
fn focus_to_workspace(stream: &UnixStream, workspace_index: usize) {
|
fn focus_to_workspace(stream: &UnixStream, workspace_index: usize) {
|
||||||
if workspace_index < 10 {
|
if workspace_index < 10 {
|
||||||
let mut cmd: String = "workspace number ".to_string();
|
focus_to_workspace_relative(stream, workspace_index);
|
||||||
let full_ws_name = format!("{}{}", get_current_output_index(stream), &workspace_index)
|
|
||||||
.parse::<i32>()
|
|
||||||
.unwrap();
|
|
||||||
cmd.push_str(&full_ws_name.to_string());
|
|
||||||
send_command(stream, &cmd);
|
|
||||||
} else {
|
} else {
|
||||||
focus_to_workspace_absolute(stream, workspace_index);
|
focus_to_workspace_absolute(stream, workspace_index);
|
||||||
}
|
}
|
||||||
|
|
@ -390,7 +392,7 @@ fn focus_to_workspace_absolute(stream: &UnixStream, workspace_index: usize) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn focus_to_workspace_virtual_output(stream: &UnixStream, workspace_index: usize) {
|
fn focus_to_workspace_relative(stream: &UnixStream, workspace_index: usize) {
|
||||||
let current_workspace_index: usize = get_current_workspace(stream).num;
|
let current_workspace_index: usize = get_current_workspace(stream).num;
|
||||||
let focused_output_index = current_workspace_index / 10;
|
let focused_output_index = current_workspace_index / 10;
|
||||||
|
|
||||||
|
|
@ -402,17 +404,60 @@ fn focus_to_workspace_virtual_output(stream: &UnixStream, workspace_index: usize
|
||||||
send_command(stream, &cmd);
|
send_command(stream, &cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn focus_to_output(stream: &UnixStream, target_output_index: usize) {
|
fn focus_to_group(stream: &UnixStream, group_index: usize) {
|
||||||
let outputs = get_outputs(stream);
|
let outputs = get_outputs(stream);
|
||||||
if target_output_index < outputs.len() {
|
let workspaces = get_workspaces(stream);
|
||||||
let mut cmd: String = "focus output ".to_string();
|
|
||||||
cmd.push_str(&outputs[target_output_index - 1].name);
|
let current_workspace_index: usize = get_current_workspace(stream).num;
|
||||||
send_command(stream, &cmd);
|
let contextual_target_workspace_index =
|
||||||
} else {
|
current_workspace_index - (current_workspace_index / 10) * 10;
|
||||||
let current_workspace_index = get_current_workspace(stream).num;
|
|
||||||
let contextual_workspace_index =
|
let target_workspace_index = group_index * 10 + contextual_target_workspace_index;
|
||||||
current_workspace_index - (current_workspace_index / 10) * 10;
|
|
||||||
focus_to_workspace_virtual_output(stream, contextual_workspace_index);
|
// If the workspace already exists
|
||||||
|
match workspaces.iter().find(|w| w.num == target_workspace_index) {
|
||||||
|
Some(_) => {
|
||||||
|
let mut focus_cmd: String = "workspace number ".to_string();
|
||||||
|
focus_cmd.push_str(&target_workspace_index.to_string());
|
||||||
|
send_command(stream, &focus_cmd);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let target_screen_index = match workspaces.iter().find(|w| w.num / 10 == group_index) {
|
||||||
|
// If other workspaces on the same group exists
|
||||||
|
Some(other_workspace) => Some(
|
||||||
|
outputs
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.find(|i| i.1.name == other_workspace.output)
|
||||||
|
.unwrap()
|
||||||
|
.0,
|
||||||
|
),
|
||||||
|
None => {
|
||||||
|
// Or if the targeted output is currently connected
|
||||||
|
if group_index < outputs.len() {
|
||||||
|
Some(group_index)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match target_screen_index {
|
||||||
|
// If we have to send it to another screen
|
||||||
|
Some(target_screen_index) => {
|
||||||
|
let target_output = &outputs[target_screen_index];
|
||||||
|
|
||||||
|
let mut focus_cmd: String = "focus output ".to_string();
|
||||||
|
focus_cmd.push_str(&target_output.name);
|
||||||
|
send_command(stream, &focus_cmd);
|
||||||
|
}
|
||||||
|
None => {}
|
||||||
|
};
|
||||||
|
// Then we focus the workspace
|
||||||
|
let mut focus_cmd: String = "workspace number ".to_string();
|
||||||
|
focus_cmd.push_str(&target_workspace_index.to_string());
|
||||||
|
send_command(stream, &focus_cmd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -515,7 +560,13 @@ fn init_workspaces(stream: &UnixStream, workspace_index: usize) {
|
||||||
cmd.push_str(output.name.as_str());
|
cmd.push_str(output.name.as_str());
|
||||||
println!("{:?}", cmd.clone());
|
println!("{:?}", cmd.clone());
|
||||||
send_command(stream, &cmd);
|
send_command(stream, &cmd);
|
||||||
focus_to_workspace(stream, workspace_index);
|
|
||||||
|
let mut cmd: String = "workspace number ".to_string();
|
||||||
|
let full_ws_name = format!("{}{}", get_current_output_index(stream), &workspace_index)
|
||||||
|
.parse::<i32>()
|
||||||
|
.unwrap();
|
||||||
|
cmd.push_str(&full_ws_name.to_string());
|
||||||
|
send_command(stream, &cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -553,8 +604,8 @@ fn main() {
|
||||||
Command::Focus(action) => {
|
Command::Focus(action) => {
|
||||||
focus_to_workspace(&stream, action.index);
|
focus_to_workspace(&stream, action.index);
|
||||||
}
|
}
|
||||||
Command::FocusOutput(action) => {
|
Command::FocusGroup(action) => {
|
||||||
focus_to_output(&stream, action.index);
|
focus_to_group(&stream, action.index);
|
||||||
}
|
}
|
||||||
Command::FocusAllOutputs(action) => {
|
Command::FocusAllOutputs(action) => {
|
||||||
focus_all_outputs_to_workspace(&stream, action.index);
|
focus_all_outputs_to_workspace(&stream, action.index);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue