Window collection behavior on activation read after NSApplicationDidBecomeActiveNotification

Originator:textmate
Number:rdar://23587833 Date Originated:2015-11-18
Status:Open Resolved:
Product:OS X Product Version:10.11.1 (15B42)
Classification:Other Bug Reproducible:Always
 
For some windows I desire the NSWindowCollectionBehaviorMoveToActiveSpace behavior when the application is active, e.g. calling up a find dialog should show that dialog on the active space, even if it was previously used on another space.

But when moving focus to my application I do not want this behavior. For example if we leave the application with the find window as key, switch space, and bring back focus to my app (command-tab) then rather than move back to the space where the find dialog was last used, the find dialog is moved to the active space.

For this reason I observe the NSApplicationDidBecomeActiveNotification/NSApplicationDidResignActiveNotification notifications and run this code:

	- (void)applicationDidBecomeActive:(NSNotification*)aNotification
	{
		self.window.collectionBehavior |= NSWindowCollectionBehaviorMoveToActiveSpace;
	}

	- (void)applicationDidResignActive:(NSNotification*)aNotification
	{
		self.window.collectionBehavior &= ~NSWindowCollectionBehaviorMoveToActiveSpace;
	}

Starting with 10.11 this no longer works.

Steps to Reproduce:
1. Add the code from the description to an app.
2. Open the window on which the code works.
3. Switch to another application and space.
4. Command-tab back to the application.

Expected Results:
We should switch back to the space the application was last used in.

Actual Results:
The window is brought to our current space.

Notes:
If we change the collection behavior asynchronously then it works on 10.11, for example:

	- (void)applicationDidBecomeActive:(NSNotification*)aNotification
	{
		dispatch_async(dispatch_get_main_queue(), ^{
			self.window.collectionBehavior |= NSWindowCollectionBehaviorMoveToActiveSpace;
		});
	}

	- (void)applicationDidResignActive:(NSNotification*)aNotification
	{
		dispatch_async(dispatch_get_main_queue(), ^{
			self.window.collectionBehavior &= ~NSWindowCollectionBehaviorMoveToActiveSpace;
		});
	}

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!