Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/accessibility/browser/unfocusedViewDimmingContribution.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { createStyleSheet } from '../../../../base/browser/domStylesheets.js';
7
import { Event } from '../../../../base/common/event.js';
8
import { Disposable, DisposableStore, toDisposable } from '../../../../base/common/lifecycle.js';
9
import { clamp } from '../../../../base/common/numbers.js';
10
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
11
import { IWorkbenchContribution } from '../../../common/contributions.js';
12
import { AccessibilityWorkbenchSettingId, ViewDimUnfocusedOpacityProperties } from './accessibilityConfiguration.js';
13
14
export class UnfocusedViewDimmingContribution extends Disposable implements IWorkbenchContribution {
15
private _styleElement?: HTMLStyleElement;
16
private _styleElementDisposables: DisposableStore | undefined = undefined;
17
18
constructor(
19
@IConfigurationService configurationService: IConfigurationService,
20
) {
21
super();
22
23
this._register(toDisposable(() => this._removeStyleElement()));
24
25
this._register(Event.runAndSubscribe(configurationService.onDidChangeConfiguration, e => {
26
if (e && !e.affectsConfiguration(AccessibilityWorkbenchSettingId.DimUnfocusedEnabled) && !e.affectsConfiguration(AccessibilityWorkbenchSettingId.DimUnfocusedOpacity)) {
27
return;
28
}
29
30
let cssTextContent = '';
31
32
const enabled = ensureBoolean(configurationService.getValue(AccessibilityWorkbenchSettingId.DimUnfocusedEnabled), false);
33
if (enabled) {
34
const opacity = clamp(
35
ensureNumber(configurationService.getValue(AccessibilityWorkbenchSettingId.DimUnfocusedOpacity), ViewDimUnfocusedOpacityProperties.Default),
36
ViewDimUnfocusedOpacityProperties.Minimum,
37
ViewDimUnfocusedOpacityProperties.Maximum
38
);
39
40
if (opacity !== 1) {
41
// These filter rules are more specific than may be expected as the `filter`
42
// rule can cause problems if it's used inside the element like on editor hovers
43
const rules = new Set<string>();
44
const filterRule = `filter: opacity(${opacity});`;
45
// Terminal tabs
46
rules.add(`.monaco-workbench .pane-body.integrated-terminal:not(:focus-within) .tabs-container { ${filterRule} }`);
47
// Terminals
48
rules.add(`.monaco-workbench .pane-body.integrated-terminal .terminal-wrapper:not(:focus-within) { ${filterRule} }`);
49
// Text editors
50
rules.add(`.monaco-workbench .editor-instance:not(:focus-within) .monaco-editor { ${filterRule} }`);
51
// Breadcrumbs
52
rules.add(`.monaco-workbench .editor-instance:not(:focus-within) .breadcrumbs-below-tabs { ${filterRule} }`);
53
// Terminal editors
54
rules.add(`.monaco-workbench .editor-instance:not(:focus-within) .terminal-wrapper { ${filterRule} }`);
55
// Settings editor
56
rules.add(`.monaco-workbench .editor-instance:not(:focus-within) .settings-editor { ${filterRule} }`);
57
// Keybindings editor
58
rules.add(`.monaco-workbench .editor-instance:not(:focus-within) .keybindings-editor { ${filterRule} }`);
59
// Editor placeholder (error case)
60
rules.add(`.monaco-workbench .editor-instance:not(:focus-within) .monaco-editor-pane-placeholder { ${filterRule} }`);
61
// Welcome editor
62
rules.add(`.monaco-workbench .editor-instance:not(:focus-within) .gettingStartedContainer { ${filterRule} }`);
63
cssTextContent = [...rules].join('\n');
64
}
65
66
}
67
68
if (cssTextContent.length === 0) {
69
this._removeStyleElement();
70
} else {
71
this._getStyleElement().textContent = cssTextContent;
72
}
73
}));
74
}
75
76
private _getStyleElement(): HTMLStyleElement {
77
if (!this._styleElement) {
78
this._styleElementDisposables = new DisposableStore();
79
this._styleElement = createStyleSheet(undefined, undefined, this._styleElementDisposables);
80
this._styleElement.className = 'accessibilityUnfocusedViewOpacity';
81
}
82
return this._styleElement;
83
}
84
85
private _removeStyleElement(): void {
86
this._styleElementDisposables?.dispose();
87
this._styleElementDisposables = undefined;
88
this._styleElement = undefined;
89
}
90
}
91
92
93
function ensureBoolean(value: unknown, defaultValue: boolean): boolean {
94
return typeof value === 'boolean' ? value : defaultValue;
95
}
96
97
function ensureNumber(value: unknown, defaultValue: number): number {
98
return typeof value === 'number' ? value : defaultValue;
99
}
100
101