NSWindow隐藏活动窗口并专注于其他窗口

时间:2015-01-26 10:42:46

标签: objective-c xcode cocoa nswindow nsapplication

如何隐藏当前活动的NSWindow A 并关注最后一个 B (当前窗口后一级)并将其激活?

我尝试使用此跟踪代码,但它不起作用( B 将变为前窗但未激活):

[_parentWindow orderBack:nil];
// Now i want to do some stuffs with last opened App (NSWindow) and it should be focused and activated now. 
[_parentWindow orderFront:nil];

2 个答案:

答案 0 :(得分:0)

请尝试makeKeyAndOrderFront:

[_window makeKeyAndOrderFront:nil];

答案 1 :(得分:0)

@bluedome响应的补充。您可以在当前用户会话中获取有关Windows的信息:

CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
for (NSDictionary* entry in (__bridge NSArray *)windowList) {
  NSString *ownerName = [entry objectForKey:(id)kCGWindowOwnerName];
  NSInteger ownerPID = [[entry objectForKey:(id)kCGWindowOwnerPID] integerValue];
  NSString *windowName = [entry objectForKey:(id)kCGWindowName];
  NSLog(@"%@:%ld, %@", ownerName, (long)ownerPID, windowName);
}