Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bring NSWindow to front and to the current Space?

Tags:

swift

cocoa

I'm using this code to bring up my window:

[self.window makeKeyAndOrderFront:self]; [self.window setOrderedIndex:0]; 

But often it will be beneath other windows or displayed in other Space desktop that I last open it in. How do I make it always appear "in front" to the user?

Update I found the answer from previously asked question; make the window show up to the top of other windows: [NSApp activateIgnoringOtherApps:YES];

But how to move the app to the user's current Space?

like image 515
Teo Choong Ping Avatar asked Nov 16 '09 06:11

Teo Choong Ping


2 Answers

To bring your app to the front:

[NSApp activateIgnoringOtherApps:YES]; 

Swift:

NSApp.activateIgnoringOtherApps(true) 

Swift 3:

NSApp.activate(ignoringOtherApps: true) 
like image 136
jtbandes Avatar answered Sep 28 '22 02:09

jtbandes


Perhaps you want:

  [self.window setCollectionBehavior: NSWindowCollectionBehaviorCanJoinAllSpaces]; 

Experiment with the other collection behaviors... I found NSWindowCollectionBehaviorMoveToActiveSpace was a bit buggy in 10.5 but it might be better now.

like image 34
Nicholas Riley Avatar answered Sep 28 '22 01:09

Nicholas Riley