Skip to content

Commit 8a135d1

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 8a135d1

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,7 @@ public class OS extends C {
18621862
public static final int WM_XBUTTONDBLCLK = 0x020D;
18631863
public static final int XBUTTON1 = 0x1;
18641864
public static final int XBUTTON2 = 0x2;
1865+
public static final int DWMWA_EXTENDED_FRAME_BOUNDS = 9;
18651866

18661867
public static int VERSION (int major, int minor) {
18671868
return major << 16 | minor;
@@ -3022,6 +3023,10 @@ 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+
/**
3027+
* @param hwnd cast=(HWND)
3028+
* */
3029+
public static final native int DwmGetWindowAttribute (long hwnd, int dwAttribute, RECT pvAttribute, int cbAttribute);
30253030
/**
30263031
* @param hWnd cast=(HWND)
30273032
* @param hRgn cast=(HRGN)

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,9 +1015,13 @@ 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+
OS.GetWindowRect(handle, rect);
1020+
int hr = OS.DwmGetWindowAttribute(handle, OS.DWMWA_EXTENDED_FRAME_BOUNDS, rect, RECT.sizeof);
1021+
if (hr != 0) {
1022+
OS.GetWindowRect(handle, rect);
1023+
}
1024+
return new Point(rect.left, rect.top);
10211025
}
10221026

10231027
@Override

0 commit comments

Comments
 (0)