Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workbench.fontAliasing.auto option #41895

Merged
merged 3 commits into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/vs/workbench/electron-browser/main.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,15 @@ configurationRegistry.registerConfiguration({
},
'workbench.fontAliasing': {
'type': 'string',
'enum': ['default', 'antialiased', 'none'],
'enum': ['default', 'antialiased', 'none', 'auto'],
'default': 'default',
'description':
nls.localize('fontAliasing', "Controls font aliasing method in the workbench.\n- default: Sub-pixel font smoothing. On most non-retina displays this will give the sharpest text\n- antialiased: Smooth the font on the level of the pixel, as opposed to the subpixel. Can make the font appear lighter overall\n- none: Disables font smoothing. Text will show with jagged sharp edges"),
nls.localize('fontAliasing', "Controls font aliasing method in the workbench.\n- default: Sub-pixel font smoothing. On most non-retina displays this will give the sharpest text\n- antialiased: Smooth the font on the level of the pixel, as opposed to the subpixel. Can make the font appear lighter overall\n- none: Disables font smoothing. Text will show with jagged sharp edges\n- auto: Applies `default` or `antialiased` automatically based on the DPI of displays."),
'enumDescriptions': [
nls.localize('workbench.fontAliasing.default', "Sub-pixel font smoothing. On most non-retina displays this will give the sharpest text."),
nls.localize('workbench.fontAliasing.antialiased', "Smooth the font on the level of the pixel, as opposed to the subpixel. Can make the font appear lighter overall."),
nls.localize('workbench.fontAliasing.none', "Disables font smoothing. Text will show with jagged sharp edges.")
nls.localize('workbench.fontAliasing.none', "Disables font smoothing. Text will show with jagged sharp edges."),
nls.localize('workbench.fontAliasing.auto', "Applies `default` or `antialiased` automatically based on the DPI of displays.")
],
'included': isMacintosh
},
Expand Down
14 changes: 14 additions & 0 deletions src/vs/workbench/electron-browser/media/workbench.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,18 @@

.monaco-workbench.windows .monaco-action-bar .select-box {
margin-top: 7px; /* Center the select box */
}

.monaco-font-aliasing-antialiased {
-webkit-font-smoothing: antialiased;
}

.monaco-font-aliasing-none {
-webkit-font-smoothing: none;
}

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
.monaco-font-aliasing-auto {
-webkit-font-smoothing: antialiased;
}
}
21 changes: 15 additions & 6 deletions src/vs/workbench/electron-browser/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ export interface IWorkbenchStartedInfo {
restoredEditors: string[];
}

type FontAliasingOption = 'default' | 'antialiased' | 'none' | 'auto';

const Identifiers = {
WORKBENCH_CONTAINER: 'workbench.main.container',
TITLEBAR_PART: 'workbench.parts.titlebar',
Expand Down Expand Up @@ -202,7 +204,7 @@ export class Workbench implements IPartService {
private inZenMode: IContextKey<boolean>;
private sideBarVisibleContext: IContextKey<boolean>;
private hasFilesToCreateOpenOrDiff: boolean;
private fontAliasing: string;
private fontAliasing: FontAliasingOption;
private zenMode: {
active: boolean;
transitionedToFullScreen: boolean;
Expand Down Expand Up @@ -643,7 +645,7 @@ export class Workbench implements IPartService {
this.activityBarHidden = !activityBarVisible;

// Font aliasing
this.fontAliasing = this.configurationService.getValue<string>(Workbench.fontAliasingConfigurationKey);
this.fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);

// Zen mode
this.zenMode = {
Expand Down Expand Up @@ -937,10 +939,17 @@ export class Workbench implements IPartService {
});
}

private setFontAliasing(aliasing: string) {
private setFontAliasing(aliasing: FontAliasingOption) {
this.fontAliasing = aliasing;

document.body.style['-webkit-font-smoothing'] = (aliasing === 'default' ? '' : aliasing);
const fontAliasingClassNames = [
'monaco-font-aliasing-antialiased',
'monaco-font-aliasing-none',
'monaco-font-aliasing-auto'
];
document.body.classList.remove(...fontAliasingClassNames);
if (aliasing !== 'default') {
document.body.classList.add(`monaco-font-aliasing-${aliasing}`);
}
}

public dispose(reason = ShutdownReason.QUIT): void {
Expand Down Expand Up @@ -1088,7 +1097,7 @@ export class Workbench implements IPartService {

this.setPanelPositionFromStorageOrConfig();

const fontAliasing = this.configurationService.getValue<string>(Workbench.fontAliasingConfigurationKey);
const fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);
if (fontAliasing !== this.fontAliasing) {
this.setFontAliasing(fontAliasing);
}
Expand Down