Skip to content

Commit

Permalink
feat: When drag start, sets window to floating
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCoduriV committed Jul 28, 2024
1 parent ad4b78c commit 48b17a2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 35 deletions.
47 changes: 25 additions & 22 deletions packages/wm/src/common/events/handle_window_moved_end.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
use std::{collections::VecDeque, io::Split};

use anyhow::Context;
use tracing::{debug, info};
use windows::Win32::{Foundation, UI::WindowsAndMessaging::GetCursorPos};
use tracing::info;

use crate::{
common::{
commands::platform_sync,
platform::{MouseMoveEvent, NativeWindow, Platform},
LengthValue, Point, Rect, TilingDirection,
},
common::{platform::Platform, Point, TilingDirection},
containers::{
commands::{
attach_container, detach_container, move_container_within_tree,
},
commands::{attach_container, move_container_within_tree},
traits::{CommonGetters, PositionGetters, TilingDirectionGetters},
Container, SplitContainer, WindowContainer,
Container, SplitContainer,
},
user_config::UserConfig,
windows::{
commands::resize_window, traits::WindowGetters, NonTilingWindow,
TilingWindow,
commands::update_window_state, traits::WindowGetters, NonTilingWindow,
TilingWindow, WindowState,
},
wm_event::WmEvent,
wm_state::WmState,
};

/// Handles window move events
pub fn window_moved_end(
moved_window: TilingWindow,
moved_window: NonTilingWindow,
state: &mut WmState,
config: &UserConfig,
) -> anyhow::Result<()> {
info!("Tiling window moved");
info!("Tiling window moved end");

let workspace = moved_window
.workspace()
Expand Down Expand Up @@ -118,18 +108,15 @@ pub fn window_moved_end(
}
_ => {}
}

state.pending_sync.containers_to_redraw.push(parent);

// info!("{:#?}", workspace);

Ok(())
}

fn move_window_to_target(
state: &mut WmState,
config: &UserConfig,
moved_window: TilingWindow,
moved_window: NonTilingWindow,
target_window: TilingWindow,
target_window_parent: &Container,
current_tiling_direction: TilingDirection,
Expand All @@ -148,6 +135,22 @@ fn move_window_to_target(
})
.context("Window index not found")?;

update_window_state(
moved_window.as_window_container().unwrap(),
WindowState::Tiling,
state,
config,
)?;

let moved_window = state
.windows()
.iter()
.find(|w| w.id() == moved_window.id())
.context("couldn't find the new tiled window")?
.as_tiling_window()
.context("window is not a tiled window")?
.clone();

match (new_tiling_direction, current_tiling_direction) {
(TilingDirection::Horizontal, TilingDirection::Horizontal)
| (TilingDirection::Vertical, TilingDirection::Vertical) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ pub fn handle_window_moved_or_resized_end(
config: &UserConfig,
) -> anyhow::Result<()> {
let found_window = state.window_from_native(&native_window);
info!("{:#?}", found_window);

if let Some(WindowContainer::TilingWindow(window)) = found_window {
if let Some(WindowContainer::NonTilingWindow(window)) = found_window {
// TODO: Log window details.

let parent = window.parent().context("No parent.")?;
Expand All @@ -61,17 +62,34 @@ pub fn handle_window_moved_or_resized_end(
_ => false,
};

return match has_window_moved {
true => window_moved_end(window, state, config),
false => window_resized_start(window, state, width_delta, height_delta),
};
if has_window_moved {
window_moved_end(window, state, config)?;
}
} else if let Some(WindowContainer::TilingWindow(window)) = found_window
{
let parent = window.parent().context("No parent.")?;

// Snap window to its original position if it's the only window in the
// workspace.
if parent.is_workspace() && window.tiling_siblings().count() == 0 {
state.pending_sync.containers_to_redraw.push(window.into());
return Ok(());
}

let new_rect = window.native().refresh_frame_position()?;
let old_rect = window.to_rect()?;

let width_delta = new_rect.width() - old_rect.width();
let height_delta = new_rect.height() - old_rect.height();

window_resized_end(window, state, width_delta, height_delta)?;
}

Ok(())
}

/// Handles window resize events
fn window_resized_start(
fn window_resized_end(
window: TilingWindow,
state: &mut WmState,
width_delta: i32,
Expand Down
31 changes: 24 additions & 7 deletions packages/wm/src/common/events/handle_window_moved_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ use windows::Win32::{Foundation, UI::WindowsAndMessaging::GetCursorPos};
use crate::{
common::{
commands::platform_sync,
LengthValue,
platform::{MouseMoveEvent, NativeWindow, Platform}, Point, Rect, TilingDirection,
platform::{MouseMoveEvent, NativeWindow, Platform},
LengthValue, Point, Rect, TilingDirection,
},
containers::{
commands::{
attach_container, detach_container, move_container_within_tree,
},
Container,
SplitContainer, traits::{CommonGetters, PositionGetters, TilingDirectionGetters}, WindowContainer,
traits::{CommonGetters, PositionGetters, TilingDirectionGetters},
Container, SplitContainer, WindowContainer,
},
user_config::UserConfig,
user_config::{FloatingStateConfig, UserConfig},
windows::{
commands::resize_window, NonTilingWindow, TilingWindow,
commands::{resize_window, update_window_state},
traits::WindowGetters,
NonTilingWindow, TilingWindow, WindowState,
},
wm_event::WmEvent,
wm_state::WmState,
Expand All @@ -32,6 +33,22 @@ pub fn window_moved_start(
state: &mut WmState,
config: &UserConfig,
) -> anyhow::Result<()> {
info!("Tiling window move start");
info!("Tiling window moved start");
let moved_window_parent = moved_window
.parent()
.context("Tiling window has no parent")?;
update_window_state(
moved_window.as_window_container().unwrap(),
WindowState::Floating(FloatingStateConfig {
centered: true,
shown_on_top: true,
}),
state,
config,
)?;
state
.pending_sync
.containers_to_redraw
.push(moved_window_parent);
Ok(())
}

0 comments on commit 48b17a2

Please sign in to comment.