diff --git a/CHANGES.md b/CHANGES.md index c7c5c2551..385b9eca6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ Features Bug Fixes --------- +* [#1745](https://github.com/java-native-access/jna/issues/1745): Add correctly typed `User32.SetCursorPos(int, int)` mapping and deprecate the previous `long` overload, retained for binary compatibility - [@OKAN-SOFTWARE](https://github.com/OKAN-SOFTWARE). * [#1740](https://github.com/java-native-access/jna/issues/1740): Fix `c.s.j.p.unix.solaris.LibKstat.KstatCtl` mapping `kc_chain` as an inline `Kstat` instead of a pointer, which made every call taking a `KstatCtl` write past the end of the structure `kstat_open()` allocated, and map the `Kstat` function pointers `ks_update` and `ks_snapshot` as `Pointer` instead of `int` - [@dbwiddis](https://github.com/dbwiddis). Breaking Changes diff --git a/contrib/platform/src/com/sun/jna/platform/win32/User32.java b/contrib/platform/src/com/sun/jna/platform/win32/User32.java index a1e43aada..ec6387980 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/User32.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/User32.java @@ -2326,6 +2326,21 @@ LRESULT SendMessageTimeout(HWND hWnd, int msg, WPARAM wParam, LPARAM lParam, * Returns nonzero if successful or zero otherwise. To get extended * error information, call GetLastError. */ + boolean SetCursorPos(int x, int y); + + /** + * Moves the cursor to the specified screen coordinates. + * + * @param x + * The new x-coordinate of the cursor. + * @param y + * The new y-coordinate of the cursor. + * @return Whether the call succeeded. + * @deprecated Windows expects 32-bit coordinates, so this declaration has + * the wrong calling convention on 32-bit Windows. Use + * {@link #SetCursorPos(int, int)} instead. + */ + @Deprecated boolean SetCursorPos(long x, long y); /** diff --git a/contrib/platform/test/com/sun/jna/platform/win32/User32Test.java b/contrib/platform/test/com/sun/jna/platform/win32/User32Test.java index 38f82beaa..e5275d76a 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/User32Test.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/User32Test.java @@ -110,7 +110,9 @@ public void testNoDuplicateMethodsNames() { // has 2 overloads since the original API accepts both MONITORINFO and MONITORINFOEX "GetMonitorInfo" // has 2 overloads since there was a broken binding for MonitorFromPoint , - "MonitorFromPoint" + "MonitorFromPoint", + // Keep the deprecated long overload for binary compatibility. + "SetCursorPos" }) { dupSet.remove(name); } @@ -413,6 +415,14 @@ public void testGetCursorPos() { assertTrue("Y coordinate in POINT should be >= 0", cursorPos.y >= 0); } + @Test + public void testSetCursorPosNativeSignature() throws NoSuchMethodException { + assertEquals(boolean.class, + User32.class.getMethod("SetCursorPos", int.class, int.class).getReturnType()); + assertTrue(User32.class.getMethod("SetCursorPos", long.class, long.class) + .isAnnotationPresent(Deprecated.class)); + } + @Test public void testSetCursorPos() { POINT cursorPos = new POINT(); @@ -432,6 +442,8 @@ public void testSetCursorPos() { ), cursorPos2.x == cursorPos.x + 20 ); + assertEquals("Y coordinate should be preserved after SetCursorPos", + cursorPos.y, cursorPos2.y); } @Test