Comments (2)
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.
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)
- Size property not immediately consistent with frame
- Mark writes that did not match the desired value as external events
- Swindler does not compile on Xcode 10.2 HOT 2
- xcode
- Mac App Store HOT 1
- NSScreen.Screens Coordinates don't align with AXUIElement coordinates for multi-monitor displays HOT 3
- Mouse over active window title bar event HOT 2
- Is it possible to get value of kCGWindowNumber of window? HOT 3
- Swift Package Manager support? HOT 1
- bug: 'self' captured by a closure before all members were initialized HOT 4
- Docs seem to be out of date (Podfile missing) HOT 2
- Cannot be added as a Swift Package HOT 1
- Add Close Button to Window element
- How do I find the topmost window at a given point? HOT 1
- Is there a way to prevent windows from being dragged after they've been dragged a certain distance?
- Move window to another desktop HOT 2
- "Safari Web Content (Cached)" processes causing 20 second+ initialization times HOT 1
- Example app fails HOT 1
- Window frame return wrong value HOT 1
- "window destroyed" event sent for tab closing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swindler.