diff --git a/binaries/org.eclipse.swt.cocoa.macosx.aarch64/.settings/.api_filters b/binaries/org.eclipse.swt.cocoa.macosx.aarch64/.settings/.api_filters index 263c1ef9bd..a7c6971eeb 100644 --- a/binaries/org.eclipse.swt.cocoa.macosx.aarch64/.settings/.api_filters +++ b/binaries/org.eclipse.swt.cocoa.macosx.aarch64/.settings/.api_filters @@ -242,12 +242,4 @@ - - - - - - - - diff --git a/binaries/org.eclipse.swt.cocoa.macosx.x86_64/.settings/.api_filters b/binaries/org.eclipse.swt.cocoa.macosx.x86_64/.settings/.api_filters index c730e78b64..ace860e848 100644 --- a/binaries/org.eclipse.swt.cocoa.macosx.x86_64/.settings/.api_filters +++ b/binaries/org.eclipse.swt.cocoa.macosx.x86_64/.settings/.api_filters @@ -242,12 +242,4 @@ - - - - - - - - diff --git a/binaries/org.eclipse.swt.gtk.linux.aarch64/.settings/.api_filters b/binaries/org.eclipse.swt.gtk.linux.aarch64/.settings/.api_filters index f1fd76d8fc..445157d2fb 100644 --- a/binaries/org.eclipse.swt.gtk.linux.aarch64/.settings/.api_filters +++ b/binaries/org.eclipse.swt.gtk.linux.aarch64/.settings/.api_filters @@ -250,12 +250,4 @@ - - - - - - - - diff --git a/binaries/org.eclipse.swt.gtk.linux.ppc64le/.settings/.api_filters b/binaries/org.eclipse.swt.gtk.linux.ppc64le/.settings/.api_filters index d426bbdcd1..cf85cec583 100644 --- a/binaries/org.eclipse.swt.gtk.linux.ppc64le/.settings/.api_filters +++ b/binaries/org.eclipse.swt.gtk.linux.ppc64le/.settings/.api_filters @@ -250,12 +250,4 @@ - - - - - - - - diff --git a/binaries/org.eclipse.swt.gtk.linux.riscv64/.settings/.api_filters b/binaries/org.eclipse.swt.gtk.linux.riscv64/.settings/.api_filters index 360928ecea..95adbe43e1 100644 --- a/binaries/org.eclipse.swt.gtk.linux.riscv64/.settings/.api_filters +++ b/binaries/org.eclipse.swt.gtk.linux.riscv64/.settings/.api_filters @@ -250,12 +250,4 @@ - - - - - - - - diff --git a/binaries/org.eclipse.swt.gtk.linux.x86_64/.settings/.api_filters b/binaries/org.eclipse.swt.gtk.linux.x86_64/.settings/.api_filters index 51aea13b79..e8ceeb035e 100644 --- a/binaries/org.eclipse.swt.gtk.linux.x86_64/.settings/.api_filters +++ b/binaries/org.eclipse.swt.gtk.linux.x86_64/.settings/.api_filters @@ -242,12 +242,4 @@ - - - - - - - - diff --git a/binaries/org.eclipse.swt.win32.win32.aarch64/.settings/.api_filters b/binaries/org.eclipse.swt.win32.win32.aarch64/.settings/.api_filters index c5d11ec407..ac0e9574b9 100644 --- a/binaries/org.eclipse.swt.win32.win32.aarch64/.settings/.api_filters +++ b/binaries/org.eclipse.swt.win32.win32.aarch64/.settings/.api_filters @@ -361,12 +361,4 @@ - - - - - - - - diff --git a/binaries/org.eclipse.swt.win32.win32.x86_64/.settings/.api_filters b/binaries/org.eclipse.swt.win32.win32.x86_64/.settings/.api_filters index 3773537c75..53c577d6a5 100644 --- a/binaries/org.eclipse.swt.win32.win32.x86_64/.settings/.api_filters +++ b/binaries/org.eclipse.swt.win32.win32.x86_64/.settings/.api_filters @@ -361,12 +361,4 @@ - - - - - - - - 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 3913a9c9ab..7159b83344 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 @@ -1774,6 +1774,20 @@ public static boolean isSystemDarkTheme () { return OS.isSystemDarkAppearance(); } +/** + * Informs the operating system that the application prefers a dark + * theme for native components such as title bars, scrollbars, and + * native dialogs. + * + * @param preferred true if the dark theme is preferred, false otherwise. + * + * @since 3.134 + */ +public void setDarkThemePreferred(boolean preferred) { + checkDevice(); + OS.setTheme(preferred); +} + int getLastEventTime () { NSEvent event = application != null ? application.currentEvent() : null; if (event == null) return 0; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java index 51e61b97dd..ed25785495 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java @@ -2063,6 +2063,26 @@ void setScrolling () { view.performSelector(OS.sel_clearDeferFlushing, null, 0.0, display.runLoopModes()); } +/** + * Informs the operating system that the application prefers a dark + * theme for native components such as title bars, scrollbars, and + * native dialogs. + * + * @param preferred true if the dark theme is preferred, false otherwise. + * + * @since 3.134 + */ +public void setDarkThemePreferred(boolean preferred) { + checkWidget(); + if (OS.VERSION < OS.VERSION (10, 14, 0)) return; + if (window == null) return; + String appearanceName = preferred ? "NSAppearanceNameDarkAqua" : "NSAppearanceNameAqua"; + NSAppearance appearance = NSAppearance.appearanceNamed (NSString.stringWith (appearanceName)); + if (appearance != null) { + OS.objc_msgSend(window.id, OS.sel_setAppearance_, appearance.id); + } +} + @Override public void setText (String string) { checkWidget(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java index 23b874a09e..d87e9e8815 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java @@ -2619,6 +2619,20 @@ public static boolean isSystemDarkTheme () { return themeDark; } +/** + * Informs the operating system that the application prefers a dark + * theme for native components such as title bars, scrollbars, and + * native dialogs. + * + * @param preferred true if the dark theme is preferred, false otherwise. + * + * @since 3.134 + */ +public void setDarkThemePreferred(boolean preferred) { + checkDevice(); + OS.setTheme(preferred); +} + int getLastEventTime () { return lastEventTime; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java index 9294965770..98eb4eff3f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java @@ -2879,6 +2879,20 @@ static Region mirrorRegion (Region region) { void setRelations() { } +/** + * Informs the operating system that the application prefers a dark + * theme for native components such as title bars, scrollbars, and + * native dialogs. + * + * @param preferred true if the dark theme is preferred, false otherwise. + * + * @since 3.134 + */ +public void setDarkThemePreferred(boolean preferred) { + checkWidget(); + display.setDarkThemePreferred(preferred); +} + @Override public void setText (String string) { super.setText (string); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java index 8796d214a3..c31dc56556 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java @@ -2179,6 +2179,20 @@ public static boolean isSystemDarkTheme () { return isDarkTheme; } +/** + * Informs the operating system that the application prefers a dark + * theme for native components such as title bars, scrollbars, and + * native dialogs. + * + * @param preferred true if the dark theme is preferred, false otherwise. + * + * @since 3.134 + */ +public void setDarkThemePreferred(boolean preferred) { + checkDevice(); + OS.setTheme(preferred); +} + int getLastEventTime () { return OS.GetMessageTime (); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java index e0f3fa115f..99091971b8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java @@ -576,7 +576,7 @@ void createBalloonTipHandle () { OS.SetWindowLongPtr (balloonTipHandle, OS.GWLP_WNDPROC, display.windowProc); } -void setTitleColoring() { +void setTitleColoring(boolean preferred) { int attributeID = 0; if (OsVersion.IS_WIN10_2004) { // Documented since build 20348, but was already present since build 19041 @@ -590,10 +590,24 @@ void setTitleColoring() { return; } - int[] value = new int[] {1}; + int[] value = new int[] {preferred ? 1 : 0}; OS.DwmSetWindowAttribute (handle, attributeID, value, 4); } +/** + * Informs the operating system that the application prefers a dark + * theme for native components such as title bars, scrollbars, and + * native dialogs. + * + * @param preferred true if the dark theme is preferred, false otherwise. + * + * @since 3.134 + */ +public void setDarkThemePreferred(boolean preferred) { + checkWidget(); + setTitleColoring(preferred); +} + @Override void createHandle () { boolean embedded = handle != 0 && (state & FOREIGN_HANDLE) == 0; @@ -627,7 +641,7 @@ void createHandle () { if (!embedded) { if (display.useShellTitleColoring) { - setTitleColoring(); + setTitleColoring(true); } int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet393.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet393.java new file mode 100644 index 0000000000..2ee4b46179 --- /dev/null +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet393.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2026 Eclipse Foundation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eclipse Foundation - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.snippets; + +import org.eclipse.swt.*; +import org.eclipse.swt.layout.*; +import org.eclipse.swt.widgets.*; + +/** + * Dark Theme Preferred API snippet: demonstrate how to request a dark theme for + * native components (title bars, scrollbars, and native dialogs). + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +public class Snippet393 { + +public static void main (String [] args) { + Display display = new Display (); + + /* Signal that the application prefers a dark theme */ + display.setDarkThemePreferred(true); + + Shell shell = new Shell (display); + shell.setText("Snippet 393 - Dark Theme Preferred"); + shell.setLayout(new GridLayout(1, false)); + + Label label = new Label(shell, SWT.NONE); + label.setText("The title bar and native dialogs should appear dark if supported by the OS."); + + Button button = new Button(shell, SWT.PUSH); + button.setText("Open DirectoryDialog"); + button.addListener(SWT.Selection, event -> { + DirectoryDialog dialog = new DirectoryDialog(shell); + dialog.setMessage("Select a directory (dialog should be dark)"); + dialog.open(); + }); + + shell.pack (); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} +}