Add CoreGraphics bindings and macOS getAllWindows() implementation#1719
Conversation
e9bcbca to
fcac6d7
Compare
fcac6d7 to
02819aa
Compare
matthiasblaesing
left a comment
There was a problem hiding this comment.
In general the implementation makes sense to me. The usage of HWND is the general API in unfortunate, but the approach taken here is IMHO a good match.
I left two inline comments regarding the data types.
| * @see <a href= | ||
| * "https://developer.apple.com/documentation/coregraphics/1456599-cgmaindisplayid">CGMainDisplayID</a> | ||
| */ | ||
| int CGMainDisplayID(); |
There was a problem hiding this comment.
Hm - the declaration is a bit more involved:
// https://developer.apple.com/documentation/coregraphics/cgdisplaypixelswide(_:)?language=objc
extern size_t CGDisplayPixelsWide(CGDirectDisplayID display);
// https://developer.apple.com/documentation/kernel/size_t?language=objc
typedef typeof (sizeof(int)) size_t;
// https://developer.apple.com/documentation/coregraphics/cgdirectdisplayid?language=objc
typedef uint32_t CGDirectDisplayID;If I remember correctly sizeof results a value of type size_t. The size of that depends on the architecture and can be 32bit or 64bit. Could you please check if it makes sense to reuse com.sun.jna.platform.unix.LibCAPI.size_t. That type is already used in SystemB for mac os.
There was a problem hiding this comment.
That type is already used in
SystemBfor mac os.
And that was one of my earliest mappings here.
MacOS has been 64-bit capable since 10.6 (Snow Leopard) and 64-bit only since 10.15 (Catalina) in 2019. We had a discussion about 32-bit support here and it looks like you're only building 64-bit binaries for it recently.
OpenJDK dropped 32-bit support with JDK 25 (probably to avoid providing SIZE_T support in FFM 😉).
I can certainly map it that way, although I have a feeling I've already made a 64-bit assumption in a JNA contribution elsewhere.
There was a problem hiding this comment.
OK, size_t is definitely correct here and I looked at all my other contributions here and haven't made any 64-bit assumptions... except one. I added this in #1131 7 years ago and it didn't break anything.
That's a vm_size_t which is essentially a NativeLongByReference. Should I fix that in another PR?
There was a problem hiding this comment.
To keep compatibility I'd deprecate this method and add the one with the correct mapping. In the end yeah mac os is 64bit only and I have some serious hopes, that by the time 128bit becomes mainstream project panama obsoleted JNA ;-)
There was a problem hiding this comment.
I have some serious hopes, that by the time 128bit becomes mainstream project panama obsoleted JNA ;-)
FYI I and another maintainer have essentially replicated most of the JNA mappings I use with Panama mappings. Wish there was a repo I could share them...
c0ada93 to
e81598f
Compare
Add CoreGraphics interface to c.s.j.p.mac providing: - Quartz Window Services: CGWindowListCopyWindowInfo, CGRectMakeWithDictionaryRepresentation, window list option constants, and window info dictionary key constants - Quartz Display Services: CGMainDisplayID, CGDisplayBounds, CGDisplayPixelsWide/High, CGGetActiveDisplayList, CGGetOnlineDisplayList, CGDisplayRotation, CGDisplayIsActive/Main/Builtin, CGDisplayVendorNumber/ModelNumber/SerialNumber - CGPoint, CGSize, CGRect structures Implement getAllWindows() in MacWindowUtils using CGWindowListCopyWindowInfo, providing macOS parity with the existing Windows implementation.
e81598f to
8678fe1
Compare
matthiasblaesing
left a comment
There was a problem hiding this comment.
I can't really test, but looks sane and I assume you tested on your end. Thank you.
Adds
CoreGraphicsinterface toc.s.j.p.macproviding JNA bindings for the macOS Quartz Window Services and Quartz Display Services APIs.Also implements
getAllWindows()inMacWindowUtils, giving macOS parity with the existing Windows implementation inWindowUtils. (Note that I had to use the Win32HWNDclass to be compatible with theDesktopWindowclass.)Window Services
CGWindowListCopyWindowInfoCGRectMakeWithDictionaryRepresentationConstants:
kCGWindowListOption*(filtering),kCGWindow*(dictionary keys), sharing types, backing store types.Display Services
CGMainDisplayIDCGDisplayBoundsCGDisplayPixelsWide/CGDisplayPixelsHighCGGetActiveDisplayList/CGGetOnlineDisplayListCGDisplayRotationCGDisplayIsActive/CGDisplayIsMain/CGDisplayIsBuiltinCGDisplayVendorNumber/CGDisplayModelNumber/CGDisplaySerialNumberStructures
CGPoint,CGSize,CGRect(withByValuefor return types)MacWindowUtils.getAllWindows()Uses
CGWindowListCopyWindowInfoto enumerate windows, filtering to normal windows (layer 0). Extracts title, owner name, window ID (as HWND), and bounds, using theDesktopWindowclass used by the Windows implementation.Test Output
On my mac:
and