Code Monkey home page Code Monkey logo

Comments (2)

tmandry avatar tmandry commented on June 23, 2024

The fourth goal, keeping track of which space each window is on, is a bit more subtle. The user can trigger Mission Control and drag windows to other spaces. As far as I can tell, there is no direct way to observe a window moving to another space. Nor is there a notification for Mission Control being activated.

So far, the best signal I've found is to watch com.apple.dock for the uiElementDestroyed notification. When Mission Control is triggered, an AXGroup element is created (with some nested groups for the window and desktop buttons). There's no way to observe this with the AX API, other than polling. However, when Mission Control is deactivated, that AXGroup gets destroyed, triggering the uiElementDestroyed notification. (At that point we won't be able to see what the element was, of course.)

When we see this notification occur, we can check to see if any windows from the current space have moved.

There's also a trick using Quartz event tap that can be used to detect when Mission Control is activated, but that won't help us much.

This tracking is going to be best-effort; we can only reliably track when windows move away from the current space when Mission Control is deactivated. We can also notice when a window we thought was on a space is no longer there when we switch to it. Hopefully, these are the only cases we really care about.

Also, let's not forget that there may be one space per screen.

Keeping that in mind.. we can support something like the following API:

Window
- isOnCurrentSpace: bool

Space
- knownWindows: [Window]

Screen
- activeSpace: Space

Events
- ActiveSpaceChanged(new: Space, old: Space)
- NewSpaceDetected(space)
- EmptySpaceCulled(space)
- WindowMovedFromCurrentSpace(window)
- WindowMovedToCurrentSpace(window)

I'm not including Window.space, for instance, because it just won't be useful beyond determining whether the window is on a current space.

from swindler.

tmandry avatar tmandry commented on June 23, 2024

There is also a way to track the order of spaces, but tying that to the information we already have is not trivial. See this gist for more.

Using the defaults database to get this information probably falls in the category of undocumented APIs.

The window IDs there are probably CGWindowIds. See this comment for some links on getting window ids for AXWindows.

The main blocker for this, however, is that the window list can go stale. When a user changes the order of spaces we know we can rely on the information, because it all gets updated. However, it can already be stale the first time we read the window lists. Thus we won't know the order of the spaces until the first time they change!

I suspect that every space has an invisible window that is dedicated to it, owned by the Dock or something similar. If we can find these windows in the list and on the current space, it might be possible to determine the index of the current space. I have no idea if this will work, and if it does, whether it will continue to work in the future.

from swindler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.