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

Fixed Dark Mode detection on macOS #1972

Merged
Merged
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
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2023 Lablicate GmbH.
* Copyright (c) 2017, 2024 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -14,9 +14,14 @@
import java.util.ArrayList;
import java.util.List;

import org.eclipse.chemclipse.support.settings.OperatingSystemUtils;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.preference.IPreferenceNode;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;

public class PreferencesSupport {
Expand All @@ -36,7 +41,13 @@ public static void cleanPreferencesByNodeId(List<String> preservePreferenceNodes
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=564022
public static boolean isDarkTheme() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you mean "isDarkSystemTheme" here? If so, then I believe the new strategy should be the default one for most OSs, and Windows would be the exception as it basically doesn't set system colors.

return Platform.getPreferencesService().getString("org.eclipse.e4.ui.css.swt.theme", "themeid", "", null).endsWith("dark");
if(OperatingSystemUtils.isMac()) {
Color background = Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
RGB rgb = background.getRGB();
return (rgb.red < 128 && rgb.green < 128 && rgb.blue < 128);
} else {
return Platform.getPreferencesService().getString("org.eclipse.e4.ui.css.swt.theme", "themeid", "", null).endsWith("dark");
}
}

/**
Expand Down