0
votes

I wrote a project that is working as a background app and I have this little issue.

Let's say I have 3 open desktops (spaces) on my mac:

  1. Space with open NSWindow from my project
  2. Empty space with no open folder apps
  3. Space with for example open folder

I am currently on space number 1.

I swipe 3 fingers left to switch to en empty space, and then again, to switch to a space with open folder (which immediately gets focus).

Then I swipe 3 fingers right to switch from 3rd space to 2nd, and what happens is that it (IMO) knows, that there is not a single NSWindow there to be focused on, so it switches to 1st space (without me even touching the touchpad) and NSWindow from my app is focused now.

My question is - how to prevent this? I mean, I don't remember setting such thing on purpose (my app is based on getting current focused NSWindow, but only when user clicks on a window).

1

1 Answers

0
votes

I suspect that your app is considered still active when you first switch to space 2. Then, when you switch back from space 3 to 2, your app is reactivated (since it was the last active on that space), which makes your app's window the main/key window, and the default behavior is to switch to the window's space when it becomes main/key.

You can change the system behavior with System Preferences > Mission Control > When switching to an application, switch to a Space with open windows for the application.

You can change your app's behavior by setting the window's collectionBehavior property to include NSWindowCollectionBehaviorMoveToActiveSpace, although that would result in your app's window moving to space 2. This can also be set in IB using the Attributes inspector.