Skip to content
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

fix: Correct modal focus behavior on macOS #18995

Merged
merged 8 commits into from Jul 1, 2019
Merged

Conversation

erickzhao
Copy link
Member

@erickzhao erickzhao commented Jun 26, 2019

Description of Change

Fixes #18502

This PR changes the focus and blur events that we emit in Electron to listen to changes in key window rather than main window. It swaps out windowDidBecomeMain and windowDidResignMain for windowDidBecomeKey and windowDidResignKey, respectively.

It seems to work as intended now. Also added a new test to test this exact situation. Please let me know if there's a less convoluted way to test this specific case, since it seems like I'm listening to a very specific series of events. Test seems to be working locally on my end, and fails on a downloaded CI build from master. ✅

Context

In our macOS code, the NativeWindowMac::Show() function in native_window_mac.mm calls this beginSheet function, which specifies that:

If the window has no presented sheets, this method displays the specified sheet, makes it key, and returns control to the caller. While the sheet remains visible, most events targeted at the receiver are prohibited.

For additional context, see Apple developer documentation on key and main windows here.

Fiddle: https://gist.github.com/c9c19684f6e0d23c102161fb3e86500b


cc @codebytere @deermichel

Checklist

Release Notes

Notes: Fixed bug on macOS where the main window could be targeted for a focus event when it was disabled behind a modal.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Jun 26, 2019
@erickzhao erickzhao changed the title [WIP] fix: Correct modal focus on macOS [WIP] fix: Correct modal focus behavior on macOS Jun 26, 2019
@erickzhao erickzhao marked this pull request as ready for review June 26, 2019 17:32
@erickzhao erickzhao changed the title [WIP] fix: Correct modal focus behavior on macOS fix: Correct modal focus behavior on macOS Jun 26, 2019
Copy link
Contributor

@jkleinsc jkleinsc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @erickzhao! Overall looks good to me - I would just make your new test a little more robust by verifying the main window can regain focus once the modal is closed.

spec/api-browser-window-spec.js Outdated Show resolved Hide resolved
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Jun 27, 2019
@erickzhao
Copy link
Member Author

@jkleinsc Seems like calling child.isDestroyed() and not relying on focus and closed emission ordering helped make the spec pass on Linux and Windows!

@codebytere codebytere merged commit c7da54e into master Jul 1, 2019
@release-clerk
Copy link

release-clerk bot commented Jul 1, 2019

Release Notes Persisted

Fixed bug on macOS where the main window could be targeted for a focus event when it was disabled behind a modal.

@trop
Copy link
Contributor

trop bot commented Jul 1, 2019

I have automatically backported this PR to "4-2-x", please check out #19061

@trop
Copy link
Contributor

trop bot commented Jul 1, 2019

I have automatically backported this PR to "6-0-x", please check out #19062

@trop
Copy link
Contributor

trop bot commented Jul 1, 2019

I have automatically backported this PR to "5-0-x", please check out #19063

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
5.0.x
Fixed in 5.0.7
6.1.x
Fixed in 6.0.0-beta.12
Development

Successfully merging this pull request may close these issues.

MacOS modal focus
3 participants