Virtual Desktops (Spaces on Mac) Where is my window?

  1. 6 months ago

    I'm having an issue I want to handle before it becomes too much of a problem. When I start my app, I restore the windows which were open when I last quit to the same locations and general state they were in at the time. I have written the code necessary to confirm that the window is fully on-screen (in case of montitor switches etc. from when shutdown, I hate when other apps restore windows off screen and are very difficult to find and get back on screen) if needed the window gets shifted, generally as little as possible to be on-screen.

    My problem is on a mac with spaces (virtual desktops) enabled where each monitor has its own space. I can't seem to find out anything about 'which space' a window is located within. I expect the same problem on Windows will also exist in similar configurations. Any ideas as to how to determine the 'space' the window is within?

    Thanks

  2. Not sure how it works and I suspect the normal restoration of windows in macOS does some magical tricks to handle that automatically.

    All I know is that NSWindow has an isOnActiveSpace read-only property and that you can be informed when a new Space is activated by listening to the NSWorkSpace notification NSWorkspaceActiveSpaceDidChangeNotification.

    Hope that helps a bit.

or Sign Up to reply!