Simplifications and bugfixes discovered when writing tests

This commit is contained in:
Skia 2025-03-24 20:15:21 +01:00
parent 3f61dbda90
commit a8a80eb514

View file

@ -371,58 +371,33 @@ impl SwaySome {
}
fn focus_to_workspace_absolute(&self, workspace_index: usize) {
let output_index = (workspace_index / MAX_GROUP_WS) as usize;
// If the workspace already exists
match self.workspaces.iter().find(|w| w.num == workspace_index) {
Some(_) => {
let mut focus_cmd: String = "workspace number ".to_string();
focus_cmd.push_str(&workspace_index.to_string());
self.send_command(&focus_cmd);
}
None => {
let target_group = workspace_index / MAX_GROUP_WS;
let target_screen_index = match self
.workspaces
let target_group = workspace_index / MAX_GROUP_WS;
match self
.workspaces
.iter()
.find(|w| w.num / MAX_GROUP_WS == target_group)
{
// If other workspaces on the same group exists
Some(other_workspace) => {
// find the corresponding output and focus it
let target_output = self
.outputs
.iter()
.find(|w| w.num / MAX_GROUP_WS == target_group)
{
// If other workspaces on the same group exists
Some(other_workspace) => Some(
self.outputs
.iter()
.enumerate()
.find(|i| i.1.name == other_workspace.output)
.unwrap()
.0,
),
None => {
// Or if the targeted output is currently connected
if output_index < self.outputs.len() {
Some(output_index)
} else {
None
}
}
};
match target_screen_index {
// If we have to send it to another screen
Some(target_screen_index) => {
let target_output = &self.outputs[target_screen_index - 1];
let mut focus_cmd: String = "focus output ".to_string();
focus_cmd.push_str(&target_output.name);
self.send_command(&focus_cmd);
}
None => {}
};
// Then we focus the workspace
let mut focus_cmd: String = "workspace number ".to_string();
focus_cmd.push_str(&workspace_index.to_string());
.enumerate()
.find(|i| i.1.name == other_workspace.output)
.unwrap()
.1;
let mut focus_cmd: String = "focus output ".to_string();
focus_cmd.push_str(&target_output.name);
self.send_command(&focus_cmd);
}
}
None => {}
};
// Then we focus the workspace
let mut focus_cmd: String = "workspace number ".to_string();
focus_cmd.push_str(&workspace_index.to_string());
self.send_command(&focus_cmd);
}
fn focus_to_workspace_relative(&self, workspace_index: usize) {
@ -644,12 +619,13 @@ impl SwaySome {
focus_cmd.push_str(&workspace.num.to_string());
self.send_command(&focus_cmd);
let group_index = workspace.num / MAX_GROUP_WS;
if group_index <= self.outputs.len() - 1 {
let mut move_cmd = move_cmd_prefix.clone();
move_cmd.push_str(&self.outputs[group_index.max(1) - 1].name);
self.send_command(&move_cmd);
}
let group_index =
(workspace.num / MAX_GROUP_WS + self.outputs.len() - 1) % self.outputs.len();
// if group_index <= self.outputs.len() - 1 {
let mut move_cmd = move_cmd_prefix.clone();
move_cmd.push_str(&self.outputs[group_index].name);
self.send_command(&move_cmd);
// }
}
}
}