diff options
author | Jeremy Huddleston Sequoia <jeremyhu@apple.com> | 2017-07-18 21:35:49 -0700 |
---|---|---|
committer | Jeremy Huddleston Sequoia <jeremyhu@apple.com> | 2021-02-01 23:24:10 -0800 |
commit | 32760f39dd48277ecb00910dbbebff941cfcbb46 (patch) | |
tree | c2294f1f95abdee47409dcc2737d581ea4caa508 | |
parent | 24f9d825883742fa7ae3086cbea29250af14eb34 (diff) |
XQuartz: Hack around an issue that can occur on macOS due to background apps incorrectly stealing focus
Works around <rdar://problem/7150340>.
Tested-by: Martin Otte <martinjotte@gmail.com>
Tested-by: Tom Lane <tgl@sss.pgh.pa.us>
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit dd0b721c977e88d7c3830cc2a672c2793bca4fa0)
-rw-r--r-- | hw/xquartz/X11Application.m | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m index e745f53d7..9076eb75f 100644 --- a/hw/xquartz/X11Application.m +++ b/hw/xquartz/X11Application.m @@ -268,13 +268,32 @@ message_kit_thread(SEL selector, NSObject *arg) if (_x_active) [self activateX:NO]; } else if ([self modalWindow] == nil) { - /* Must be an X window. Tell appkit it doesn't have focus. */ + /* Must be an X window. Tell appkit windows to resign main/key */ for_appkit = NO; - if ([self isActive]) { - [self deactivate]; - if (!_x_active && quartzProcs->IsX11Window([e windowNumber])) - [self activateX:YES]; + if (!_x_active && quartzProcs->IsX11Window([e windowNumber])) { + if ([self respondsToSelector:@selector(_setKeyWindow:)] && [self respondsToSelector:@selector(_setMainWindow:)]) { + NSWindow *keyWindow = [self keyWindow]; + if (keyWindow) { + [self _setKeyWindow:nil]; + [keyWindow resignKeyWindow]; + } + + NSWindow *mainWindow = [self mainWindow]; + if (mainWindow) { + [self _setMainWindow:nil]; + [mainWindow resignMainWindow]; + } + } else { + /* This has a side effect of causing background apps to steal focus from XQuartz. + * Unfortunately, there is no public and stable API to do what we want, but this + * is a decent fallback in the off chance that the above selectors get dropped + * in the future. + */ + [self deactivate]; + } + + [self activateX:YES]; } } |