Skip to content

Commit 21dd836

Browse files
author
Benjamin Pasero
committed
macOS: detect high contrast theme (fix microsoft#105481)
1 parent 860a687 commit 21dd836

5 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/vs/code/electron-main/window.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
778778
if (windowConfig?.autoDetectHighContrast === false) {
779779
autoDetectHighContrast = false;
780780
}
781-
windowConfiguration.highContrast = isWindows && autoDetectHighContrast && nativeTheme.shouldUseInvertedColorScheme;
781+
windowConfiguration.highContrast = (isWindows || isMacintosh) && autoDetectHighContrast && nativeTheme.shouldUseInvertedColorScheme;
782782
windowConfiguration.accessibilitySupport = app.accessibilitySupportEnabled;
783783

784784
// Title style related

src/vs/platform/theme/electron-main/themeMainService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ export class ThemeMainService implements IThemeMainService {
4242
}
4343

4444
getBackgroundColor(): string {
45-
if (isWindows && nativeTheme.shouldUseInvertedColorScheme) {
45+
if ((isWindows || isMacintosh) && nativeTheme.shouldUseInvertedColorScheme) {
4646
return DEFAULT_BG_HC_BLACK;
4747
}
4848

4949
let background = this.stateService.getItem<string | null>(THEME_BG_STORAGE_KEY, null);
5050
if (!background) {
5151
let baseTheme: string;
52-
if (isWindows && nativeTheme.shouldUseInvertedColorScheme) {
52+
if ((isWindows || isMacintosh) && nativeTheme.shouldUseInvertedColorScheme) {
5353
baseTheme = 'hc-black';
5454
} else {
5555
baseTheme = this.stateService.getItem<string>(THEME_STORAGE_KEY, 'vs-dark').split(' ')[0];

src/vs/platform/windows/electron-main/windowsMainService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
212212

213213
private registerListeners(): void {
214214

215-
// React to HC color scheme changes (Windows)
216-
if (isWindows) {
215+
// React to HC color scheme changes (Windows, macOS)
216+
if (isWindows || isMacintosh) {
217217
nativeTheme.on('updated', () => {
218218
if (nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors) {
219219
this.sendToAll('vscode:enterHighContrast');

src/vs/workbench/electron-sandbox/desktop.contribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ import { IJSONSchema } from 'vs/base/common/jsonSchema';
258258
'window.autoDetectHighContrast': {
259259
'type': 'boolean',
260260
'default': true,
261-
'description': nls.localize('autoDetectHighContrast', "If enabled, will automatically change to high contrast theme if Windows is using a high contrast theme, and to dark theme when switching away from a Windows high contrast theme."),
261+
'description': nls.localize('autoDetectHighContrast', "If enabled, will automatically change to high contrast theme if the OS is using a high contrast theme, and to dark theme when switching away from a high contrast theme."),
262262
'scope': ConfigurationScope.APPLICATION,
263-
'included': isWindows
263+
'included': isWindows || isMacintosh
264264
},
265265
'window.doubleClickIconToClose': {
266266
'type': 'boolean',

src/vs/workbench/services/themes/common/themeConfiguration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { workbenchColorsSchemaId } from 'vs/platform/theme/common/colorRegistry'
1414
import { tokenStylingSchemaId } from 'vs/platform/theme/common/tokenClassificationRegistry';
1515
import { ThemeSettings, IWorkbenchColorTheme, IWorkbenchFileIconTheme, IColorCustomizations, ITokenColorCustomizations, IWorkbenchProductIconTheme, ISemanticTokenColorCustomizations, IExperimentalSemanticTokenColorCustomizations } from 'vs/workbench/services/themes/common/workbenchThemeService';
1616
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
17-
import { isWeb } from 'vs/base/common/platform';
17+
import { isMacintosh, isWeb, isWindows } from 'vs/base/common/platform';
1818

1919
const DEFAULT_THEME_DARK_SETTING_VALUE = 'Default Dark+';
2020
const DEFAULT_THEME_LIGHT_SETTING_VALUE = 'Default Light+';
@@ -60,6 +60,7 @@ const preferredHCThemeSettingSchema: IConfigurationPropertySchema = {
6060
default: DEFAULT_THEME_HC_SETTING_VALUE,
6161
enum: colorThemeSettingEnum,
6262
enumDescriptions: colorThemeSettingEnumDescriptions,
63+
included: isWindows || isMacintosh,
6364
errorMessage: nls.localize('colorThemeError', "Theme is unknown or not installed."),
6465
};
6566
const detectColorSchemeSettingSchema: IConfigurationPropertySchema = {

0 commit comments

Comments
 (0)