Skip to content

Commit 5c6fbbb

Browse files
committed
focus app on macos first for consistency
1 parent 83b48be commit 5c6fbbb

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/macos/window_manager.mm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,25 @@ MMRect getWindowRect(const WindowHandle windowHandle) {
109109

110110
bool focusWindow(const WindowHandle windowHandle) {
111111

112+
CGWindowListOption listOptions =
113+
kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements;
114+
CFArrayRef windowList =
115+
CGWindowListCopyWindowInfo(listOptions, kCGNullWindowID);
116+
bool activated = false;
117+
for (NSDictionary *info in (NSArray *)windowList) {
118+
NSNumber *ownerPid = info[(id)kCGWindowOwnerPID];
119+
NSNumber *windowNumber = info[(id)kCGWindowNumber];
120+
if ([windowNumber intValue] == windowHandle) {
121+
NSRunningApplication *app = [NSRunningApplication
122+
runningApplicationWithProcessIdentifier:[ownerPid intValue]];
123+
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
124+
activated = true;
125+
}
126+
}
127+
if (windowList) {
128+
CFRelease(windowList);
129+
}
130+
112131
NSDictionary *windowInfo = getWindowInfo(windowHandle);
113132
if (windowInfo == nullptr || windowHandle < 0) {
114133
NSLog(@"Could not find window info for window handle %lld", windowHandle);

0 commit comments

Comments
 (0)