Skip to content

Commit c5928bb

Browse files
ShahzaibIbrahimHeikoKlare
authored andcommitted
Adding experimental preference to enable rescaling at runtime (Windows)
In the UI Preferences -> General -> Appearance, there is a new HiDPI setting that could be checked to enable the monitor-specific scaling of the UI. This check will also enable Edge browser by default. This is an experimental feature to test the multi-monitor HiDPI support before it is actually released and set by default. For now, this preference is disabled by default.
1 parent 83c128c commit c5928bb

File tree

5 files changed

+82
-7
lines changed

5 files changed

+82
-7
lines changed

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPreferenceConstants.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,4 +705,14 @@ public interface IWorkbenchPreferenceConstants {
705705
* @since 3.130
706706
*/
707707
String LARGE_VIEW_LIMIT = "largeViewLimit"; //$NON-NLS-1$
708+
709+
/**
710+
* <p>
711+
* <strong>EXPERIMENTAL</strong>. Whether the UI adapts to DPI changes at
712+
* runtime. It only effects Windows.
713+
* </p>
714+
*
715+
* @since 3.133
716+
*/
717+
String RESCALING_AT_RUNTIME = "RESCALING_AT_RUNTIME"; //$NON-NLS-1$
708718
}

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ public static int createAndRunWorkbench(final Display display, final WorkbenchAd
584584
int orientation = store.getInt(IPreferenceConstants.LAYOUT_DIRECTION);
585585
Window.setDefaultOrientation(orientation);
586586
}
587-
587+
setRescaleAtRuntimePropertyFromPreference(display);
588588
if (obj instanceof E4Application) {
589589
E4Application e4app = (E4Application) obj;
590590
E4Workbench e4Workbench = e4app.createE4Workbench(getApplicationContext(), display);
@@ -678,6 +678,15 @@ public void update() {
678678
return returnCode[0];
679679
}
680680

681+
private static void setRescaleAtRuntimePropertyFromPreference(final Display display) {
682+
boolean rescaleAtRuntime = PrefUtil.getAPIPreferenceStore()
683+
.getBoolean(IWorkbenchPreferenceConstants.RESCALING_AT_RUNTIME);
684+
if (rescaleAtRuntime) {
685+
display.setRescalingAtRuntime(rescaleAtRuntime);
686+
System.setProperty("org.eclipse.swt.browser.DefaultType", "edge"); //$NON-NLS-1$ //$NON-NLS-2$
687+
}
688+
}
689+
681690
private static void setSearchContribution(MApplication app, boolean enabled) {
682691
for (MTrimContribution contribution : app.getTrimContributions()) {
683692
if ("org.eclipse.ui.ide.application.trimcontribution.QuickAccess".contains(contribution //$NON-NLS-1$

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ public class WorkbenchMessages extends NLS {
3434

3535
public static String ThemingEnabled;
3636

37+
public static String HiDpiSettingsGroupTitle;
38+
39+
public static String RescaleAtRuntimeEnabled;
40+
41+
public static String RescaleAtRuntimeDisclaimer;
42+
43+
public static String RescaleAtRuntimeSettingChangeWarningTitle;
44+
45+
public static String RescaleAtRuntimeSettingChangeWarningText;
46+
3747
public static String ThemeChangeWarningText;
3848

3949
public static String ThemeChangeWarningTitle;

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.eclipse.core.runtime.IExtensionPoint;
3838
import org.eclipse.core.runtime.IExtensionRegistry;
3939
import org.eclipse.core.runtime.Platform;
40+
import org.eclipse.core.runtime.Platform.OS;
4041
import org.eclipse.core.runtime.RegistryFactory;
4142
import org.eclipse.core.runtime.preferences.DefaultScope;
4243
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
@@ -53,6 +54,7 @@
5354
import org.eclipse.jface.dialogs.MessageDialog;
5455
import org.eclipse.jface.fieldassist.ControlDecoration;
5556
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
57+
import org.eclipse.jface.layout.GridDataFactory;
5658
import org.eclipse.jface.preference.IPreferenceStore;
5759
import org.eclipse.jface.preference.PreferencePage;
5860
import org.eclipse.jface.util.Util;
@@ -73,6 +75,7 @@
7375
import org.eclipse.swt.widgets.Composite;
7476
import org.eclipse.swt.widgets.Control;
7577
import org.eclipse.swt.widgets.Display;
78+
import org.eclipse.swt.widgets.Group;
7679
import org.eclipse.swt.widgets.Label;
7780
import org.eclipse.ui.IWorkbench;
7881
import org.eclipse.ui.IWorkbenchPreferenceConstants;
@@ -114,6 +117,7 @@ public class ViewsPreferencePage extends PreferencePage implements IWorkbenchPre
114117
private boolean highContrastMode;
115118

116119
private Button themingEnabled;
120+
private Button rescaleAtRuntime;
117121

118122
private Button hideIconsForViewTabs;
119123
private Button showFullTextForViewTabs;
@@ -135,6 +139,7 @@ protected Control createContents(Composite parent) {
135139
layout.horizontalSpacing = 10;
136140
comp.setLayout(layout);
137141
createThemeIndependentComposits(comp);
142+
createHiDPISettingsGroup(comp);
138143
return comp;
139144
}
140145

@@ -180,6 +185,8 @@ protected Control createContents(Composite parent) {
180185
createHideIconsForViewTabs(comp);
181186
createDependency(showFullTextForViewTabs, hideIconsForViewTabs);
182187

188+
createHiDPISettingsGroup(comp);
189+
183190
if (currentTheme != null) {
184191
String colorsAndFontsThemeId = getColorAndFontThemeIdByThemeId(currentTheme.getId());
185192
if (colorsAndFontsThemeId != null && !currentColorsAndFontsTheme.getId().equals(colorsAndFontsThemeId)) {
@@ -192,6 +199,30 @@ protected Control createContents(Composite parent) {
192199
return comp;
193200
}
194201

202+
private void createHiDPISettingsGroup(Composite parent) {
203+
if (!OS.isWindows()) {
204+
return;
205+
}
206+
createLabel(parent, ""); //$NON-NLS-1$
207+
Group group = new Group(parent, SWT.LEFT);
208+
group.setText(WorkbenchMessages.HiDpiSettingsGroupTitle);
209+
210+
GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
211+
gridData.horizontalSpan = ((GridLayout) parent.getLayout()).numColumns;
212+
group.setLayoutData(gridData);
213+
group.setFont(parent.getFont());
214+
GridLayout layout = new GridLayout(1, false);
215+
group.setLayout(layout);
216+
Label infoLabel = new Label(group, SWT.WRAP);
217+
infoLabel.setText(WorkbenchMessages.RescaleAtRuntimeDisclaimer);
218+
infoLabel.setLayoutData(GridDataFactory.defaultsFor(infoLabel).create());
219+
createLabel(group, ""); //$NON-NLS-1$
220+
221+
boolean initialStateRescaleAtRuntime = PrefUtil.getAPIPreferenceStore()
222+
.getBoolean(IWorkbenchPreferenceConstants.RESCALING_AT_RUNTIME);
223+
rescaleAtRuntime = createCheckButton(group, WorkbenchMessages.RescaleAtRuntimeEnabled, initialStateRescaleAtRuntime);
224+
}
225+
195226
private void createThemeIndependentComposits(Composite comp) {
196227
createUseRoundTabs(comp);
197228
createColoredLabelsPref(comp);
@@ -227,7 +258,6 @@ private void createDependency(Button parent, Button dependent) {
227258
GridData gridData = new GridData();
228259
gridData.horizontalIndent = 20;
229260
dependent.setLayoutData(gridData);
230-
231261
boolean parentState = parent.getSelection();
232262
dependent.setEnabled(parentState);
233263

@@ -341,6 +371,14 @@ public boolean performOk() {
341371
.getSelection();
342372
prefs.putBoolean(PartRenderingEngine.ENABLED_THEME_KEY, themingEnabled.getSelection());
343373

374+
boolean isRescaleAtRuntimeChanged = false;
375+
if (rescaleAtRuntime != null) {
376+
boolean initialStateRescaleAtRuntime = PrefUtil.getAPIPreferenceStore()
377+
.getBoolean(IWorkbenchPreferenceConstants.RESCALING_AT_RUNTIME);
378+
isRescaleAtRuntimeChanged = initialStateRescaleAtRuntime != rescaleAtRuntime.getSelection();
379+
apiStore.setValue(IWorkbenchPreferenceConstants.RESCALING_AT_RUNTIME, rescaleAtRuntime.getSelection());
380+
}
381+
344382
prefs.putBoolean(CTabRendering.USE_ROUND_TABS, useRoundTabs.getSelection());
345383
try {
346384
prefs.flush();
@@ -367,19 +405,22 @@ public boolean performOk() {
367405
colorFontsDecorator.hide();
368406

369407
if (themeChanged || colorsAndFontsThemeChanged) {
370-
showRestartDialog();
408+
showRestartDialog(WorkbenchMessages.ThemeChangeWarningTitle, WorkbenchMessages.ThemeChangeWarningText);
371409
}
372410
}
373411
if (themingEnabledChanged) {
374-
showRestartDialog();
412+
showRestartDialog(WorkbenchMessages.ThemeChangeWarningTitle, WorkbenchMessages.ThemeChangeWarningText);
413+
}
414+
if (isRescaleAtRuntimeChanged) {
415+
showRestartDialog(WorkbenchMessages.RescaleAtRuntimeSettingChangeWarningTitle,
416+
WorkbenchMessages.RescaleAtRuntimeSettingChangeWarningText);
375417
}
376418

377419
return super.performOk();
378420
}
379421

380-
private void showRestartDialog() {
381-
if (new MessageDialog(null, WorkbenchMessages.ThemeChangeWarningTitle, null,
382-
WorkbenchMessages.ThemeChangeWarningText, MessageDialog.NONE, 2,
422+
private void showRestartDialog(String title, String warningText) {
423+
if (new MessageDialog(null, title, null, warningText, MessageDialog.NONE, 2,
383424
WorkbenchMessages.Workbench_RestartButton, WorkbenchMessages.Workbench_DontRestartButton)
384425
.open() == Window.OK) {
385426
Display.getDefault().asyncExec(() -> PlatformUI.getWorkbench().restart());

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ PreferencePageParameterValues_pageLabelSeparator = \ >\
497497
ThemingEnabled = E&nable theming
498498
ThemeChangeWarningText = Restart for the theme changes to take full effect
499499
ThemeChangeWarningTitle = Theme Changed
500+
RescaleAtRuntimeSettingChangeWarningTitle = DPI Setting Changed
501+
RescaleAtRuntimeSettingChangeWarningText = Restart for the DPI setting changes to take effect
502+
HiDpiSettingsGroupTitle = HiDPI settings
503+
RescaleAtRuntimeEnabled = Monitor-specific UI &scaling
504+
RescaleAtRuntimeDisclaimer = EXPERIMENTAL! Activating this option will dynamically scale all windows according to the monitor they are currently in. It will also set the default browser to Edge in order to provide the appropriate scaling of content displayed in a browser. This feature is still in development and therefore considered experimental.
500505
# --- Workbench -----
501506
WorkbenchPreference_openMode=Open mode
502507
WorkbenchPreference_doubleClick=D&ouble click

0 commit comments

Comments
 (0)