mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 22:31:30 +11:00
Add MouseEntered/MouseLeft for Windows, X11, Wayland, & Cocoa
This commit is contained in:
parent
705f5f50fa
commit
db45e58390
|
@ -397,9 +397,9 @@ impl wl_pointer::Handler for WaylandEnv {
|
||||||
if window.equals(surface) {
|
if window.equals(surface) {
|
||||||
self.mouse_focus = Some(eviter.clone());
|
self.mouse_focus = Some(eviter.clone());
|
||||||
let (w, h) = self.mouse_location;
|
let (w, h) = self.mouse_location;
|
||||||
eviter.lock().unwrap().push_back(
|
let mut event_queue = eviter.lock().unwrap();
|
||||||
Event::MouseMoved(w, h)
|
event_queue.push_back(Event::MouseEntered);
|
||||||
);
|
event_queue.push_back(Event::MouseMoved(w, h));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -409,9 +409,16 @@ impl wl_pointer::Handler for WaylandEnv {
|
||||||
_evqh: &mut EventQueueHandle,
|
_evqh: &mut EventQueueHandle,
|
||||||
_proxy: &wl_pointer::WlPointer,
|
_proxy: &wl_pointer::WlPointer,
|
||||||
_serial: u32,
|
_serial: u32,
|
||||||
_surface: &wl_surface::WlSurface)
|
surface: &wl_surface::WlSurface)
|
||||||
{
|
{
|
||||||
self.mouse_focus = None
|
self.mouse_focus = None;
|
||||||
|
for &(ref window, ref eviter) in &self.windows {
|
||||||
|
if window.equals(surface) {
|
||||||
|
let mut event_queue = eviter.lock().unwrap();
|
||||||
|
event_queue.push_back(Event::MouseLeft);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn motion(&mut self,
|
fn motion(&mut self,
|
||||||
|
|
|
@ -170,7 +170,7 @@ impl XInputEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn translate_event(&mut self, cookie: &ffi::XGenericEventCookie) -> Option<Event> {
|
pub fn translate_event(&mut self, cookie: &ffi::XGenericEventCookie) -> Option<Event> {
|
||||||
use events::Event::{Focused, MouseInput, MouseMoved, MouseWheel};
|
use events::Event::{Focused, MouseEntered, MouseInput, MouseLeft, MouseMoved, MouseWheel};
|
||||||
use events::ElementState::{Pressed, Released};
|
use events::ElementState::{Pressed, Released};
|
||||||
use events::MouseButton::{Left, Right, Middle};
|
use events::MouseButton::{Left, Right, Middle};
|
||||||
use events::MouseScrollDelta::LineDelta;
|
use events::MouseScrollDelta::LineDelta;
|
||||||
|
@ -254,9 +254,9 @@ impl XInputEventHandler {
|
||||||
// our window however, so clear the previous axis state whenever
|
// our window however, so clear the previous axis state whenever
|
||||||
// the cursor re-enters the window
|
// the cursor re-enters the window
|
||||||
self.current_state.axis_values.clear();
|
self.current_state.axis_values.clear();
|
||||||
None
|
Some(MouseEntered)
|
||||||
},
|
},
|
||||||
ffi::XI_Leave => None,
|
ffi::XI_Leave => Some(MouseLeft),
|
||||||
ffi::XI_FocusIn => Some(Focused(true)),
|
ffi::XI_FocusIn => Some(Focused(true)),
|
||||||
ffi::XI_FocusOut => Some(Focused(false)),
|
ffi::XI_FocusOut => Some(Focused(false)),
|
||||||
ffi::XI_TouchBegin | ffi::XI_TouchUpdate | ffi::XI_TouchEnd => {
|
ffi::XI_TouchBegin | ffi::XI_TouchUpdate | ffi::XI_TouchEnd => {
|
||||||
|
|
|
@ -30,6 +30,12 @@ pub enum Event {
|
||||||
/// The parameter are the (x,y) coords in pixels relative to the top-left corner of the window.
|
/// The parameter are the (x,y) coords in pixels relative to the top-left corner of the window.
|
||||||
MouseMoved(i32, i32),
|
MouseMoved(i32, i32),
|
||||||
|
|
||||||
|
/// The cursor has entered the window.
|
||||||
|
MouseEntered,
|
||||||
|
|
||||||
|
/// The cursor has left the window.
|
||||||
|
MouseLeft,
|
||||||
|
|
||||||
/// A mouse wheel movement or touchpad scroll occurred.
|
/// A mouse wheel movement or touchpad scroll occurred.
|
||||||
MouseWheel(MouseScrollDelta, TouchPhase),
|
MouseWheel(MouseScrollDelta, TouchPhase),
|
||||||
|
|
||||||
|
|
|
@ -683,6 +683,8 @@ unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option<Event> {
|
||||||
appkit::NSLeftMouseUp => { Some(Event::MouseInput(ElementState::Released, MouseButton::Left)) },
|
appkit::NSLeftMouseUp => { Some(Event::MouseInput(ElementState::Released, MouseButton::Left)) },
|
||||||
appkit::NSRightMouseDown => { Some(Event::MouseInput(ElementState::Pressed, MouseButton::Right)) },
|
appkit::NSRightMouseDown => { Some(Event::MouseInput(ElementState::Pressed, MouseButton::Right)) },
|
||||||
appkit::NSRightMouseUp => { Some(Event::MouseInput(ElementState::Released, MouseButton::Right)) },
|
appkit::NSRightMouseUp => { Some(Event::MouseInput(ElementState::Released, MouseButton::Right)) },
|
||||||
|
appkit::NSMouseEntered => { Some(Event::MouseEntered) },
|
||||||
|
appkit::NSMouseExited => { Some(Event::MouseLeft) },
|
||||||
appkit::NSMouseMoved |
|
appkit::NSMouseMoved |
|
||||||
appkit::NSLeftMouseDragged |
|
appkit::NSLeftMouseDragged |
|
||||||
appkit::NSOtherMouseDragged |
|
appkit::NSOtherMouseDragged |
|
||||||
|
|
|
@ -125,11 +125,14 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
|
||||||
}
|
}
|
||||||
|
|
||||||
winapi::WM_MOUSEMOVE => {
|
winapi::WM_MOUSEMOVE => {
|
||||||
use events::Event::MouseMoved;
|
use events::Event::{MouseEntered, MouseMoved};
|
||||||
CONTEXT_STASH.with(|context_stash| {
|
CONTEXT_STASH.with(|context_stash| {
|
||||||
let mut context_stash = context_stash.borrow_mut();
|
let mut context_stash = context_stash.borrow_mut();
|
||||||
if let Some(context_stash) = context_stash.as_mut() {
|
if let Some(context_stash) = context_stash.as_mut() {
|
||||||
context_stash.mouse_in_window = true;
|
if !context_stash.mouse_in_window {
|
||||||
|
send_event(window, MouseEntered);
|
||||||
|
context_stash.mouse_in_window = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -142,10 +145,14 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
|
||||||
},
|
},
|
||||||
|
|
||||||
winapi::WM_MOUSELEAVE => {
|
winapi::WM_MOUSELEAVE => {
|
||||||
|
use events::Event::MouseLeft;
|
||||||
CONTEXT_STASH.with(|context_stash| {
|
CONTEXT_STASH.with(|context_stash| {
|
||||||
let mut context_stash = context_stash.borrow_mut();
|
let mut context_stash = context_stash.borrow_mut();
|
||||||
if let Some(context_stash) = context_stash.as_mut() {
|
if let Some(context_stash) = context_stash.as_mut() {
|
||||||
context_stash.mouse_in_window = false;
|
if context_stash.mouse_in_window {
|
||||||
|
send_event(window, MouseLeft);
|
||||||
|
context_stash.mouse_in_window = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue