Skip to content

Commit e15e9bf

Browse files
ShahzaibIbrahimHeikoKlare
authored andcommitted
Limit monitor-specific scaling to supported autoscale modes
With these changes, Eclipse applications will not fail to start anymore when an swt.autoScale value that is incompatible to monitor-specific scaling on Windows is set. The following changes are implemented: - Upon starting an Eclipse application with an swt.autoScale setting that is not compatible with monitor-specific scaling on Windows, the monitor-specific scaling will be disabled and an error dialog will be shown - Users won't be able to enable monitor-specific scaling from appearance page if unsupported swt.autoScale mode is set via system property / ini file
1 parent 2a814c8 commit e15e9bf

File tree

4 files changed

+52
-14
lines changed

4 files changed

+52
-14
lines changed

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/Workbench.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,13 @@ public void update() {
669669
// run the legacy workbench once
670670
returnCode[0] = workbench.runUI();
671671

672+
if (AUTOSCALE_ADAPTATION.isMonitorSpecificScalingDisabledForIncompatibility()) {
673+
display.asyncExec(() -> {
674+
MessageDialog.openError(null, WorkbenchMessages.RescaleAtRuntimeIncompatibilityTitle,
675+
NLS.bind(WorkbenchMessages.RescaleAtRuntimeIncompatibilityDescription));
676+
});
677+
}
678+
672679
if (returnCode[0] == PlatformUI.RETURN_OK) {
673680
// run the e4 event loop and instantiate ... well, stuff
674681
if (serviceListener.get() != null) {
@@ -694,18 +701,6 @@ public void update() {
694701
return returnCode[0];
695702
}
696703

697-
private static void setRescaleAtRuntimePropertyFromPreference() {
698-
if (System.getProperty(SWT_RESCALE_AT_RUNTIME_PROPERTY) != null) {
699-
WorkbenchPlugin.log(Status.warning(SWT_RESCALE_AT_RUNTIME_PROPERTY
700-
+ " is configured (e.g., via the INI), but the according preference should be preferred instead." //$NON-NLS-1$
701-
));
702-
} else {
703-
boolean rescaleAtRuntime = ConfigurationScope.INSTANCE.getNode(WorkbenchPlugin.PI_WORKBENCH)
704-
.getBoolean(IWorkbenchPreferenceConstants.RESCALING_AT_RUNTIME, true);
705-
System.setProperty(SWT_RESCALE_AT_RUNTIME_PROPERTY, Boolean.toString(rescaleAtRuntime));
706-
}
707-
}
708-
709704
private static void setSearchContribution(MApplication app, boolean enabled) {
710705
for (MTrimContribution contribution : app.getTrimContributions()) {
711706
if ("org.eclipse.ui.ide.application.trimcontribution.QuickAccess".contains(contribution //$NON-NLS-1$
@@ -771,7 +766,7 @@ public static Display createDisplay() {
771766
Display.setAppName(applicationName);
772767
}
773768

774-
setRescaleAtRuntimePropertyFromPreference();
769+
AUTOSCALE_ADAPTATION.setRescaleAtRuntimePropertyFromPreference();
775770

776771
// create the display
777772
Display newDisplay = Display.getCurrent();
@@ -3673,6 +3668,8 @@ protected String createId() {
36733668
private static class AutoscaleAdaptation {
36743669
private static final String SWT_AUTOSCALE = "swt.autoScale"; //$NON-NLS-1$
36753670

3671+
private boolean incompatibleMonitorSpecificScalingDisabled;
3672+
36763673
private final String initialAutoScaleValue;
36773674

36783675
public AutoscaleAdaptation() {
@@ -3683,5 +3680,26 @@ public void runWithInitialAutoScaleValue(Runnable runnable) {
36833680
DPIUtil.runWithAutoScaleValue(initialAutoScaleValue, runnable);
36843681
}
36853682

3683+
public void setRescaleAtRuntimePropertyFromPreference() {
3684+
if (System.getProperty(SWT_RESCALE_AT_RUNTIME_PROPERTY) != null) {
3685+
WorkbenchPlugin.log(Status.warning(SWT_RESCALE_AT_RUNTIME_PROPERTY
3686+
+ " is configured (e.g., via the INI), but the according preference should be preferred instead." //$NON-NLS-1$
3687+
));
3688+
} else {
3689+
boolean rescaleAtRuntime = ConfigurationScope.INSTANCE.getNode(WorkbenchPlugin.PI_WORKBENCH)
3690+
.getBoolean(IWorkbenchPreferenceConstants.RESCALING_AT_RUNTIME, true);
3691+
System.setProperty(SWT_RESCALE_AT_RUNTIME_PROPERTY, Boolean.toString(rescaleAtRuntime));
3692+
}
3693+
3694+
if (DPIUtil.isMonitorSpecificScalingActive() && !DPIUtil.isSetupCompatibleToMonitorSpecificScaling()) {
3695+
incompatibleMonitorSpecificScalingDisabled = true;
3696+
System.setProperty(SWT_RESCALE_AT_RUNTIME_PROPERTY, Boolean.toString(false));
3697+
}
3698+
}
3699+
3700+
public boolean isMonitorSpecificScalingDisabledForIncompatibility() {
3701+
return incompatibleMonitorSpecificScalingDisabled;
3702+
}
3703+
36863704
}
36873705
}

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public class WorkbenchMessages extends NLS {
3636

3737
public static String RescaleAtRuntimeDescription;
3838

39+
public static String RescaleAtRuntimeDisabledDescription;
40+
41+
public static String RescaleAtRuntimeIncompatibilityTitle;
42+
43+
public static String RescaleAtRuntimeIncompatibilityDescription;
44+
3945
public static String RescaleAtRuntimeEnabled;
4046

4147
public static String RescaleAtRuntimeSettingChangeWarningTitle;

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.eclipse.jface.dialogs.MessageDialog;
5454
import org.eclipse.jface.fieldassist.ControlDecoration;
5555
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
56+
import org.eclipse.jface.layout.GridDataFactory;
5657
import org.eclipse.jface.preference.IPreferenceStore;
5758
import org.eclipse.jface.preference.PreferencePage;
5859
import org.eclipse.jface.viewers.ArrayContentProvider;
@@ -65,7 +66,9 @@
6566
import org.eclipse.swt.SWT;
6667
import org.eclipse.swt.events.SelectionEvent;
6768
import org.eclipse.swt.events.SelectionListener;
69+
import org.eclipse.swt.graphics.Font;
6870
import org.eclipse.swt.graphics.Image;
71+
import org.eclipse.swt.internal.DPIUtil;
6972
import org.eclipse.swt.layout.GridData;
7073
import org.eclipse.swt.layout.GridLayout;
7174
import org.eclipse.swt.widgets.Button;
@@ -222,7 +225,15 @@ private void createRescaleAtRuntimeCheckButton(Composite parent) {
222225
.getBoolean(IWorkbenchPreferenceConstants.RESCALING_AT_RUNTIME, true);
223226
rescaleAtRuntime = createCheckButton(parent, WorkbenchMessages.RescaleAtRuntimeEnabled,
224227
initialStateRescaleAtRuntime);
225-
rescaleAtRuntime.setToolTipText(WorkbenchMessages.RescaleAtRuntimeDescription);
228+
if (!DPIUtil.isSetupCompatibleToMonitorSpecificScaling()) {
229+
rescaleAtRuntime.setEnabled(false);
230+
Font font = parent.getFont();
231+
Composite note = createNoteComposite(font, parent, WorkbenchMessages.Preference_note,
232+
WorkbenchMessages.RescaleAtRuntimeDisabledDescription);
233+
note.setLayoutData(GridDataFactory.swtDefaults().span(2, 1).create());
234+
} else {
235+
rescaleAtRuntime.setToolTipText(WorkbenchMessages.RescaleAtRuntimeDescription);
236+
}
226237
}
227238

228239
private void createThemeIndependentComposits(Composite comp) {

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,10 @@ ThemeChangeWarningTitle = Theme Changed
503503
RescaleAtRuntimeSettingChangeWarningTitle = DPI Setting Changed
504504
RescaleAtRuntimeSettingChangeWarningText = Restart for the DPI setting changes to take effect
505505
RescaleAtRuntimeDescription = Activating this option will dynamically scale all windows according to the monitor they are currently in
506+
RescaleAtRuntimeDisabledDescription = Incompatible value for system property "swt.autoScale" is defined
506507
RescaleAtRuntimeEnabled = Use monitor-specific UI &scaling
508+
RescaleAtRuntimeIncompatibilityTitle = Monitor-Specific Scaling Deactivated
509+
RescaleAtRuntimeIncompatibilityDescription = Monitor-specific scaling is currently active but an incompatible "swt.autoScale" value is defined. For this reason, monitor-specific scaling has been disabled. Please review your auto-scaling configuration.
507510
# --- Workbench -----
508511
WorkbenchPreference_openMode=Open mode
509512
WorkbenchPreference_doubleClick=D&ouble click

0 commit comments

Comments
 (0)