mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 14:21:31 +11:00
Merge pull request #81 from AndyBarron/master
Add MouseEntered/MouseLeft for Windows, X11, Wayland, & Cocoa
This commit is contained in:
commit
1caa499f59
|
@ -397,9 +397,9 @@ impl wl_pointer::Handler for WaylandEnv {
|
|||
if window.equals(surface) {
|
||||
self.mouse_focus = Some(eviter.clone());
|
||||
let (w, h) = self.mouse_location;
|
||||
eviter.lock().unwrap().push_back(
|
||||
Event::MouseMoved(w, h)
|
||||
);
|
||||
let mut event_queue = eviter.lock().unwrap();
|
||||
event_queue.push_back(Event::MouseEntered);
|
||||
event_queue.push_back(Event::MouseMoved(w, h));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -409,9 +409,16 @@ impl wl_pointer::Handler for WaylandEnv {
|
|||
_evqh: &mut EventQueueHandle,
|
||||
_proxy: &wl_pointer::WlPointer,
|
||||
_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,
|
||||
|
|
|
@ -170,7 +170,7 @@ impl XInputEventHandler {
|
|||
}
|
||||
|
||||
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::MouseButton::{Left, Right, Middle};
|
||||
use events::MouseScrollDelta::LineDelta;
|
||||
|
@ -254,9 +254,9 @@ impl XInputEventHandler {
|
|||
// our window however, so clear the previous axis state whenever
|
||||
// the cursor re-enters the window
|
||||
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_FocusOut => Some(Focused(false)),
|
||||
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.
|
||||
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.
|
||||
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::NSRightMouseDown => { Some(Event::MouseInput(ElementState::Pressed, MouseButton::Right)) },
|
||||
appkit::NSRightMouseUp => { Some(Event::MouseInput(ElementState::Released, MouseButton::Right)) },
|
||||
appkit::NSMouseEntered => { Some(Event::MouseEntered) },
|
||||
appkit::NSMouseExited => { Some(Event::MouseLeft) },
|
||||
appkit::NSMouseMoved |
|
||||
appkit::NSLeftMouseDragged |
|
||||
appkit::NSOtherMouseDragged |
|
||||
|
|
|
@ -125,12 +125,15 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
|
|||
}
|
||||
|
||||
winapi::WM_MOUSEMOVE => {
|
||||
use events::Event::MouseMoved;
|
||||
use events::Event::{MouseEntered, MouseMoved};
|
||||
CONTEXT_STASH.with(|context_stash| {
|
||||
let mut context_stash = context_stash.borrow_mut();
|
||||
if let Some(context_stash) = context_stash.as_mut() {
|
||||
if !context_stash.mouse_in_window {
|
||||
send_event(window, MouseEntered);
|
||||
context_stash.mouse_in_window = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let x = winapi::GET_X_LPARAM(lparam) as i32;
|
||||
|
@ -142,11 +145,15 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
|
|||
},
|
||||
|
||||
winapi::WM_MOUSELEAVE => {
|
||||
use events::Event::MouseLeft;
|
||||
CONTEXT_STASH.with(|context_stash| {
|
||||
let mut context_stash = context_stash.borrow_mut();
|
||||
if let Some(context_stash) = context_stash.as_mut() {
|
||||
if context_stash.mouse_in_window {
|
||||
send_event(window, MouseLeft);
|
||||
context_stash.mouse_in_window = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
0
|
||||
|
|
Loading…
Reference in a new issue