diff --git a/CHANGELOG.md b/CHANGELOG.md index 67cb672b..7b9e2745 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,8 @@ FlatLaf Change Log updated when table width changed and was painted on wrong side in right-to-left component orientation). - Theme Editor: Fixed occasional empty window on startup on macOS. +- FlatLaf window decorations: Fixed black line sometimes painted on top of + (native) window border on Windows 11. (issue #852) #### Incompatibilities diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/flatlaf-windows-arm64.dll b/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/flatlaf-windows-arm64.dll index ea7d69bd..b91c3210 100644 Binary files a/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/flatlaf-windows-arm64.dll and b/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/flatlaf-windows-arm64.dll differ diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/flatlaf-windows-x86.dll b/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/flatlaf-windows-x86.dll index 37c592cd..ba214bf0 100644 Binary files a/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/flatlaf-windows-x86.dll and b/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/flatlaf-windows-x86.dll differ diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/flatlaf-windows-x86_64.dll b/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/flatlaf-windows-x86_64.dll index d3ccf1b6..d4e2233a 100644 Binary files a/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/flatlaf-windows-x86_64.dll and b/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/flatlaf-windows-x86_64.dll differ diff --git a/flatlaf-natives/flatlaf-natives-jna/src/main/java/com/formdev/flatlaf/natives/jna/windows/FlatWindowsNativeWindowBorder.java b/flatlaf-natives/flatlaf-natives-jna/src/main/java/com/formdev/flatlaf/natives/jna/windows/FlatWindowsNativeWindowBorder.java index bdf31aa7..77dac5cb 100644 --- a/flatlaf-natives/flatlaf-natives-jna/src/main/java/com/formdev/flatlaf/natives/jna/windows/FlatWindowsNativeWindowBorder.java +++ b/flatlaf-natives/flatlaf-natives-jna/src/main/java/com/formdev/flatlaf/natives/jna/windows/FlatWindowsNativeWindowBorder.java @@ -60,8 +60,11 @@ import com.sun.jna.platform.win32.WinDef.LRESULT; import com.sun.jna.platform.win32.WinDef.RECT; import com.sun.jna.platform.win32.WinDef.UINT_PTR; import com.sun.jna.platform.win32.WinDef.WPARAM; +import com.sun.jna.platform.win32.WinError; import com.sun.jna.platform.win32.WinUser.HMONITOR; import com.sun.jna.platform.win32.WinUser.WindowProc; +import com.sun.jna.ptr.IntByReference; +import com.sun.jna.win32.StdCallLibrary; import com.sun.jna.win32.W32APIOptions; // @@ -615,6 +618,14 @@ public class FlatWindowsNativeWindowBorder if( hasAutohideTaskbar( ABE_RIGHT, monitorInfo.rcMonitor ) ) params.rgrc[0].right--; } + } else if( SystemInfo.isWindows_11_orLater ) { + // For Windows 11, add border thickness to top, which is necessary to make the whole Java area visible. + // This also avoids that a black line is sometimes painted on top window border. + // Note: Do not increase top on Windows 10 because this would not hide Windows title bar. + IntByReference borderThickness = new IntByReference(); + if( DWMApi.INSTANCE.DwmGetWindowAttribute( hwnd, DWMApi.DWMWA_VISIBLE_FRAME_BORDER_THICKNESS, + borderThickness.getPointer(), 4 ) == WinError.S_OK.intValue() ) + params.rgrc[0].top += borderThickness.getValue(); } // write changed params back to native memory @@ -898,6 +909,18 @@ public class FlatWindowsNativeWindowBorder HBRUSH CreateSolidBrush( DWORD color ); } + //---- interface DWMApi --------------------------------------------------- + + private interface DWMApi + extends StdCallLibrary + { + DWMApi INSTANCE = Native.load( "dwmapi", DWMApi.class, W32APIOptions.DEFAULT_OPTIONS ); + + int DWMWA_VISIBLE_FRAME_BORDER_THICKNESS = 37; + + int DwmGetWindowAttribute( HWND hwnd, int dwAttribute, Pointer pvAttribute, int cbAttribute ); + } + //---- class NCCALCSIZE_PARAMS -------------------------------------------- @FieldOrder( { "rgrc" } ) diff --git a/flatlaf-natives/flatlaf-natives-windows/src/main/cpp/FlatWndProc.cpp b/flatlaf-natives/flatlaf-natives-windows/src/main/cpp/FlatWndProc.cpp index 8af6061b..6ce6af91 100644 --- a/flatlaf-natives/flatlaf-natives-windows/src/main/cpp/FlatWndProc.cpp +++ b/flatlaf-natives/flatlaf-natives-windows/src/main/cpp/FlatWndProc.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include "FlatWndProc.h" @@ -76,6 +77,7 @@ jmethodID FlatWndProc::isFullscreenMID; jmethodID FlatWndProc::fireStateChangedLaterOnceMID; HWNDMap* FlatWndProc::hwndMap; +DWORD FlatWndProc::osBuildNumber = 0; #define java_awt_Frame_ICONIFIED 1 #define java_awt_Frame_MAXIMIZED_BOTH (4 | 2) @@ -107,6 +109,14 @@ HWND FlatWndProc::install( JNIEnv *env, jobject obj, jobject window ) { return 0; } + // get OS build number + if( osBuildNumber == 0 ) { + OSVERSIONINFO info; + info.dwOSVersionInfoSize = sizeof( info ); + if( ::GetVersionEx( &info ) ) + osBuildNumber = info.dwBuildNumber; + } + // get window handle HWND hwnd = getWindowHandle( env, window ); if( hwnd == NULL || hwndMap->get( hwnd ) != NULL ) @@ -391,6 +401,13 @@ LRESULT FlatWndProc::WmNcCalcSize( HWND hwnd, int uMsg, WPARAM wParam, LPARAM lP if( hasAutohideTaskbar( ABE_RIGHT, monitorInfo.rcMonitor ) ) params->rgrc[0].right--; } + } else if( osBuildNumber >= 22000 ) { + // For Windows 11, add border thickness to top, which is necessary to make the whole Java area visible. + // This also avoids that a black line is sometimes painted on top window border. + // Note: Do not increase top on Windows 10 because this would not hide Windows title bar. + UINT borderThickness = 0; + if( ::DwmGetWindowAttribute( hwnd, DWMWA_VISIBLE_FRAME_BORDER_THICKNESS, &borderThickness, sizeof( borderThickness ) ) == S_OK ) + params->rgrc[0].top += borderThickness; } return lResult; diff --git a/flatlaf-natives/flatlaf-natives-windows/src/main/cpp/FlatWndProc.h b/flatlaf-natives/flatlaf-natives-windows/src/main/cpp/FlatWndProc.h index 96e255d1..a5870f94 100644 --- a/flatlaf-natives/flatlaf-natives-windows/src/main/cpp/FlatWndProc.h +++ b/flatlaf-natives/flatlaf-natives-windows/src/main/cpp/FlatWndProc.h @@ -35,6 +35,7 @@ private: static jmethodID fireStateChangedLaterOnceMID; static HWNDMap* hwndMap; + static DWORD osBuildNumber; JavaVM* jvm; JNIEnv* env; // attached to AWT-Windows/Win32 thread