I've been spending some time looking at the window system in OSX. I'm trying to understand all the information around it for some capture code that I'm working on.
WHAT I WANT TO DO
I would like to be able to filter my window query such that I only grab windows that are visible in any of the spaces or are minimized in any of the spaces.
WORK SO FAR
Right now, using the SonOfGrab test code, and the documentation, I have created a program that can query the window server and give me a listing like this:
{
"name": "Xcode",
"id": 25314,
"width": 16,
"height": 194,
"visible": "NO",
"desktop": -1,
"owner pid": 37319,
"layer": 0
}
I filter out all desktop elements and I only grab shareable windows.
WHAT I'VE LEARNED
So as far as I can tell from the documentation, which is sort of limited, and the my example programs are these things
- The visibility attribute of a window will tell you if it's visible in the current active space.
- The layer seems to be important. As far as I can tell, the windows that I want to filter are only available in layer 0. It looks like other layers are related to the dock, toolbar, icons, etc.
- Items that are not visible but in layer 0 are sometimes minimized windows.
PROBLEMS I'VE ENCOUNTERED
Here are the issues I'm facing with my code and with the SonOfGrab example.
- Minimized windows and closed windows on some applications seem to be identical. For example with the Activity Monitor. If I minimize the window or close it, the output is identical. Are there other fields which would help me differentiate this? It seems like this happens because the application is always running in the task bar.
MINIMIZED ACTIVITY MONITOR
{
"name": "Activity Monitor",
"id": 94,
"width": 703,
"height": 728,
"visible": "NO",
"desktop": -1,
"owner pid": 2353,
"layer": 0
},
CLOSED ACTIVITY MONITOR
{
"name": "Activity Monitor",
"id": 94,
"width": 703,
"height": 728,
"visible": "NO",
"desktop": -1,
"owner pid": 2353,
"layer": 0
},
- Even when I filter out desktop elements and only grab from layer 0. I still see the SystemUIServer floating around. When I try to grab it's windows with SonOfGrab I don't get anything. Is there any meaningful way to filter this other than by name?
- Unviewable windows. With XCODE I notice that if I have one project opened up and viewable. My program and SonOfGrab will show 5 windows in layer 0. 1 will be visible, the rest are invisible.
SUMMARY
I'd like to be able to only list windows that are viewable in any space or are minimized and could potentially be viewed. It seems like the visibility and layer kind of help, but maybe I need more window details to figure this out. Any ideas :-)?