changed stuff
This commit is contained in:
Regular → Executable
+46
-17
@@ -42,30 +42,59 @@ async fn main() {
|
||||
.unwrap();
|
||||
|
||||
while let Some(event) = workspace_event_rx.recv().await {
|
||||
let sway_ipc_clone = sway_ipc.clone();
|
||||
|
||||
// Handle the new layout setup
|
||||
let root = sway_ipc_clone.get_tree().await.unwrap();
|
||||
let workspaces = sway_ipc_clone.get_workspaces().await.unwrap();
|
||||
let leaves = get_current_leaves_here(&root, &workspaces);
|
||||
if let SwayEvent::Window(window_event) = event {
|
||||
if let WindowChangeType::New = window_event.change {
|
||||
let sway_ipc_clone = sway_ipc.clone();
|
||||
|
||||
// Handle the new layout setup
|
||||
let root = sway_ipc_clone.get_tree().await.unwrap();
|
||||
let workspaces = sway_ipc_clone.get_workspaces().await.unwrap();
|
||||
let leaves = get_current_leaves_here(&root, &workspaces);
|
||||
|
||||
if let (Some(first), Some(second)) = (leaves.first(), leaves.get(1)) {
|
||||
let mut command = format!("[con_id={}] splith", first.id);
|
||||
match leaves.get(2) {
|
||||
Some(third) => {
|
||||
command = format!(
|
||||
match window_event.change {
|
||||
WindowChangeType::New => {
|
||||
if let (Some(first), Some(second)) = (leaves.first(), leaves.get(1)) {
|
||||
let mut command = format!("[con_id={}] splith", first.id);
|
||||
match leaves.get(2) {
|
||||
Some(third) => {
|
||||
command = format!(
|
||||
"{};[con_id={}] splitv;[con_id={}] mark target;[con_id={}] move container to mark target;[con_id={}] swap container with mark target;",
|
||||
command, second.id, third.id, second.id, second.id
|
||||
);
|
||||
}
|
||||
None => {
|
||||
command = format!("{};[con_id={}] splitv;", command, second.id);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
command = format!("{};[con_id={}] splitv;", command, second.id);
|
||||
}
|
||||
sway_ipc_clone.run_command(command).await.unwrap();
|
||||
}
|
||||
sway_ipc_clone.run_command(command).await.unwrap();
|
||||
}
|
||||
WindowChangeType::Close => {
|
||||
println!("❌ Window closed: ID {}", window_event.container.id);
|
||||
|
||||
if let Some(master) = leaves.first() {
|
||||
println!("🔍 Current Master ID before closing: {}", master.id);
|
||||
} else {
|
||||
println!("⚠️ No Master found in current workspace!");
|
||||
}
|
||||
|
||||
if leaves
|
||||
.first()
|
||||
.map_or(false, |master| master.id == window_event.container.id)
|
||||
{
|
||||
println!("🔥 Master was closed! Promoting next container...");
|
||||
|
||||
let command = "
|
||||
focus right;
|
||||
layout splitv;
|
||||
focus left;
|
||||
move up;
|
||||
layout splith;
|
||||
";
|
||||
sway_ipc_clone.run_command(command.to_string()).await.unwrap();
|
||||
} else {
|
||||
println!("✅ Closed window was NOT the Master. No action needed.");
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Regular → Executable
Reference in New Issue
Block a user