Skip to content

Commit e8b9e37

Browse files
Limit monitor-specific scaling to supported autoscale modes
These changes have following affects: - Upon starting eclipse product when monitor-specific scaling is set with unsupported autoscale mode, it will show a error dialog and application won't start. - User won't be able to enable monitor-specific scaling from appearance page if unsupported autoscale mode is set from property or ini file. - User can then either force the unsupported autoscale mode with monitor specific-scaling by setting swt.autoScale.force to true or switch to supported autoscale mode.
1 parent b9ab7dc commit e8b9e37

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@
147147
import org.eclipse.osgi.service.datalocation.Location;
148148
import org.eclipse.osgi.service.runnable.StartupMonitor;
149149
import org.eclipse.osgi.util.NLS;
150+
import org.eclipse.swt.AutoScaling;
150151
import org.eclipse.swt.SWT;
152+
import org.eclipse.swt.SWTError;
151153
import org.eclipse.swt.SWTException;
152154
import org.eclipse.swt.browser.Browser;
153155
import org.eclipse.swt.custom.BusyIndicator;
@@ -158,7 +160,6 @@
158160
import org.eclipse.swt.graphics.Point;
159161
import org.eclipse.swt.graphics.Rectangle;
160162
import org.eclipse.swt.graphics.Transform;
161-
import org.eclipse.swt.internal.DPIUtil;
162163
import org.eclipse.swt.widgets.Display;
163164
import org.eclipse.swt.widgets.Listener;
164165
import org.eclipse.swt.widgets.Monitor;
@@ -703,6 +704,7 @@ private static void setRescaleAtRuntimePropertyFromPreference() {
703704
boolean rescaleAtRuntime = ConfigurationScope.INSTANCE.getNode(WorkbenchPlugin.PI_WORKBENCH)
704705
.getBoolean(IWorkbenchPreferenceConstants.RESCALING_AT_RUNTIME, true);
705706
System.setProperty(SWT_RESCALE_AT_RUNTIME_PROPERTY, Boolean.toString(rescaleAtRuntime));
707+
AutoScaling.setAutoScaleForMonitorSpecificScaling();
706708
}
707709
}
708710

@@ -773,6 +775,9 @@ public static Display createDisplay() {
773775

774776
setRescaleAtRuntimePropertyFromPreference();
775777

778+
if (AutoScaling.isMonitorSpecificScalingActive() && !AutoScaling.isSetupCompatibleToMonitorSpecificScaling()) {
779+
showMonitorSpecificIncompambatibilityDialog();
780+
}
776781
// create the display
777782
Display newDisplay = Display.getCurrent();
778783
if (newDisplay == null) {
@@ -802,6 +807,15 @@ public static Display createDisplay() {
802807
return newDisplay;
803808
}
804809

810+
private static void showMonitorSpecificIncompambatibilityDialog() throws SWTError {
811+
MessageDialog.openError(new Shell(Display.getDefault()), WorkbenchMessages.RescaleAtRuntimeIncompatibilityTitle,
812+
NLS.bind(WorkbenchMessages.RescaleAtRuntimeIncompatibilityDescription,
813+
AutoScaling.getAutoScaleValue()));
814+
throw new SWTError(SWT.ERROR_NOT_IMPLEMENTED,
815+
"monitor-specific scaling is only implemented for auto-scale values \"quarter\", \"exact\", \"false\" or a concrete zoom value, but \"" //$NON-NLS-1$
816+
+ AutoScaling.getAutoScaleValue() + "\" has been specified"); //$NON-NLS-1$
817+
}
818+
805819
/**
806820
* Create the splash wrapper and set it to work.
807821
*
@@ -3680,7 +3694,7 @@ public AutoscaleAdaptation() {
36803694
}
36813695

36823696
public void runWithInitialAutoScaleValue(Runnable runnable) {
3683-
DPIUtil.runWithAutoScaleValue(initialAutoScaleValue, runnable);
3697+
AutoScaling.runWithAutoScaleValue(initialAutoScaleValue, runnable);
36843698
}
36853699

36863700
}

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
@@ -38,6 +38,12 @@ public class WorkbenchMessages extends NLS {
3838

3939
public static String RescaleAtRuntimeDescription;
4040

41+
public static String RescaleAtRuntimeDisabledDescription;
42+
43+
public static String RescaleAtRuntimeIncompatibilityTitle;
44+
45+
public static String RescaleAtRuntimeIncompatibilityDescription;
46+
4147
public static String RescaleAtRuntimeEnabled;
4248

4349
public static String RescaleAtRuntimeSettingChangeWarningTitle;

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

Lines changed: 13 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;
@@ -62,9 +63,11 @@
6263
import org.eclipse.jface.viewers.StructuredSelection;
6364
import org.eclipse.jface.window.Window;
6465
import org.eclipse.osgi.util.NLS;
66+
import org.eclipse.swt.AutoScaling;
6567
import org.eclipse.swt.SWT;
6668
import org.eclipse.swt.events.SelectionEvent;
6769
import org.eclipse.swt.events.SelectionListener;
70+
import org.eclipse.swt.graphics.Font;
6871
import org.eclipse.swt.graphics.Image;
6972
import org.eclipse.swt.layout.GridData;
7073
import org.eclipse.swt.layout.GridLayout;
@@ -222,7 +225,16 @@ 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 (!AutoScaling.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.setEnabled(true);
236+
rescaleAtRuntime.setToolTipText(WorkbenchMessages.RescaleAtRuntimeDescription);
237+
}
226238
}
227239

228240
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
@@ -504,7 +504,10 @@ RescaleAtRuntimeSettingChangeWarningTitle = DPI Setting Changed
504504
RescaleAtRuntimeSettingChangeWarningText = Restart for the DPI setting changes to take effect
505505
HiDpiSettingsGroupTitle = HiDPI settings
506506
RescaleAtRuntimeDescription = Activating this option will dynamically scale all windows according to the monitor they are currently in
507+
RescaleAtRuntimeDisabledDescription = Incompatible autoscale value was defined via system property or ini
507508
RescaleAtRuntimeEnabled = Use monitor-specific UI &scaling
509+
RescaleAtRuntimeIncompatibilityTitle = Scaling Configuration Error
510+
RescaleAtRuntimeIncompatibilityDescription = Monitor-specific scaling is currently active with the wrong autoscale value (''{0}''). This combination may lead to unexpected UI scaling behavior. Please review your auto-scaling configuration.
508511
# --- Workbench -----
509512
WorkbenchPreference_openMode=Open mode
510513
WorkbenchPreference_doubleClick=D&ouble click

0 commit comments

Comments
 (0)