|
| 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 { Event } from 'vs/base/common/event'; |
| 7 | +import { Disposable, toDisposable } from 'vs/base/common/lifecycle'; |
| 8 | +import { clamp } from 'vs/base/common/numbers'; |
| 9 | +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; |
| 10 | +import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; |
| 11 | +import { AccessibilitySettingId } from 'vs/workbench/contrib/accessibility/browser/accessibilityContribution'; |
| 12 | + |
| 13 | +export class UnfocusedViewDimmingContribution extends Disposable implements IWorkbenchContribution { |
| 14 | + constructor( |
| 15 | + @IConfigurationService configurationService: IConfigurationService, |
| 16 | + ) { |
| 17 | + super(); |
| 18 | + |
| 19 | + const elStyle = document.createElement('style'); |
| 20 | + elStyle.className = 'accessibilityUnfocusedViewOpacity'; |
| 21 | + document.head.appendChild(elStyle); |
| 22 | + this._register(toDisposable(() => elStyle.remove())); |
| 23 | + |
| 24 | + this._register(Event.runAndSubscribe(configurationService.onDidChangeConfiguration, e => { |
| 25 | + if (e && !e.affectsConfiguration(AccessibilitySettingId.UnfocusedViewOpacity)) { |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + let opacity: number; |
| 30 | + const opacityConfig = configurationService.getValue(AccessibilitySettingId.UnfocusedViewOpacity); |
| 31 | + if (typeof opacityConfig !== 'number') { |
| 32 | + opacity = 1; |
| 33 | + } else { |
| 34 | + opacity = clamp(opacityConfig, 0.2, 1); |
| 35 | + } |
| 36 | + |
| 37 | + const rules = new Set<string>(); |
| 38 | + rules.add(`.monaco-workbench .terminal.xterm:not(.focus) { filter: opacity(${opacity}); }`); |
| 39 | + rules.add(`.monaco-workbench .editor-instance .monaco-editor:not(.focused) { filter: opacity(${opacity}); }`); |
| 40 | + |
| 41 | + elStyle.textContent = [...rules].join('\n'); |
| 42 | + })); |
| 43 | + } |
| 44 | +} |
0 commit comments