From eca9f4919dc2683500be64fca5287bf3d28c63c2 Mon Sep 17 00:00:00 2001 From: Phillip Tennen Date: Sun, 27 Nov 2022 12:53:11 +0000 Subject: [PATCH] [awm2] Initial support for window dragging --- rust_programs/awm2/src/desktop.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/rust_programs/awm2/src/desktop.rs b/rust_programs/awm2/src/desktop.rs index a1b1206fe..59f087544 100644 --- a/rust_programs/awm2/src/desktop.rs +++ b/rust_programs/awm2/src/desktop.rs @@ -668,13 +668,43 @@ impl Desktop { //println!("Mouse state change: {state_change:?}"); match state_change { MouseStateChange::LeftClickBegan => { + self.interaction_state.dragged_window = + self.interaction_state.window_under_mouse.clone(); } MouseStateChange::LeftClickEnded => { + if self.interaction_state.dragged_window.is_some() { + println!("Releasing dragged window"); + self.interaction_state.dragged_window = None; + } } MouseStateChange::Moved(new_pos, rel_pos) => { // Check whether we've entered a hover window self.interaction_state.window_under_mouse = self.window_containing_point(*new_pos); + /* + println!( + "Set window under mouse? {}", + self.interaction_state.window_under_mouse.is_some() + ); + */ + + let mut prev_frame = None; + let mut new_frame = None; + if let Some(dragged_window) = &self.interaction_state.dragged_window { + //println!("Dragged window moved {}", dragged_window.name()); + //dragged_window.frame.origin = dragged_window.frame.origin + *rel_pos; + prev_frame = Some(dragged_window.frame()); + new_frame = Some(Rect::from_parts( + dragged_window.frame().origin + *rel_pos, + dragged_window.frame().size, + )); + dragged_window.set_frame(new_frame.unwrap()); + } + if new_frame.is_some() { + let total_update_region = prev_frame.unwrap().union(new_frame.unwrap()); + self.recompute_drawable_regions_in_rect(total_update_region); + self.compositor_state.queue_full_redraw(total_update_region); + } } } }