Skip to content

Commit a4ebaa5

Browse files
Use DwmGetWindowAttribute for Shell#getLocation to avoid shadow margins
GetWindowRect includes invisible shadow borders on Windows 10/11, causing Shell#getLocation to return coordinates offset by ~9px from the visible frame. Replaced with DwmGetWindowAttribute(DWMWA_EXTENDED_FRAME_BOUNDS) to report the true window bounds in screen space, with GetWindowRect as a fallback if DWM is unavailable.
1 parent a641cdb commit a4ebaa5

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
11-
* Contributors:
12-
* IBM Corporation - initial API and implementation
1310
*******************************************************************************/
1411

1512
/* Note: This file was auto-generated by org.eclipse.swt.tools.internal.JNIGenerator */
@@ -1513,6 +1510,22 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(DuplicateHandle)
15131510
}
15141511
#endif
15151512

1513+
#ifndef NO_DwmGetWindowAttribute
1514+
JNIEXPORT jint JNICALL OS_NATIVE(DwmGetWindowAttribute)
1515+
(JNIEnv *env, jclass that, jlong arg0, jint arg1, jobject arg2, jint arg3)
1516+
{
1517+
RECT _arg2, *lparg2=NULL;
1518+
jint rc = 0;
1519+
OS_NATIVE_ENTER(env, that, DwmGetWindowAttribute_FUNC);
1520+
if (arg2) if ((lparg2 = getRECTFields(env, arg2, &_arg2)) == NULL) goto fail;
1521+
rc = (jint)DwmGetWindowAttribute((HWND)arg0, arg1, lparg2, arg3);
1522+
fail:
1523+
if (arg2 && lparg2) setRECTFields(env, arg2, lparg2);
1524+
OS_NATIVE_EXIT(env, that, DwmGetWindowAttribute_FUNC);
1525+
return rc;
1526+
}
1527+
#endif
1528+
15161529
#ifndef NO_DwmSetWindowAttribute
15171530
JNIEXPORT jboolean JNICALL OS_NATIVE(DwmSetWindowAttribute)
15181531
(JNIEnv *env, jclass that, jlong arg0, jint arg1, jintArray arg2, jint arg3)

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
11-
* Contributors:
12-
* IBM Corporation - initial API and implementation
1310
*******************************************************************************/
1411

1512
/* Note: This file was auto-generated by org.eclipse.swt.tools.internal.JNIGenerator */
@@ -133,6 +130,7 @@ typedef enum {
133130
DrawThemeBackground_FUNC,
134131
DrawThemeText_FUNC,
135132
DuplicateHandle_FUNC,
133+
DwmGetWindowAttribute_FUNC,
136134
DwmSetWindowAttribute_FUNC,
137135
EMREXTCREATEFONTINDIRECTW_1sizeof_FUNC,
138136
EMR_1sizeof_FUNC,

bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ public class OS extends C {
380380
public static final int DTS_SHORTDATEFORMAT = 0x0000;
381381
public static final int DTS_TIMEFORMAT = 0x0009;
382382
public static final int DTS_UPDOWN = 0x0001;
383+
public static final int DWMWA_EXTENDED_FRAME_BOUNDS = 9;
383384
public static final int E_POINTER = 0x80004003;
384385
public static final int EBP_NORMALGROUPBACKGROUND = 5;
385386
public static final int EBP_NORMALGROUPCOLLAPSE = 6;
@@ -3022,6 +3023,8 @@ public static int HRESULT_FROM_WIN32(int x) {
30223023
public static final native boolean GetWindowPlacement (long hWnd, WINDOWPLACEMENT lpwndpl);
30233024
/** @param hWnd cast=(HWND) */
30243025
public static final native boolean GetWindowRect (long hWnd, RECT lpRect);
3026+
/** @param hwnd cast=(HWND) */
3027+
public static final native int DwmGetWindowAttribute (long hwnd, int dwAttribute, RECT pvAttribute, int cbAttribute);
30253028
/**
30263029
* @param hWnd cast=(HWND)
30273030
* @param hRgn cast=(HRGN)

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,9 +1015,12 @@ public int getImeInputMode () {
10151015

10161016
@Override Point getLocationInPixels () {
10171017
if (OS.IsIconic (handle)) return super.getLocationInPixels ();
1018-
RECT rect = new RECT ();
1019-
OS.GetWindowRect (handle, rect);
1020-
return new Point (rect.left, rect.top);
1018+
RECT rect = new RECT();
1019+
int hr = OS.DwmGetWindowAttribute(handle, OS.DWMWA_EXTENDED_FRAME_BOUNDS, rect, RECT.sizeof);
1020+
if (hr != 0) {
1021+
OS.GetWindowRect(handle, rect);
1022+
}
1023+
return new Point(rect.left, rect.top);
10211024
}
10221025

10231026
@Override

0 commit comments

Comments
 (0)