macos: Fire a ModifiersChanged event on window_did_resign_key

From debugging, I determined that macOS' emission of a flagsChanged
around window switching is inconsistent.  It is fair to assume, I think,
that when the user switches windows, they do not expect their former
modifiers state to remain effective; so I think it's best to clear that
state by sending a ModifiersChanged(ModifiersState::empty()).

Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
This commit is contained in:
Kristofer Rye
2020-01-22 09:25:27 -06:00
parent e518931264
commit f79f21641a
2 changed files with 4 additions and 1 deletions

View File

@@ -762,6 +762,8 @@ extern "C" fn flags_changed(this: &Object, _sel: Sel, event: id) {
}));
}
trace!("Queueing event with modifiers {:?}", state.modifiers);
AppState::queue_event(EventWrapper::StaticEvent(Event::WindowEvent {
// TODO Maybe memoize get_window_id if it's safe to reuse?
window_id: WindowId(get_window_id(state.ns_window)),

View File

@@ -16,7 +16,7 @@ use objc::{
use crate::{
dpi::LogicalSize,
event::{Event, WindowEvent},
event::{Event, ModifiersState, WindowEvent},
platform_impl::platform::{
app_state::AppState,
event::{EventProxy, EventWrapper},
@@ -319,6 +319,7 @@ extern "C" fn window_did_become_key(this: &Object, _: Sel, _: id) {
extern "C" fn window_did_resign_key(this: &Object, _: Sel, _: id) {
trace!("Triggered `windowDidResignKey:`");
with_state(this, |state| {
state.emit_event(WindowEvent::ModifiersChanged(ModifiersState::empty()));
state.emit_event(WindowEvent::Focused(false));
});
trace!("Completed `windowDidResignKey:`");