Repository navigation
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.
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [net.java.dev.jna:jna](https://github.com/java-native-access/jna) | `5.18.1` → `5.19.1` |  |  | --- ### Release Notes <details> <summary>java-native-access/jna (net.java.dev.jna:jna)</summary> ### [`v5.19.1`](https://github.com/java-native-access/jna/blob/HEAD/CHANGES.md#Release-5191) [Compare Source](java-native-access/jna@5.19.0...5.19.1) \============== ## Bug Fixes - [#​1730](java-native-access/jna#1730): Replace usage of `MethodHandle` with reflection to restore support for older Android releases - [@​matthiasblaesing](https://github.com/matthiasblaesing). ### [`v5.19.0`](https://github.com/java-native-access/jna/blob/HEAD/CHANGES.md#Release-5190) [Compare Source](java-native-access/jna@5.18.1...5.19.0) \============== ## Features - [#​1696](java-native-access/jna#1696): Add `LARGE_INTEGER.ByValue` to `LARGE_INTEGER` in `WinNT.java` - [@​baier233](https://github.com/baier233). - [#​1697](java-native-access/jna#1697): Add WlanApi module - [@​eranl](https://github.com/eranl). - [#​1718](java-native-access/jna#1718): Add `Cups` to `c.s.j.p.unix` providing CUPS printing system bindings for destinations, jobs, options, and server configuration - [@​dbwiddis](https://github.com/dbwiddis). - [#​1720](java-native-access/jna#1720): Add `groupCount` and `groupMasks` fields to `CACHE_RELATIONSHIP` in `c.s.j.p.win32.WinNT`, matching the updated Windows struct layout - [@​dbwiddis](https://github.com/dbwiddis). - [#​1719](java-native-access/jna#1719): Add `CoreGraphics` to `c.s.j.p.mac` with Quartz Window Services and Display Services bindings; implement `getAllWindows()` in `MacWindowUtils` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1723](java-native-access/jna#1723): Add `ProcFdInfo`, `InSockInfo`, `TcpSockInfo`, `proc_pidfdinfo`, `statfs64`, and `vm_deallocate` to `c.s.j.p.mac.SystemB` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1725](java-native-access/jna#1725): Add `BluetoothApis` to `c.s.j.p.win32` providing Bluetooth device and radio enumeration via `BluetoothFindFirstRadio`, `BluetoothFindFirstDevice`, and related functions - [@​dbwiddis](https://github.com/dbwiddis). ## Bug Fixes - [#​1644](java-native-access/jna#1644): Fix bug in VARDESC and TYPEDESC causing an illegal memory access - [@​lwahonen](https://github.com/lwahonen) - [#​1715](java-native-access/jna#1715): Fix `UdevDevice.getSysname()` calling `udev_device_get_syspath` instead of `udev_device_get_sysname` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1721](java-native-access/jna#1721): Fix switched `serverName`/`domainName` arguments in `Netapi32Util#getDCName` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1722](java-native-access/jna#1722): Fix `Advapi32#RegisterServiceCtrlHandler` using wrong `Handler` type - [@​dbwiddis](https://github.com/dbwiddis). - [#​1636](java-native-access/jna#1636): Drop hard dependency on java.lang.SecurityManager/java.security.AccessController - [@​matthiasblaesing](https://github.com/matthiasblaesing). - [#​1724](java-native-access/jna#1724): Fix `host_page_size` in `c.s.j.p.mac.SystemB` and `getxattr`/`setxattr`/`listxattr` in `c.s.j.p.mac.XAttr` using `long` instead of pointer-sized types for `size_t`/`ssize_t` parameters - [@​dbwiddis](https://github.com/dbwiddis). - [#​1727](java-native-access/jna#1727): Include DragonFlyBSD in `NativeLibrary` versioned library resolution, libc special-case loading, and 64-bit search paths - [@​dbwiddis](https://github.com/dbwiddis). - [#​1709](java-native-access/jna#1709): Rebuild native library for OpenBSD 7.9 x86-64, drop OpenBSD x86 - [@​matthiasblaesing](https://github.com/matthiasblaesing). </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - "before 9am on tuesday" - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMzMuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjE3NS4xIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==--> Reviewed-on: https://code.futo.org/harbor/harbor/pulls/1820 Reviewed-by: Mark Harding <[email protected]>
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [net.java.dev.jna:jna](https://github.com/java-native-access/jna) | `5.18.1` → `5.19.1` |  |  | --- ### Release Notes <details> <summary>java-native-access/jna (net.java.dev.jna:jna)</summary> ### [`v5.19.1`](https://github.com/java-native-access/jna/blob/HEAD/CHANGES.md#Release-5191) [Compare Source](java-native-access/jna@5.19.0...5.19.1) \============== ## Bug Fixes - [#​1730](java-native-access/jna#1730): Replace usage of `MethodHandle` with reflection to restore support for older Android releases - [@​matthiasblaesing](https://github.com/matthiasblaesing). ### [`v5.19.0`](https://github.com/java-native-access/jna/blob/HEAD/CHANGES.md#Release-5190) [Compare Source](java-native-access/jna@5.18.1...5.19.0) \============== ## Features - [#​1696](java-native-access/jna#1696): Add `LARGE_INTEGER.ByValue` to `LARGE_INTEGER` in `WinNT.java` - [@​baier233](https://github.com/baier233). - [#​1697](java-native-access/jna#1697): Add WlanApi module - [@​eranl](https://github.com/eranl). - [#​1718](java-native-access/jna#1718): Add `Cups` to `c.s.j.p.unix` providing CUPS printing system bindings for destinations, jobs, options, and server configuration - [@​dbwiddis](https://github.com/dbwiddis). - [#​1720](java-native-access/jna#1720): Add `groupCount` and `groupMasks` fields to `CACHE_RELATIONSHIP` in `c.s.j.p.win32.WinNT`, matching the updated Windows struct layout - [@​dbwiddis](https://github.com/dbwiddis). - [#​1719](java-native-access/jna#1719): Add `CoreGraphics` to `c.s.j.p.mac` with Quartz Window Services and Display Services bindings; implement `getAllWindows()` in `MacWindowUtils` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1723](java-native-access/jna#1723): Add `ProcFdInfo`, `InSockInfo`, `TcpSockInfo`, `proc_pidfdinfo`, `statfs64`, and `vm_deallocate` to `c.s.j.p.mac.SystemB` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1725](java-native-access/jna#1725): Add `BluetoothApis` to `c.s.j.p.win32` providing Bluetooth device and radio enumeration via `BluetoothFindFirstRadio`, `BluetoothFindFirstDevice`, and related functions - [@​dbwiddis](https://github.com/dbwiddis). ## Bug Fixes - [#​1644](java-native-access/jna#1644): Fix bug in VARDESC and TYPEDESC causing an illegal memory access - [@​lwahonen](https://github.com/lwahonen) - [#​1715](java-native-access/jna#1715): Fix `UdevDevice.getSysname()` calling `udev_device_get_syspath` instead of `udev_device_get_sysname` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1721](java-native-access/jna#1721): Fix switched `serverName`/`domainName` arguments in `Netapi32Util#getDCName` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1722](java-native-access/jna#1722): Fix `Advapi32#RegisterServiceCtrlHandler` using wrong `Handler` type - [@​dbwiddis](https://github.com/dbwiddis). - [#​1636](java-native-access/jna#1636): Drop hard dependency on java.lang.SecurityManager/java.security.AccessController - [@​matthiasblaesing](https://github.com/matthiasblaesing). - [#​1724](java-native-access/jna#1724): Fix `host_page_size` in `c.s.j.p.mac.SystemB` and `getxattr`/`setxattr`/`listxattr` in `c.s.j.p.mac.XAttr` using `long` instead of pointer-sized types for `size_t`/`ssize_t` parameters - [@​dbwiddis](https://github.com/dbwiddis). - [#​1727](java-native-access/jna#1727): Include DragonFlyBSD in `NativeLibrary` versioned library resolution, libc special-case loading, and 64-bit search paths - [@​dbwiddis](https://github.com/dbwiddis). - [#​1709](java-native-access/jna#1709): Rebuild native library for OpenBSD 7.9 x86-64, drop OpenBSD x86 - [@​matthiasblaesing](https://github.com/matthiasblaesing). </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - "before 9am on tuesday" - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMzMuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjE3NS4xIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==--> Reviewed-on: https://code.futo.org/harbor/harbor/pulls/1820 Reviewed-by: Mark Harding <[email protected]>
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