-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add high resolution mouse to Windows #118
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,10 +244,14 @@ pub enum EventType { | |
/// `delta_y` represents vertical scroll and `delta_x` represents horizontal scroll. | ||
/// Positive values correspond to scrolling up or right and negative values | ||
/// correspond to scrolling down or left | ||
Wheel { | ||
delta_x: i64, | ||
delta_y: i64, | ||
}, | ||
Wheel(MouseScrollDelta), | ||
} | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq)] | ||
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] | ||
pub enum MouseScrollDelta { | ||
LineDelta(f32, f32), | ||
// Not supported yet PixelDelta(PhysicalPosition<f64>), | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This imitates the Winit API |
||
|
||
/// When events arrive from the OS they get some additional information added from | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use crate::rdev::{Event, EventType, GrabError}; | ||
use crate::windows::common::{convert, set_key_hook, set_mouse_hook, HookError, HOOK, KEYBOARD}; | ||
use crate::EventTypes; | ||
use std::ptr::null_mut; | ||
use std::time::SystemTime; | ||
use winapi::um::winuser::{CallNextHookEx, GetMessageA, HC_ACTION}; | ||
|
@@ -44,15 +45,18 @@ impl From<HookError> for GrabError { | |
} | ||
} | ||
|
||
pub fn grab<T>(callback: T) -> Result<(), GrabError> | ||
pub fn grab<T>(event_types: EventTypes, callback: T) -> Result<(), GrabError> | ||
where | ||
T: FnMut(Event) -> Option<Event> + 'static, | ||
{ | ||
unsafe { | ||
GLOBAL_CALLBACK = Some(Box::new(callback)); | ||
set_key_hook(raw_callback)?; | ||
set_mouse_hook(raw_callback)?; | ||
|
||
if event_types.keyboard { | ||
set_key_hook(raw_callback)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, the current keyboard hook can break things. |
||
} | ||
if event_types.mouse { | ||
set_mouse_hook(raw_callback)?; | ||
} | ||
GetMessageA(null_mut(), null_mut(), 0, 0); | ||
} | ||
Ok(()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a useful optimisation on platforms like Windows.