Skip to content

Commit

Permalink
refactor: simplified code
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCoduriV committed Jul 31, 2024
1 parent 5c8b85f commit e195c28
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 40 deletions.
36 changes: 13 additions & 23 deletions packages/wm/src/common/events/handle_window_location_changed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ use crate::{
},
user_config::{FloatingStateConfig, FullscreenStateConfig, UserConfig},
windows::{
commands::update_window_state,
traits::WindowGetters,
window_operation::{Operation, WindowOperation},
TilingWindow, WindowState,
commands::update_window_state, traits::WindowGetters,
window_operation::WindowOperation, TilingWindow, WindowState,
},
wm_state::WmState,
};
Expand Down Expand Up @@ -150,8 +148,9 @@ pub fn handle_window_location_changed(

/// Updates the window operation based on changes in frame position.
///
/// This function determines whether a window is being moved or resized and updates its
/// operation state accordingly. If the window is being moved, it's set to floating mode.
/// This function determines whether a window is being moved or resized and
/// updates its operation state accordingly. If the window is being moved,
/// it's set to floating mode.
fn update_window_operation(
state: &mut WmState,
config: &UserConfig,
Expand All @@ -161,35 +160,26 @@ fn update_window_operation(
) -> anyhow::Result<()> {
if let Some(tiling_window) = window.as_tiling_window() {
let window_operation = window.window_operation();
if matches!(
window_operation,
WindowOperation {
operation: Operation::Waiting,
}
) {
if window_operation == WindowOperation::Waiting {
if frame_position.height() == old_frame_position.height()
&& frame_position.width() == old_frame_position.width()
{
window.set_window_operation(WindowOperation {
operation: Operation::Moving,
..window_operation
});
window.set_window_operation(WindowOperation::Moving);
set_into_floating(tiling_window.clone(), state, config)?;
} else {
window.set_window_operation(WindowOperation {
operation: Operation::Resizing,
..window_operation
});
window.set_window_operation(WindowOperation::Resizing);
}
}
}
Ok(())
}

/// Converts a tiling window to a floating window and updates the window hierarchy.
/// Converts a tiling window to a floating window and updates the window
/// hierarchy.
///
/// This function handles the process of transitioning a tiling window to a floating state,
/// including necessary adjustments to the window hierarchy and updating the window's state.
/// This function handles the process of transitioning a tiling window to a
/// floating state, including necessary adjustments to the window hierarchy
/// and updating the window's state.
fn set_into_floating(
moved_window: TilingWindow,
state: &mut WmState,
Expand Down
4 changes: 2 additions & 2 deletions packages/wm/src/common/events/handle_window_moved_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
windows::{
commands::update_window_state,
traits::WindowGetters,
window_operation::{Operation, WindowOperation},
window_operation::{WindowOperation},
NonTilingWindow, TilingWindow, WindowState,
},
wm_state::WmState,
Expand All @@ -35,7 +35,7 @@ pub fn window_moved_end(
is_tiling_drag: false,
..
})
) || moved_window.window_operation().operation != Operation::Moving
) || moved_window.window_operation() != WindowOperation::Moving
{
moved_window.set_window_operation(WindowOperation::default());
return Ok(());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ pub fn handle_window_moved_or_resized_end(
let height_delta = new_rect.height() - old_rect.height();

if let WindowContainer::NonTilingWindow(window) = window {
let has_window_moved = match (width_delta, height_delta) {
(0, 0) => true,
_ => false,
};
let has_window_moved = matches!((width_delta, height_delta), (0,0));

if has_window_moved {
window_moved_end(window, state, config)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
containers::WindowContainer,
windows::{
traits::WindowGetters,
window_operation::{Operation, WindowOperation},
window_operation::{WindowOperation},
},
wm_state::WmState,
};
Expand All @@ -17,9 +17,7 @@ pub fn handle_window_moved_or_resized_start(
let found_window = state.window_from_native(&native_window);

if let Some(WindowContainer::TilingWindow(moved_window)) = found_window {
moved_window.set_window_operation(WindowOperation {
operation: Operation::Waiting,
});
moved_window.set_window_operation(WindowOperation::Waiting);
}

Ok(())
Expand Down
8 changes: 1 addition & 7 deletions packages/wm/src/windows/window_operation.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#[derive(Debug, Clone, Default)]
pub struct WindowOperation{
pub operation: Operation,

}

#[derive(Debug, Copy, Clone, Default, PartialEq)]
pub enum Operation{
pub enum WindowOperation{
#[default]
None,
Waiting,
Expand Down

0 comments on commit e195c28

Please sign in to comment.