Window decorations: fixed black line sometimes painted on top of (native) window border on Windows 11 (issue #852)

Windows binaries built and signed locally in clean workspace
This commit is contained in:
Karl Tauber
2024-06-21 19:58:36 +02:00
parent c95e95ef67
commit 72a4c00e72
7 changed files with 43 additions and 0 deletions

View File

@@ -20,6 +20,7 @@
#include <windows.h>
#include <windowsx.h>
#include <shellapi.h>
#include <dwmapi.h>
#include <jawt.h>
#include <jawt_md.h>
#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;

View File

@@ -35,6 +35,7 @@ private:
static jmethodID fireStateChangedLaterOnceMID;
static HWNDMap* hwndMap;
static DWORD osBuildNumber;
JavaVM* jvm;
JNIEnv* env; // attached to AWT-Windows/Win32 thread