Hammerspoon / hammerspoon

Staggeringly powerful macOS desktop automation with Lua
http://www.hammerspoon.org
MIT License
11.98k stars 581 forks source link

window has no API for z index #2046

Open macrael opened 5 years ago

macrael commented 5 years ago

With orderedWindows you can get a list of all the windows in order but there is no way to just inspect the z index of a single window.

asmagill commented 5 years ago

From what a cursory review of the Quartz CGWindow functions shows, this isn't readily available... you could do something like the following to get it from orderedWindows:

index = hs.fnutils.indexOf(hs.window.orderedWindows(), windowObjectThatICareAbout)

where windowObjectThatICareAbout is the userdata object representing the window you are interested in.

macrael commented 5 years ago

Thanks, if it's not possible it's not possible. It looks like -[NSWindow orderedIndex] might have it but if you are only interacting with CGWindow then that's that.

asmagill commented 5 years ago

Most of the NSWindow methods only work on your own application's windows, but there are a few exceptions using undocumented (private) API functions and sometimes they can be accessed through the Accessibility interface (AXUIElement)... this gives me a starting point, so I'll see what I can come up with... it will probably be a few days before I can do any real digging, but let's leave this open for now.

macrael commented 5 years ago

That makes sense. Thanks.