Skip to content

Commit

Permalink
when mouse click, should check if mouse moved
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhou121 committed Sep 8, 2023
1 parent e3372c1 commit 25edc72
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 12 deletions.
52 changes: 50 additions & 2 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1542,12 +1542,37 @@ unsafe fn public_window_callback_inner<T: 'static>(
}

WM_LBUTTONDOWN => {
use crate::event::{ElementState::Pressed, MouseButton::Left, WindowEvent::MouseInput};
use crate::event::{
ElementState::Pressed, MouseButton::Left, WindowEvent::CursorMoved,
WindowEvent::MouseInput,
};

capture_mouse(window, &mut userdata.window_state_lock());

update_modifiers(window, userdata);

let x = super::get_x_lparam(lparam as u32) as f64;
let y = super::get_y_lparam(lparam as u32) as f64;
let position = PhysicalPosition::new(x, y);
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 = userdata.window_state_lock();
cursor_moved = w.mouse.last_position != Some(position);
w.mouse.last_position = Some(position);
}
if cursor_moved {
userdata.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)),
event: CursorMoved {
device_id: DEVICE_ID,
position,
},
});
}

userdata.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)),
event: MouseInput {
Expand Down Expand Up @@ -1581,13 +1606,36 @@ unsafe fn public_window_callback_inner<T: 'static>(

WM_RBUTTONDOWN => {
use crate::event::{
ElementState::Pressed, MouseButton::Right, WindowEvent::MouseInput,
ElementState::Pressed, MouseButton::Right, WindowEvent::CursorMoved,
WindowEvent::MouseInput,
};

capture_mouse(window, &mut userdata.window_state_lock());

update_modifiers(window, userdata);

let x = super::get_x_lparam(lparam as u32) as f64;
let y = super::get_y_lparam(lparam as u32) as f64;
let position = PhysicalPosition::new(x, y);
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 = userdata.window_state_lock();
cursor_moved = w.mouse.last_position != Some(position);
w.mouse.last_position = Some(position);
}
if cursor_moved {
userdata.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)),
event: CursorMoved {
device_id: DEVICE_ID,
position,
},
});
}

userdata.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)),
event: MouseInput {
Expand Down
22 changes: 12 additions & 10 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ use windows_sys::Win32::{
Touch::{RegisterTouchWindow, TWF_WANTPALM},
},
WindowsAndMessaging::{
CreateWindowExW, FlashWindowEx, GetClientRect, GetCursorPos, GetForegroundWindow,
GetSystemMetrics, GetWindowPlacement, GetWindowTextLengthW, GetWindowTextW,
IsWindowVisible, LoadCursorW, PeekMessageW, PostMessageW, RegisterClassExW, SetCursor,
SetCursorPos, SetForegroundWindow, SetWindowDisplayAffinity, SetWindowPlacement,
SetWindowPos, SetWindowTextW, TrackPopupMenu, CS_HREDRAW, CS_VREDRAW, CW_USEDEFAULT,
FLASHWINFO, FLASHW_ALL, FLASHW_STOP, FLASHW_TIMERNOFG, FLASHW_TRAY, GWLP_HINSTANCE,
HTBOTTOM, HTBOTTOMLEFT, HTBOTTOMRIGHT, HTCAPTION, HTLEFT, HTRIGHT, HTTOP, HTTOPLEFT,
HTTOPRIGHT, NID_READY, PM_NOREMOVE, SM_DIGITIZER, SWP_ASYNCWINDOWPOS, SWP_NOACTIVATE,
SWP_NOSIZE, SWP_NOZORDER, TPM_LEFTALIGN, WDA_EXCLUDEFROMCAPTURE, WDA_NONE,
WM_NCLBUTTONDOWN, WNDCLASSEXW,
CreateWindowExW, DestroyMenu, FlashWindowEx, GetClientRect, GetCursorPos,
GetForegroundWindow, GetSystemMetrics, GetWindowPlacement, GetWindowTextLengthW,
GetWindowTextW, IsWindowVisible, LoadCursorW, PeekMessageW, PostMessageW,
RegisterClassExW, SetCursor, SetCursorPos, SetForegroundWindow,
SetWindowDisplayAffinity, SetWindowPlacement, SetWindowPos, SetWindowTextW,
TrackPopupMenu, CS_HREDRAW, CS_VREDRAW, CW_USEDEFAULT, FLASHWINFO, FLASHW_ALL,
FLASHW_STOP, FLASHW_TIMERNOFG, FLASHW_TRAY, GWLP_HINSTANCE, HTBOTTOM, HTBOTTOMLEFT,
HTBOTTOMRIGHT, HTCAPTION, HTLEFT, HTRIGHT, HTTOP, HTTOPLEFT, HTTOPRIGHT, NID_READY,
PM_NOREMOVE, SM_DIGITIZER, SWP_ASYNCWINDOWPOS, SWP_NOACTIVATE, SWP_NOSIZE,
SWP_NOZORDER, TPM_LEFTALIGN, WDA_EXCLUDEFROMCAPTURE, WDA_NONE, WM_NCLBUTTONDOWN,
WM_NULL, WNDCLASSEXW,

Check failure on line 54 in src/platform_impl/windows/window.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, i686-pc-windows-gnu, windows-latest, -i686-pc-windows-gnu)

unused import: `WM_NULL`

Check failure on line 54 in src/platform_impl/windows/window.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, i686-pc-windows-msvc, windows-latest)

unused import: `WM_NULL`

Check failure on line 54 in src/platform_impl/windows/window.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, i686-pc-windows-msvc, windows-latest)

unused import: `WM_NULL`

Check failure on line 54 in src/platform_impl/windows/window.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, x86_64-pc-windows-gnu, windows-latest, -x86_64-pc-windows-gnu)

unused import: `WM_NULL`

Check failure on line 54 in src/platform_impl/windows/window.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, x86_64-pc-windows-msvc, windows-latest)

unused import: `WM_NULL`

Check failure on line 54 in src/platform_impl/windows/window.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, i686-pc-windows-gnu, windows-latest, -i686-pc-windows-gnu)

unused import: `WM_NULL`

Check failure on line 54 in src/platform_impl/windows/window.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, x86_64-pc-windows-gnu, windows-latest, -x86_64-pc-windows-gnu)

unused import: `WM_NULL`

Check failure on line 54 in src/platform_impl/windows/window.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, x86_64-pc-windows-msvc, windows-latest)

unused import: `WM_NULL`

Check failure on line 54 in src/platform_impl/windows/window.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, i686-pc-windows-msvc, windows-latest)

unused import: `WM_NULL`

Check failure on line 54 in src/platform_impl/windows/window.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, i686-pc-windows-gnu, windows-latest, -i686-pc-windows-gnu)

unused import: `WM_NULL`

Check failure on line 54 in src/platform_impl/windows/window.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, x86_64-pc-windows-gnu, windows-latest, -x86_64-pc-windows-gnu)

unused import: `WM_NULL`

Check failure on line 54 in src/platform_impl/windows/window.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, x86_64-pc-windows-msvc, windows-latest)

unused import: `WM_NULL`
},
},
};
Expand Down Expand Up @@ -908,6 +909,7 @@ impl Window {
pt
};
TrackPopupMenu(hmenu, TPM_LEFTALIGN, pt.x, pt.y, 0, self.hwnd(), null());
DestroyMenu(hmenu);
}
}
}
Expand Down

0 comments on commit 25edc72

Please sign in to comment.