Skip to content

Commit

Permalink
fix: bug of moving window when alone in split
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCoduriV committed Jul 30, 2024
1 parent 3ef0155 commit 1414229
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
17 changes: 10 additions & 7 deletions packages/wm/src/common/events/handle_window_moved_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{
wm_state::WmState,
};
use crate::containers::commands::detach_container;
use crate::containers::RootContainer;
use crate::user_config::FloatingStateConfig;
use crate::workspaces::Workspace;

Expand All @@ -36,13 +37,11 @@ pub fn window_moved_end(
}
info!("Tiling window drag end event");

let workspace = moved_window
.workspace()
.context("Couldn't find a workspace")?;
let root_container = state.root_container.clone();

let mouse_position = Platform::mouse_position()?;

let window_under_cursor = match get_window_at_mouse_pos(&moved_window, workspace, &mouse_position) {
let window_under_cursor = match get_tiling_window_at_mouse_pos(&moved_window, root_container, &mouse_position) {
Some(value) => value,
None => return Ok(()),
};
Expand Down Expand Up @@ -107,8 +106,8 @@ pub fn window_moved_end(
}

/// Return the window under the mouse position excluding the dragged window
fn get_window_at_mouse_pos(exclude_window: &NonTilingWindow, workspace: Workspace, mouse_position: &Point) -> Option<TilingWindow> {
let children_at_mouse_position: Vec<_> = workspace
fn get_tiling_window_at_mouse_pos(exclude_window: &NonTilingWindow, root_container: RootContainer, mouse_position: &Point) -> Option<TilingWindow> {
let children_at_mouse_position: Vec<_> = root_container
.descendants()
.filter_map(|container| match container {
Container::TilingWindow(tiling) => Some(tiling),
Expand Down Expand Up @@ -141,9 +140,13 @@ fn move_window_to_target(

// TODO: We can optimize that for sure by not detaching and attaching the window
// Little trick to get the right index
let test_parent = moved_window.parent().unwrap();
dbg!(&test_parent);
detach_container(Container::NonTilingWindow(moved_window.clone()))?;
dbg!(&test_parent);
let target_window_index = target_window.index();
attach_container(&Container::NonTilingWindow(moved_window.clone()), target_window_parent, None)?;
dbg!(&test_parent);

let target_index = match new_window_position {
DropPosition::Start => target_window_index,
Expand Down Expand Up @@ -252,7 +255,7 @@ enum DropPosition {
}

/// Returns the closest position of the mouse over the window
///
///
/// Example: Mouse x pos: 3, Window width: 5, Result: [DropPosition::End]
fn get_new_window_position(
mouse_position: &Point,
Expand Down
19 changes: 18 additions & 1 deletion packages/wm/src/common/events/handle_window_moved_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ use anyhow::Context;
use tracing::info;

use crate::{
containers::traits::CommonGetters,
containers::{
commands::{attach_container, detach_container},
traits::CommonGetters,
Container,
},
user_config::{FloatingStateConfig, UserConfig},
windows::{commands::update_window_state, TilingWindow, WindowState},
wm_state::WmState,
Expand All @@ -19,6 +23,19 @@ pub fn window_moved_start(
.parent()
.context("Tiling window has no parent")?;

if let Some(Container::Split(split)) = moved_window.parent() {
if split.child_count() == 1 {
let split_parent = split.parent().unwrap();
let split_index = split.index();
detach_container(Container::TilingWindow(moved_window.clone()))?;
attach_container(
&Container::TilingWindow(moved_window.clone()),
&split_parent,
Some(split_index),
)?;
}
}

update_window_state(
moved_window.as_window_container().unwrap(),
WindowState::Floating(FloatingStateConfig {
Expand Down

0 comments on commit 1414229

Please sign in to comment.