Browse Source

Windows: Allow changing the window border radius for popups

pull/336/head
Jannis Weis 2 years ago
parent
commit
20ae893d2b
No known key found for this signature in database
GPG Key ID: 7C9D8D4B558049AB
  1. 3
      platform-base/src/main/java/com/github/weisj/darklaf/platform/DecorationsConstants.java
  2. 10
      windows/src/main/cpp/Decorations.cpp
  3. 4
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java
  4. 13
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsDecorationsProvider.java

3
platform-base/src/main/java/com/github/weisj/darklaf/platform/DecorationsConstants.java

@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2022 Jannis Weis
* Copyright (c) 2022-2023 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
@ -28,4 +28,5 @@ public interface DecorationsConstants {
String KEY_UNIFIED_MENUBAR = "JRootPane.unifiedMenuBar";
String KEY_COLORED_TITLE_BAR = "JRootPane.coloredTitleBar";
String KEY_HIDE_TITLE = "JRootPane.hideTitle";
String KEY_WINDOWS_SMALL_CORNER_RADIUS = "JRootPane.windows.smallCornerRadius";
}

10
windows/src/main/cpp/Decorations.cpp

@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2019-2022 Jannis Weis
* Copyright (c) 2019-2023 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
@ -316,14 +316,14 @@ static void SetupWindowStyle(HWND handle) {
SetWindowLongPtr(handle, GWL_STYLE, style);
}
static bool InstallDecorations(HWND handle, bool is_popup) {
static bool InstallDecorations(HWND handle, bool is_popup, bool use_small_corner_arc = false) {
// Prevent multiple installations overriding the real window procedure.
auto it = wrapper_map.find(handle);
if (it != wrapper_map.end()) return false;
SetupWindowStyle(handle);
ExtendClientFrame(handle);
if (is_popup) {
if (use_small_corner_arc) {
auto attribute = DWMWINDOWATTRIBUTE::DWMWA_WINDOW_CORNER_PREFERENCE;
auto preference = DWM_WINDOW_CORNER_PREFERENCE::DWMWCP_ROUNDSMALL;
DwmSetWindowAttribute(handle, attribute, &preference, sizeof(preference));
@ -509,9 +509,9 @@ Java_com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows_uninstallDe
}
JNIEXPORT jboolean JNICALL
Java_com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows_installPopupMenuDecorations(JNIEnv*, jclass, jlong hwnd) {
Java_com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows_installPopupMenuDecorations(JNIEnv*, jclass, jlong hwnd, jboolean useSmallCornerArc) {
HWND handle = reinterpret_cast<HWND>(hwnd);
return static_cast<jboolean>(InstallDecorations(handle, true));
return static_cast<jboolean>(InstallDecorations(handle, true, useSmallCornerArc));
}
//Window functions.

4
windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java

@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2019-2021 Jannis Weis
* Copyright (c) 2019-2023 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
@ -48,7 +48,7 @@ public final class JNIDecorationsWindows {
public static native void uninstallDecorations(final long hwnd, final boolean decorated);
public static native boolean installPopupMenuDecorations(final long hwnd);
public static native boolean installPopupMenuDecorations(final long hwnd, final boolean useSmallCornerArc);
public static native void init();

13
windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsDecorationsProvider.java

@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2019-2022 Jannis Weis
* Copyright (c) 2019-2023 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
@ -29,6 +29,7 @@ import javax.swing.border.Border;
import com.github.weisj.darklaf.platform.*;
import com.github.weisj.darklaf.platform.windows.ui.WindowsTitlePane;
import com.github.weisj.darklaf.util.PropertyUtil;
public class WindowsDecorationsProvider implements DecorationsProvider {
@ -61,7 +62,9 @@ public class WindowsDecorationsProvider implements DecorationsProvider {
}
PointerUtil.WindowPointer hwnd = PointerUtil.getHWND(window);
if (hwnd.isValid()) {
JNIDecorationsWindows.installPopupMenuDecorations(hwnd.value());
JNIDecorationsWindows.installPopupMenuDecorations(hwnd.value(),
useSmallCornerRadiusForWindow(window));
if (window instanceof RootPaneContainer) {
JRootPane rootPane = ((RootPaneContainer) window).getRootPane();
Color bg = rootPane != null ? rootPane.getBackground() : null;
@ -72,6 +75,12 @@ public class WindowsDecorationsProvider implements DecorationsProvider {
}
}
private boolean useSmallCornerRadiusForWindow(final Window w) {
if (!(w instanceof RootPaneContainer)) return false;
return PropertyUtil.getBooleanProperty(((RootPaneContainer) w).getRootPane(),
DecorationsConstants.KEY_WINDOWS_SMALL_CORNER_RADIUS, true);
}
@Override
public void uninstallPopupWindow(final Window window) {
if (window.isDisplayable()) {

Loading…
Cancel
Save