Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlatLaf: Enable Window decoration option for Linux #6391

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@

package org.netbeans.swing.laf.flatlaf;

import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale;
import java.awt.Color;
import java.awt.Font;
import java.awt.Insets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
import javax.swing.BorderFactory;
import javax.swing.InputMap;
import javax.swing.JFrame;
import javax.swing.KeyStroke;
import javax.swing.UIDefaults;
import javax.swing.UIDefaults.LazyValue;
Expand Down Expand Up @@ -151,6 +154,10 @@ EDITOR_TOOLBAR_BORDER, new CompoundBorder(DPISafeBorder.matte(0, 0, 1, 0, editor
}
}
}
if (SystemInfo.isLinux) {
result.add("windowDefaultLookAndFeelDecorated");
result.add(FlatLafPrefs.isUseWindowDecorations());
}
return result.toArray();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.netbeans.swing.laf.flatlaf;

import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatLightLaf;
import com.formdev.flatlaf.util.SystemInfo;
import java.awt.Color;
import java.io.BufferedWriter;
Expand Down Expand Up @@ -52,7 +53,8 @@
public class FlatLafOptionsPanel extends javax.swing.JPanel {

private static final Color DEFAULT = new Color(0, true);
private static final Color currentAccentColor = FlatLafPrefs.getAccentColor();
private static final Color currentAccentColor = getPrefsAccentColorOrDefault();
private static final boolean currentUseWindowDecorations = FlatLafPrefs.isUseWindowDecorations();

private static final RequestProcessor RP = new RequestProcessor(FlatLafOptionsPanel.class);

Expand Down Expand Up @@ -108,7 +110,7 @@ private void initAccentColor() {
}

private void updateEnabled() {
boolean supportsWindowDecorations = FlatLaf.supportsNativeWindowDecorations();
boolean supportsWindowDecorations = FlatLaf.supportsNativeWindowDecorations() || new FlatLightLaf().getSupportsWindowDecorations();
useWindowDecorationsCheckBox.setEnabled(supportsWindowDecorations);
unifiedTitleBarCheckBox.setEnabled(supportsWindowDecorations && useWindowDecorationsCheckBox.isSelected());
menuBarEmbeddedCheckBox.setEnabled(supportsWindowDecorations && useWindowDecorationsCheckBox.isSelected());
Expand Down Expand Up @@ -341,7 +343,8 @@ protected boolean store() {
FlatLafPrefs.setUnderlineMenuSelection(underlineMenuSelectionCheckBox.isSelected());
FlatLafPrefs.setAlwaysShowMnemonics(alwaysShowMnemonicsCheckBox.isSelected());

if (!Objects.equals(accentColor, currentAccentColor)) {
if (!Objects.equals(accentColor, currentAccentColor)
|| SystemInfo.isLinux && useWindowDecorationsCheckBox.isSelected() != currentUseWindowDecorations) {
askForRestart();
}
return false;
Expand All @@ -368,7 +371,7 @@ private void askForRestart() {
NotificationDisplayer.Priority.NORMAL, NotificationDisplayer.Category.INFO);
}

private Color getPrefsAccentColorOrDefault() {
private static Color getPrefsAccentColorOrDefault() {
Color accentColor = FlatLafPrefs.getAccentColor();
return accentColor != null ? accentColor : DEFAULT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.netbeans.swing.laf.flatlaf;

import com.formdev.flatlaf.util.SystemInfo;
import java.awt.Color;
import java.util.prefs.Preferences;
import org.openide.util.NbPreferences;
Expand All @@ -37,6 +38,8 @@ class FlatLafPrefs {

private static final Preferences prefs = NbPreferences.forModule(FlatLafPrefs.class);

private static final boolean DEF_USE_WINDOW_DECORATIONS = SystemInfo.isWindows_10_orLater;
eirikbakke marked this conversation as resolved.
Show resolved Hide resolved

static Color getAccentColor() {
return parseColor(prefs.get(ACCENT_COLOR, null));
}
Expand All @@ -60,11 +63,11 @@ static void setAccentColor(Color accentColor) {
}

static boolean isUseWindowDecorations() {
return prefs.getBoolean(USE_WINDOW_DECORATIONS, true);
return prefs.getBoolean(USE_WINDOW_DECORATIONS, DEF_USE_WINDOW_DECORATIONS);
}

static void setUseWindowDecorations(boolean value) {
putBoolean(USE_WINDOW_DECORATIONS, value, true);
putBoolean(USE_WINDOW_DECORATIONS, value, DEF_USE_WINDOW_DECORATIONS);
}

static boolean isUnifiedTitleBar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ private void installLFCustoms (LFCustoms customs) {
defaults.putDefaults (customs.getLookAndFeelCustomizationKeysAndValues());
}

if (defaults.getBoolean("windowDefaultLookAndFeelDecorated")) {
JFrame.setDefaultLookAndFeelDecorated(true);
}
}

private void runPostInstall() {
Expand Down