From e195c2813a9435c5823ae98f1f433f7b67eb7e53 Mon Sep 17 00:00:00 2001 From: Luca Date: Thu, 1 Aug 2024 00:23:48 +0200 Subject: [PATCH] refactor: simplified code --- .../events/handle_window_location_changed.rs | 36 +++++++------------ .../common/events/handle_window_moved_end.rs | 4 +-- .../handle_window_moved_or_resized_end.rs | 5 +-- .../handle_window_moved_or_resized_start.rs | 6 ++-- packages/wm/src/windows/window_operation.rs | 8 +---- 5 files changed, 19 insertions(+), 40 deletions(-) diff --git a/packages/wm/src/common/events/handle_window_location_changed.rs b/packages/wm/src/common/events/handle_window_location_changed.rs index 62a7487a..af0c085c 100644 --- a/packages/wm/src/common/events/handle_window_location_changed.rs +++ b/packages/wm/src/common/events/handle_window_location_changed.rs @@ -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, }; @@ -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, @@ -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, diff --git a/packages/wm/src/common/events/handle_window_moved_end.rs b/packages/wm/src/common/events/handle_window_moved_end.rs index d3676802..138ec493 100644 --- a/packages/wm/src/common/events/handle_window_moved_end.rs +++ b/packages/wm/src/common/events/handle_window_moved_end.rs @@ -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, @@ -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(()); diff --git a/packages/wm/src/common/events/handle_window_moved_or_resized_end.rs b/packages/wm/src/common/events/handle_window_moved_or_resized_end.rs index 31115e1e..869ec648 100644 --- a/packages/wm/src/common/events/handle_window_moved_or_resized_end.rs +++ b/packages/wm/src/common/events/handle_window_moved_or_resized_end.rs @@ -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)?; diff --git a/packages/wm/src/common/events/handle_window_moved_or_resized_start.rs b/packages/wm/src/common/events/handle_window_moved_or_resized_start.rs index bf3ba699..69f12803 100644 --- a/packages/wm/src/common/events/handle_window_moved_or_resized_start.rs +++ b/packages/wm/src/common/events/handle_window_moved_or_resized_start.rs @@ -3,7 +3,7 @@ use crate::{ containers::WindowContainer, windows::{ traits::WindowGetters, - window_operation::{Operation, WindowOperation}, + window_operation::{WindowOperation}, }, wm_state::WmState, }; @@ -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(()) diff --git a/packages/wm/src/windows/window_operation.rs b/packages/wm/src/windows/window_operation.rs index 66b405cc..cc469b5b 100644 --- a/packages/wm/src/windows/window_operation.rs +++ b/packages/wm/src/windows/window_operation.rs @@ -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,