Skip to content

Commit

Permalink
fix: make BrowserWindow#isFocused() return false when blur() is called
Browse files Browse the repository at this point in the history
The isFocused() method on macOS works by checking if the selected
BrowserWindow is a key window. Unfortunately doesn't work well with
focus() and blur() because these weren't calling any macOS APIs that
would change the key status of the window. Hence, this changes the
implementation of blur() to call orderOut first, which removes the key
status of the window. Then when the orderBack function is called, it
moves the window to the back of its level in the screen list, without
changing the key window.

Fixes: #33732
Signed-off-by: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
RaisinTen committed Apr 12, 2022
1 parent 4d4682c commit c9e32e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions shell/browser/native_window_mac.mm
Expand Up @@ -506,6 +506,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
[[NSApplication sharedApplication] activateIgnoringOtherApps:NO];
[window_ makeKeyAndOrderFront:nil];
} else {
[window_ orderOut:nil];
[window_ orderBack:nil];
}
}
Expand Down
7 changes: 6 additions & 1 deletion spec-main/api-browser-window-spec.ts
Expand Up @@ -763,7 +763,12 @@ describe('BrowserWindow module', () => {
});

describe('BrowserWindow.blur()', () => {
it('removes focus from window', () => {
it('removes focus from window', async () => {
const show = emittedOnce(w, 'show');
w.show();
await show;
w.focus();
expect(w.isFocused()).to.equal(true);
w.blur();
expect(w.isFocused()).to.equal(false);
});
Expand Down

0 comments on commit c9e32e0

Please sign in to comment.