Skip to content

Commit a7caa97

Browse files
committed
OSColorScheme: Separate dark and hc
1 parent 7c20f50 commit a7caa97

10 files changed

Lines changed: 41 additions & 46 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifec
3535
import { IStorageMainService } from 'vs/platform/storage/node/storageMainService';
3636
import { IFileService } from 'vs/platform/files/common/files';
3737
import { FileAccess, Schemas } from 'vs/base/common/network';
38-
import { ColorScheme } from 'vs/platform/theme/common/theme';
3938

4039
export interface IWindowCreationOptions {
4140
state: IWindowState;
@@ -784,7 +783,10 @@ export class CodeWindow extends Disposable implements ICodeWindow {
784783
windowConfiguration.fullscreen = this.isFullScreen;
785784

786785
// Set Accessibility Config
787-
windowConfiguration.colorScheme = (nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors) ? ColorScheme.HIGH_CONTRAST : nativeTheme.shouldUseDarkColors ? ColorScheme.DARK : ColorScheme.LIGHT;
786+
windowConfiguration.colorScheme = {
787+
dark: nativeTheme.shouldUseDarkColors,
788+
highContrast: nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors
789+
};
788790
windowConfiguration.autoDetectHighContrast = windowConfig?.autoDetectHighContrast ?? true;
789791
windowConfiguration.accessibilitySupport = app.accessibilitySupportEnabled;
790792

src/vs/platform/native/common/native.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
import { Event } from 'vs/base/common/event';
77
import { MessageBoxOptions, MessageBoxReturnValue, OpenDevToolsOptions, SaveDialogOptions, OpenDialogOptions, OpenDialogReturnValue, SaveDialogReturnValue, MouseInputEvent } from 'vs/base/parts/sandbox/common/electronTypes';
8-
import { IOpenedWindow, IWindowOpenable, IOpenEmptyWindowOptions, IOpenWindowOptions } from 'vs/platform/windows/common/windows';
8+
import { IOpenedWindow, IWindowOpenable, IOpenEmptyWindowOptions, IOpenWindowOptions, IColorScheme } from 'vs/platform/windows/common/windows';
99
import { INativeOpenDialogOptions } from 'vs/platform/dialogs/common/dialogs';
1010
import { ISerializableCommandAction } from 'vs/platform/actions/common/actions';
11-
import { ColorScheme } from 'vs/platform/theme/common/theme';
1211
import { URI } from 'vs/base/common/uri';
1312

1413
export interface ICPUProperties {
@@ -48,7 +47,7 @@ export interface ICommonNativeHostService {
4847

4948
readonly onOSResume: Event<unknown>;
5049

51-
readonly onColorSchemeChange: Event<ColorScheme>;
50+
readonly onColorSchemeChange: Event<IColorScheme>;
5251

5352
// Window
5453
getWindows(): Promise<IOpenedWindow[]>;

src/vs/platform/native/electron-main/nativeHostMainService.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { IWindowsMainService, ICodeWindow } from 'vs/platform/windows/electron-m
88
import { MessageBoxOptions, MessageBoxReturnValue, shell, OpenDevToolsOptions, SaveDialogOptions, SaveDialogReturnValue, OpenDialogOptions, OpenDialogReturnValue, Menu, BrowserWindow, app, clipboard, powerMonitor, nativeTheme } from 'electron';
99
import { OpenContext } from 'vs/platform/windows/node/window';
1010
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
11-
import { IOpenedWindow, IOpenWindowOptions, IWindowOpenable, IOpenEmptyWindowOptions } from 'vs/platform/windows/common/windows';
11+
import { IOpenedWindow, IOpenWindowOptions, IWindowOpenable, IOpenEmptyWindowOptions, IColorScheme } from 'vs/platform/windows/common/windows';
1212
import { INativeOpenDialogOptions } from 'vs/platform/dialogs/common/dialogs';
1313
import { isMacintosh, isWindows, isRootUser, isLinux } from 'vs/base/common/platform';
1414
import { ICommonNativeHostService, IOSProperties, IOSStatistics } from 'vs/platform/native/common/native';
@@ -22,7 +22,6 @@ import { ITelemetryData, ITelemetryService } from 'vs/platform/telemetry/common/
2222
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
2323
import { MouseInputEvent } from 'vs/base/parts/sandbox/common/electronTypes';
2424
import { arch, totalmem, release, platform, type, loadavg, freemem, cpus } from 'os';
25-
import { ColorScheme } from 'vs/platform/theme/common/theme';
2625
import { virtualMachineHint } from 'vs/base/node/id';
2726
import { ILogService } from 'vs/platform/log/common/log';
2827
import { dirname, join } from 'vs/base/common/path';
@@ -52,16 +51,10 @@ export class NativeHostMainService implements INativeHostMainService {
5251

5352
// Color Scheme changes
5453
nativeTheme.on('updated', () => {
55-
let colorScheme: ColorScheme;
56-
if (nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors) {
57-
colorScheme = ColorScheme.HIGH_CONTRAST;
58-
} else if (nativeTheme.shouldUseDarkColors) {
59-
colorScheme = ColorScheme.DARK;
60-
} else {
61-
colorScheme = ColorScheme.LIGHT;
62-
}
63-
64-
this._onColorSchemeChange.fire(colorScheme);
54+
this._onColorSchemeChange.fire({
55+
highContrast: nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors,
56+
dark: nativeTheme.shouldUseDarkColors
57+
});
6558
});
6659
}
6760

@@ -87,7 +80,7 @@ export class NativeHostMainService implements INativeHostMainService {
8780

8881
readonly onOSResume = Event.fromNodeEventEmitter(powerMonitor, 'resume');
8982

90-
private readonly _onColorSchemeChange = new Emitter<ColorScheme>();
83+
private readonly _onColorSchemeChange = new Emitter<IColorScheme>();
9184
readonly onColorSchemeChange = this._onColorSchemeChange.event;
9285

9386
//#endregion

src/vs/platform/windows/common/windows.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier } from 'vs/platf
1111
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
1212
import { LogLevel } from 'vs/platform/log/common/log';
1313
import { ExportData } from 'vs/base/common/performance';
14-
import { ColorScheme } from 'vs/platform/theme/common/theme';
1514

1615
export const WindowMinimumSize = {
1716
WIDTH: 400,
@@ -213,12 +212,17 @@ export interface INativeRunKeybindingInWindowRequest {
213212
userSettingsLabel: string;
214213
}
215214

215+
export interface IColorScheme {
216+
dark: boolean;
217+
highContrast: boolean;
218+
}
219+
216220
export interface IWindowConfiguration {
217221
sessionId: string;
218222

219223
remoteAuthority?: string;
220224

221-
colorScheme: ColorScheme;
225+
colorScheme: IColorScheme;
222226
autoDetectHighContrast?: boolean;
223227

224228
filesToOpenOrCreate?: IPath[];

src/vs/workbench/services/environment/browser/environmentService.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { IProductService } from 'vs/platform/product/common/productService';
1515
import { memoize } from 'vs/base/common/decorators';
1616
import { onUnexpectedError } from 'vs/base/common/errors';
1717
import { parseLineAndColumnAware } from 'vs/base/common/extpath';
18-
import { ColorScheme } from 'vs/platform/theme/common/theme';
1918

2019
class BrowserWorkbenchConfiguration implements IWindowConfiguration {
2120

@@ -72,7 +71,7 @@ class BrowserWorkbenchConfiguration implements IWindowConfiguration {
7271
}
7372

7473
get colorScheme() {
75-
return ColorScheme.LIGHT;
74+
return { dark: false, highContrast: false };
7675
}
7776
}
7877

src/vs/workbench/services/themes/browser/browserHostColorSchemeService.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
88
import { Disposable } from 'vs/base/common/lifecycle';
99
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
1010
import { IHostColorSchemeService } from 'vs/workbench/services/themes/common/hostColorSchemeService';
11-
import { ColorScheme } from 'vs/platform/theme/common/theme';
1211

1312
export class BrowserHostColorSchemeService extends Disposable implements IHostColorSchemeService {
1413

@@ -38,15 +37,20 @@ export class BrowserHostColorSchemeService extends Disposable implements IHostCo
3837
return this._onDidSchemeChangeEvent.event;
3938
}
4039

41-
get colorScheme(): ColorScheme {
42-
if (window.matchMedia(`(forced-colors: active)`).matches) {
43-
return ColorScheme.HIGH_CONTRAST;
44-
} else if (window.matchMedia(`(prefers-color-scheme: light)`).matches) {
45-
return ColorScheme.LIGHT;
40+
get dark(): boolean {
41+
if (window.matchMedia(`(prefers-color-scheme: light)`).matches) {
42+
return false;
4643
} else if (window.matchMedia(`(prefers-color-scheme: dark)`).matches) {
47-
return ColorScheme.DARK;
44+
return true;
45+
}
46+
return this.environmentService.configuration.colorScheme.dark;
47+
}
48+
49+
get highContrast(): boolean {
50+
if (window.matchMedia(`(forced-colors: active)`).matches) {
51+
return true;
4852
}
49-
return this.environmentService.configuration.colorScheme;
53+
return this.environmentService.configuration.colorScheme.highContrast;
5054
}
5155

5256
}

src/vs/workbench/services/themes/browser/workbenchThemeService.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,11 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
363363
}
364364

365365
private getPreferredColorScheme(): ColorScheme | undefined {
366-
const detectHCThemeSetting = this.configurationService.getValue<boolean>(ThemeSettings.DETECT_HC);
367-
if (this.hostColorService.colorScheme === ColorScheme.HIGH_CONTRAST && detectHCThemeSetting) {
366+
if (this.configurationService.getValue<boolean>(ThemeSettings.DETECT_HC) && this.hostColorService.highContrast) {
368367
return ColorScheme.HIGH_CONTRAST;
369368
}
370369
if (this.configurationService.getValue<boolean>(ThemeSettings.DETECT_COLOR_SCHEME)) {
371-
const osScheme = this.hostColorService.colorScheme;
372-
if (osScheme !== ColorScheme.HIGH_CONTRAST) {
373-
return osScheme;
374-
}
370+
return this.hostColorService.dark ? ColorScheme.DARK : ColorScheme.LIGHT;
375371
}
376372
return undefined;
377373
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
import { Event } from 'vs/base/common/event';
77
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
8-
import { ColorScheme } from 'vs/platform/theme/common/theme';
98

109
export const IHostColorSchemeService = createDecorator<IHostColorSchemeService>('hostColorSchemeService');
1110

1211
export interface IHostColorSchemeService {
1312

1413
readonly _serviceBrand: undefined;
1514

16-
readonly colorScheme: ColorScheme;
15+
readonly dark: boolean;
16+
readonly highContrast: boolean;
1717
readonly onDidChangeColorScheme: Event<void>;
1818

1919
}

src/vs/workbench/services/themes/electron-sandbox/nativeHostColorSchemeService.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { INativeHostService } from 'vs/platform/native/electron-sandbox/native';
88
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
99
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
1010
import { Disposable } from 'vs/base/common/lifecycle';
11-
import { ColorScheme } from 'vs/platform/theme/common/theme';
1211
import { IHostColorSchemeService } from 'vs/workbench/services/themes/common/hostColorSchemeService';
1312

1413
export class NativeHostColorSchemeService extends Disposable implements IHostColorSchemeService {
@@ -27,18 +26,18 @@ export class NativeHostColorSchemeService extends Disposable implements IHostCol
2726
private registerListeners(): void {
2827

2928
// Color Scheme
30-
this._register(this.nativeHostService.onColorSchemeChange(scheme => {
31-
this._colorScheme = scheme;
32-
29+
this._register(this.nativeHostService.onColorSchemeChange(({ highContrast, dark }) => {
30+
this.dark = dark;
31+
this.highContrast = highContrast;
3332
this._onDidChangeColorScheme.fire();
3433
}));
3534
}
3635

3736
private readonly _onDidChangeColorScheme = this._register(new Emitter<void>());
3837
readonly onDidChangeColorScheme = this._onDidChangeColorScheme.event;
3938

40-
private _colorScheme: ColorScheme = this.environmentService.configuration.colorScheme;
41-
get colorScheme() { return this._colorScheme; }
39+
public dark: boolean = this.environmentService.configuration.colorScheme.dark;
40+
public highContrast: boolean = this.environmentService.configuration.colorScheme.highContrast;
4241

4342
}
4443

src/vs/workbench/test/electron-browser/workbenchTestServices.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/ur
4040
import { MouseInputEvent } from 'vs/base/parts/sandbox/common/electronTypes';
4141
import { IModeService } from 'vs/editor/common/services/modeService';
4242
import { IOSProperties, IOSStatistics } from 'vs/platform/native/common/native';
43-
import { ColorScheme } from 'vs/platform/theme/common/theme';
4443
import { homedir } from 'os';
4544

4645
export const TestWorkbenchConfiguration: INativeWorkbenchConfiguration = {
@@ -54,7 +53,7 @@ export const TestWorkbenchConfiguration: INativeWorkbenchConfiguration = {
5453
userEnv: {},
5554
execPath: process.execPath,
5655
perfEntries: [],
57-
colorScheme: ColorScheme.DARK,
56+
colorScheme: { dark: true, highContrast: false },
5857
...parseArgs(process.argv, OPTIONS)
5958
};
6059

0 commit comments

Comments
 (0)