From 393d4f309ba238f81d100aae409a784f82d88c15 Mon Sep 17 00:00:00 2001
From: Ben Bridle <ben@derelict.engineering>
Date: Mon, 16 Dec 2024 14:22:33 +1300
Subject: Only send Event::CursorExit when all mouse buttons are released

This is to allow a user to drag an element inside the program window
and for the mouse cursor to move in and out of the window during the
drag operation. This is the intuitive and expected behaviour.
---
 src/window.rs | 12 ++++++++++++
 1 file changed, 12 insertions(+)

(limited to 'src/window.rs')

diff --git a/src/window.rs b/src/window.rs
index 70c9c02..f031af5 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -18,11 +18,21 @@ fn to_physical_size(dimensions: Dimensions, scale: u32) -> PhysicalSize<u32> {
 }
 
 
+#[derive(Copy, Clone, Debug, PartialEq)]
+pub enum PointerState {
+    In,
+    Out,
+    PendingOut,
+}
+
+
 pub(crate) struct PhosphorWindow {
     pub winit: Rc<Window>,
     pub program: Box<dyn WindowProgram>,
     pub requests: EventQueue<Request>,
     pub pointer: Option<Position>,
+    pub pointer_state: PointerState,
+    pub mouse_buttons: [bool; 5],
     pub marked_for_destruction: bool,
     pub size_bounds: SizeBounds,  // logical dimensions
 
@@ -79,6 +89,8 @@ impl PhosphorWindow {
             program: builder.program,
             requests: EventQueue::new(),
             pointer: None,
+            pointer_state: PointerState::Out,
+            mouse_buttons: [false; 5],
             marked_for_destruction: false,
             size_bounds,
 
-- 
cgit v1.2.3-70-g09d2