Skip to content

Commit a254885

Browse files
Merge pull request #1750 from OKAN-SOFTWARE/fix/1745-setcursorpos-int-signature
fix(win32): correct SetCursorPos argument types (#1745)
2 parents c012e67 + 6f7b6ca commit a254885

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎CHANGES.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Features
1111

1212
Bug Fixes
1313
---------
14+
* [#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).
1415
* [#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).
1516

1617
Breaking Changes

‎contrib/platform/src/com/sun/jna/platform/win32/User32.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,6 +2326,21 @@ LRESULT SendMessageTimeout(HWND hWnd, int msg, WPARAM wParam, LPARAM lParam,
23262326
* Returns nonzero if successful or zero otherwise. To get extended
23272327
* error information, call GetLastError.
23282328
*/
2329+
boolean SetCursorPos(int x, int y);
2330+
2331+
/**
2332+
* Moves the cursor to the specified screen coordinates.
2333+
*
2334+
* @param x
2335+
* The new x-coordinate of the cursor.
2336+
* @param y
2337+
* The new y-coordinate of the cursor.
2338+
* @return Whether the call succeeded.
2339+
* @deprecated Windows expects 32-bit coordinates, so this declaration has
2340+
* the wrong calling convention on 32-bit Windows. Use
2341+
* {@link #SetCursorPos(int, int)} instead.
2342+
*/
2343+
@Deprecated
23292344
boolean SetCursorPos(long x, long y);
23302345

23312346
/**

‎contrib/platform/test/com/sun/jna/platform/win32/User32Test.java‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ public void testNoDuplicateMethodsNames() {
110110
// has 2 overloads since the original API accepts both MONITORINFO and MONITORINFOEX
111111
"GetMonitorInfo" // has 2 overloads since there was a broken binding for MonitorFromPoint
112112
,
113-
"MonitorFromPoint"
113+
"MonitorFromPoint",
114+
// Keep the deprecated long overload for binary compatibility.
115+
"SetCursorPos"
114116
}) {
115117
dupSet.remove(name);
116118
}
@@ -413,6 +415,14 @@ public void testGetCursorPos() {
413415
assertTrue("Y coordinate in POINT should be >= 0", cursorPos.y >= 0);
414416
}
415417

418+
@Test
419+
public void testSetCursorPosNativeSignature() throws NoSuchMethodException {
420+
assertEquals(boolean.class,
421+
User32.class.getMethod("SetCursorPos", int.class, int.class).getReturnType());
422+
assertTrue(User32.class.getMethod("SetCursorPos", long.class, long.class)
423+
.isAnnotationPresent(Deprecated.class));
424+
}
425+
416426
@Test
417427
public void testSetCursorPos() {
418428
POINT cursorPos = new POINT();
@@ -432,6 +442,8 @@ public void testSetCursorPos() {
432442
),
433443
cursorPos2.x == cursorPos.x + 20
434444
);
445+
assertEquals("Y coordinate should be preserved after SetCursorPos",
446+
cursorPos.y, cursorPos2.y);
435447
}
436448

437449
@Test

0 commit comments

Comments
 (0)