Skip to content

Commit

Permalink
Check the deferred caption button before execution.
Browse files Browse the repository at this point in the history
The user may cancel the button press on a caption button
by moving the mouse away before releasing.
  • Loading branch information
aloucks committed Jun 22, 2019
1 parent b0d2d7f commit e413f5a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
27 changes: 22 additions & 5 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,8 @@ unsafe extern "system" fn public_window_callback<T>(
// Discard the non-client button-down event and defer the processing until
// the non-client button-up event. This prevents a pause in the message loop
// while the user has the mouse button pressed on one of these buttons.
let mut window_state = subclass_input.window_state.lock();
window_state.deferred_nclbuttondown_wparam = Some(wparam);
0
},
_ => {
Expand All @@ -863,9 +865,18 @@ unsafe extern "system" fn public_window_callback<T>(
},

winuser::WM_NCLBUTTONUP => {
// Manually apply min, max, restore, and close since we discarded the button down event.
match wparam as isize {
winuser::HTMAXBUTTON => {
let deferred_wparam = subclass_input
.window_state
.lock()
.deferred_nclbuttondown_wparam
.filter(|deferred_wparam| *deferred_wparam == wparam)
.map(|wparam| wparam as isize)
.take();
// Manually apply min, max, restore, and close since we discarded the button down event,
// but only in the event that the user did not cancel the operation. If the user canelled
// the operation, WM_LBUTTONUP will fire and we'll clear the deferred state there as well.
match deferred_wparam {
Some(winuser::HTMAXBUTTON) => {
let window_state = subclass_input.window_state.lock();
let window_flags = window_state.window_flags();
drop(window_state);
Expand All @@ -876,11 +887,11 @@ unsafe extern "system" fn public_window_callback<T>(
}
0
}
winuser::HTMINBUTTON => {
Some(winuser::HTMINBUTTON) => {
winuser::ShowWindow(window, winuser::SW_MINIMIZE);
0
}
winuser::HTCLOSE => {
Some(winuser::HTCLOSE) => {
winuser::PostMessageW(window, winuser::WM_CLOSE, 0, 0);
0
}
Expand Down Expand Up @@ -1195,6 +1206,12 @@ unsafe extern "system" fn public_window_callback<T>(
ElementState::Released, MouseButton::Left, WindowEvent::MouseInput,
};

subclass_input
.window_state
.lock()
.deferred_nclbuttondown_wparam
.take();

release_mouse(&mut *subclass_input.window_state.lock());

subclass_input.send_event(Event::WindowEvent {
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
Expand Up @@ -8,7 +8,7 @@ use parking_lot::MutexGuard;
use std::{io, ptr};
use winapi::{
shared::{
minwindef::DWORD,
minwindef::{DWORD, WPARAM},
windef::{HWND, RECT},
},
um::winuser,
Expand All @@ -30,6 +30,7 @@ pub struct WindowState {
pub dpi_factor: f64,

pub fullscreen: Option<MonitorHandle>,
pub deferred_nclbuttondown_wparam: Option<WPARAM>,
window_flags: WindowFlags,
}

Expand Down Expand Up @@ -111,6 +112,7 @@ impl WindowState {

fullscreen: None,
window_flags: WindowFlags::empty(),
deferred_nclbuttondown_wparam: None,
}
}

Expand Down

0 comments on commit e413f5a

Please sign in to comment.