mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 14:21:31 +11:00
Send mouse position after focused/cursorenter events (#349)
* Update mouse pos after cursor enter event * Update mouse position on windows focus * Send device_id * Update other device id * Fix windows import * Remove deque for vec * Just send event * Use correct push_back method * Push correct event
This commit is contained in:
parent
fae10c6072
commit
0f14e63b34
|
@ -460,8 +460,13 @@ impl EventsLoop {
|
|||
physical_device.reset_scroll_position(info);
|
||||
}
|
||||
}
|
||||
callback(Event::WindowEvent { window_id: mkwid(xev.event), event: CursorEntered { device_id: mkdid(xev.deviceid) } });
|
||||
|
||||
callback(Event::WindowEvent { window_id: mkwid(xev.event), event: CursorEntered { device_id: mkdid(xev.deviceid) } })
|
||||
let new_cursor_pos = (xev.event_x, xev.event_y);
|
||||
callback(Event::WindowEvent { window_id: wid, event: CursorMoved {
|
||||
device_id: mkdid(xev.deviceid),
|
||||
position: new_cursor_pos
|
||||
}})
|
||||
}
|
||||
ffi::XI_Leave => {
|
||||
let xev: &ffi::XILeaveEvent = unsafe { &*(xev.data as *const _) };
|
||||
|
@ -474,7 +479,13 @@ impl EventsLoop {
|
|||
let window_data = windows.get_mut(&WindowId(xev.event)).unwrap();
|
||||
(self.display.xlib.XSetICFocus)(window_data.ic);
|
||||
}
|
||||
callback(Event::WindowEvent { window_id: mkwid(xev.event), event: Focused(true) })
|
||||
callback(Event::WindowEvent { window_id: mkwid(xev.event), event: Focused(true) });
|
||||
|
||||
let new_cursor_pos = (xev.event_x, xev.event_y);
|
||||
callback(Event::WindowEvent { window_id: wid, event: CursorMoved {
|
||||
device_id: mkdid(xev.deviceid),
|
||||
position: new_cursor_pos
|
||||
}})
|
||||
}
|
||||
ffi::XI_FocusOut => {
|
||||
let xev: &ffi::XIFocusOutEvent = unsafe { &*(xev.data as *const _) };
|
||||
|
|
|
@ -442,7 +442,32 @@ impl EventsLoop {
|
|||
appkit::NSOtherMouseDown => { Some(into_event(WindowEvent::MouseInput { device_id: DEVICE_ID, state: ElementState::Pressed, button: MouseButton::Middle })) },
|
||||
appkit::NSOtherMouseUp => { Some(into_event(WindowEvent::MouseInput { device_id: DEVICE_ID, state: ElementState::Released, button: MouseButton::Middle })) },
|
||||
|
||||
appkit::NSMouseEntered => { Some(into_event(WindowEvent::CursorEntered { device_id: DEVICE_ID })) },
|
||||
appkit::NSMouseEntered => {
|
||||
let window = match maybe_window.or_else(maybe_key_window) {
|
||||
Some(window) => window,
|
||||
None => return None,
|
||||
};
|
||||
|
||||
let window_point = ns_event.locationInWindow();
|
||||
let view_point = if ns_window == cocoa::base::nil {
|
||||
let ns_size = foundation::NSSize::new(0.0, 0.0);
|
||||
let ns_rect = foundation::NSRect::new(window_point, ns_size);
|
||||
let window_rect = window.window.convertRectFromScreen_(ns_rect);
|
||||
window.view.convertPoint_fromView_(window_rect.origin, cocoa::base::nil)
|
||||
} else {
|
||||
window.view.convertPoint_fromView_(window_point, cocoa::base::nil)
|
||||
};
|
||||
let view_rect = NSView::frame(*window.view);
|
||||
let scale_factor = window.hidpi_factor();
|
||||
|
||||
let x = (scale_factor * view_point.x as f32) as f64;
|
||||
let y = (scale_factor * (view_rect.size.height - view_point.y) as f32) as f64;
|
||||
let window_event = WindowEvent::CursorMoved { device_id: DEVICE_ID, position: (x, y) };
|
||||
let event = Event::WindowEvent { window_id: ::WindowId(window.id()), event: window_event };
|
||||
|
||||
self.shared.pending_events.lock().unwrap().push_back(event);
|
||||
Some(into_event(WindowEvent::CursorEntered { device_id: DEVICE_ID }))
|
||||
},
|
||||
appkit::NSMouseExited => { Some(into_event(WindowEvent::CursorLeft { device_id: DEVICE_ID })) },
|
||||
|
||||
appkit::NSMouseMoved |
|
||||
|
|
|
@ -673,11 +673,19 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
|
|||
},
|
||||
|
||||
winapi::WM_SETFOCUS => {
|
||||
use events::WindowEvent::Focused;
|
||||
use events::WindowEvent::{Focused, CursorMoved};
|
||||
send_event(Event::WindowEvent {
|
||||
window_id: SuperWindowId(WindowId(window)),
|
||||
event: Focused(true)
|
||||
});
|
||||
|
||||
let x = winapi::GET_X_LPARAM(lparam) as f64;
|
||||
let y = winapi::GET_Y_LPARAM(lparam) as f64;
|
||||
|
||||
send_event(Event::WindowEvent {
|
||||
window_id: SuperWindowId(WindowId(window)),
|
||||
event: CursorMoved { device_id: DEVICE_ID, position: (x, y) },
|
||||
});
|
||||
0
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue