Skip to content

Commit

Permalink
Windows: Ignore spurious mouse move messages
Browse files Browse the repository at this point in the history
  • Loading branch information
filnet committed Feb 5, 2020
1 parent e295104 commit e25c4d8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- On Wayland, fix coordinates in mouse events when scale factor isn't 1
- On Web, add the ability to provide a custom canvas
- **Breaking:** On Wayland, the `WaylandTheme` struct has been replaced with a `Theme` trait, allowing for extra configuration
- On Windows, ignore spurious mouse move messages.

# 0.20.0 (2020-01-05)

Expand Down
28 changes: 19 additions & 9 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,15 +858,25 @@ unsafe extern "system" fn public_window_callback<T: 'static>(
let x = windowsx::GET_X_LPARAM(lparam) as f64;
let y = windowsx::GET_Y_LPARAM(lparam) as f64;
let position = PhysicalPosition::new(x, y);

subclass_input.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)),
event: CursorMoved {
device_id: DEVICE_ID,
position,
modifiers: event::get_key_mods(),
},
});
let cursor_moved;
{
// handle spurious WM_MOUSEMOVE messages
// see https://devblogs.microsoft.com/oldnewthing/20031001-00/?p=42343
// and http://debugandconquer.blogspot.com/2015/08/the-cause-of-spurious-mouse-move.html
let mut w = subclass_input.window_state.lock();
cursor_moved = w.mouse.last_position != Some(position);
w.mouse.last_position = Some(position);
}
if cursor_moved {
subclass_input.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)),
event: CursorMoved {
device_id: DEVICE_ID,
position,
modifiers: event::get_key_mods(),
},
});
}

0
}
Expand Down
4 changes: 3 additions & 1 deletion src/platform_impl/windows/window_state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
dpi::Size,
dpi::{PhysicalPosition, Size},
platform_impl::platform::{event_loop, icon::WinIcon, util},
window::{CursorIcon, Fullscreen, WindowAttributes},
};
Expand Down Expand Up @@ -48,6 +48,7 @@ pub struct MouseProperties {
pub cursor: CursorIcon,
pub buttons_down: u32,
cursor_flags: CursorFlags,
pub last_position: Option<PhysicalPosition<f64>>,
}

bitflags! {
Expand Down Expand Up @@ -106,6 +107,7 @@ impl WindowState {
cursor: CursorIcon::default(),
buttons_down: 0,
cursor_flags: CursorFlags::empty(),
last_position: None,
},

min_size: attributes.min_inner_size,
Expand Down

0 comments on commit e25c4d8

Please sign in to comment.