Skip to content

Commit

Permalink
[awm2] Initial support for window dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
codyd51 committed Nov 27, 2022
1 parent 0062381 commit eca9f49
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions rust_programs/awm2/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down

0 comments on commit eca9f49

Please sign in to comment.