Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLakshmi Priya Shanmugam2019-01-22 05:51:27 -0500
committerLakshmi Shanmugam2019-04-26 03:56:23 -0400
commit215b2e93a351272e93bda116b9240ee541b38b83 (patch)
tree9edf749f3cff2677fc80199cf3baaf5cae14de4b
parenta0cd09f517e565d002b71faebae71b6162ee0720 (diff)
downloadeclipse.platform.swt-215b2e93a351272e93bda116b9240ee541b38b83.tar.gz
eclipse.platform.swt-215b2e93a351272e93bda116b9240ee541b38b83.tar.xz
eclipse.platform.swt-215b2e93a351272e93bda116b9240ee541b38b83.zip
Bug 540357 - [10.14] Make SWT adapt to switching to dark mode (and back)
The patch sets the appearance of SWT application to dark or light based on the system setting. The patch reads the setting only at startup, changing the system setting dynamically doesn't cause any change in SWT. Change-Id: I0d49f2995f55dae2a6349504a2a63e1c3723319f
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras3
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSAppearance.java5
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java17
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java9
5 files changed, 33 insertions, 2 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras
index 26a9992f71..90fa40ec2d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras
@@ -58,6 +58,9 @@
<arg swt_gen="true"></arg>
<retval swt_gen="true"></retval>
</method>
+ <method class_method="true" selector="currentAppearance" swt_gen="true">
+ <retval swt_gen="true"></retval>
+ </method>
<method selector="name" swt_gen="true">
<retval swt_gen="true"></retval>
</method>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSAppearance.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSAppearance.java
index 172c1a9563..870f4b1ba2 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSAppearance.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSAppearance.java
@@ -32,6 +32,11 @@ public static NSAppearance appearanceNamed(NSString name) {
return result != 0 ? new NSAppearance(result) : null;
}
+public static NSAppearance currentAppearance() {
+ long /*int*/ result = OS.objc_msgSend(OS.class_NSAppearance, OS.sel_currentAppearance);
+ return result != 0 ? new NSAppearance(result) : null;
+}
+
public NSString name() {
long /*int*/ result = OS.objc_msgSend(this.id, OS.sel_name);
return result != 0 ? new NSString(result) : null;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java
index 93cbd45fb4..06e7414bf2 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java
@@ -220,6 +220,22 @@ public class OS extends C {
public static void setTheme(boolean isDarkTheme) {
OS.objc_msgSend(NSApplication.sharedApplication().id, sel_appAppearanceChanged, isDarkTheme ? 1 : 0);
}
+ public static boolean isAppDarkAppearance() {
+ if (OS.VERSION_MMB >= OS.VERSION_MMB(10, 14, 0)) {
+ NSAppearance currentAppearance = NSAppearance.currentAppearance();
+ if (currentAppearance != null) {
+ return "NSAppearanceNameDarkAqua".equals(currentAppearance.name().getString());
+ }
+ }
+ return false;
+ }
+ public static boolean isSystemDarkAppearance() {
+ if (OS.VERSION_MMB >= OS.VERSION_MMB(10, 14, 0)) {
+ NSString osxMode = NSUserDefaults.standardUserDefaults ().stringForKey (NSString.stringWith ("AppleInterfaceStyle"));
+ return osxMode != null && "Dark".equals (osxMode.getString ());
+ }
+ return false;
+ }
/** JNI natives */
@@ -1242,6 +1258,7 @@ public static final long /*int*/ sel_createFileAtPath_contents_attributes_ = Sel
public static final long /*int*/ sel_credentialWithUser_password_persistence_ = Selector.sel_credentialWithUser_password_persistence_.value;
public static final long /*int*/ sel_crosshairCursor = Selector.sel_crosshairCursor.value;
public static final long /*int*/ sel_ctrlKey = Selector.sel_ctrlKey.value;
+public static final long /*int*/ sel_currentAppearance = Selector.sel_currentAppearance.value;
public static final long /*int*/ sel_currentApplication = Selector.sel_currentApplication.value;
public static final long /*int*/ sel_currentContext = Selector.sel_currentContext.value;
public static final long /*int*/ sel_currentCursor = Selector.sel_currentCursor.value;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java
index ccd2053469..ef483afb8e 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java
@@ -354,6 +354,7 @@ public enum Selector {
, sel_credentialWithUser_password_persistence_("credentialWithUser:password:persistence:")
, sel_crosshairCursor("crosshairCursor")
, sel_ctrlKey("ctrlKey")
+ , sel_currentAppearance("currentAppearance")
, sel_currentApplication("currentApplication")
, sel_currentContext("currentContext")
, sel_currentCursor("currentCursor")
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
index 84c4a40b40..7f996ebb9f 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
@@ -110,7 +110,7 @@ public class Display extends Device {
enum APPEARANCE {
Dark, Light,
}
- APPEARANCE appAppearance = null;
+ APPEARANCE appAppearance;
/* Windows and Events */
Event [] eventQueue;
@@ -1897,7 +1897,7 @@ double /*float*/ [] getWidgetColorRGB (int id) {
break;
case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: color = NSColor.controlLightHighlightColor(); break;
case SWT.COLOR_WIDGET_BACKGROUND:
- color = OS.VERSION_MMB >= OS.VERSION_MMB (10, 14, 0) ? NSColor.windowBackgroundColor()
+ color = OS.VERSION_MMB >= OS.VERSION_MMB (10, 14, 0) ? NSColor.controlBackgroundColor()
: NSColor.controlHighlightColor();
break;
case SWT.COLOR_WIDGET_FOREGROUND: color = NSColor.controlTextColor(); break;
@@ -2224,6 +2224,11 @@ boolean hasDefaultButton () {
@Override
protected void init () {
super.init ();
+
+ if (OS.isSystemDarkAppearance()) {
+ setAppAppearance(APPEARANCE.Dark);
+ }
+
initClasses ();
initColors ();
initFonts ();

Back to the top