From b750a929fac92fdd0c0c028ada9fa5ac37be65df Mon Sep 17 00:00:00 2001 From: Shahzaib Ibrahim Date: Fri, 31 Oct 2025 14:11:12 +0100 Subject: [PATCH] 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. --- .../org/eclipse/ui/internal/Workbench.java | 10 ++++++++++ .../org/eclipse/ui/internal/WorkbenchMessages.java | 6 ++++++ .../ui/internal/dialogs/ViewsPreferencePage.java | 13 ++++++++++++- .../org/eclipse/ui/internal/messages.properties | 3 +++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/Workbench.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/Workbench.java index 690aa8ac9de..4aabe4c1ce6 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/Workbench.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/Workbench.java @@ -303,6 +303,8 @@ public final class Workbench extends EventManager implements IWorkbench, org.ecl private static final String SWT_RESCALE_AT_RUNTIME_PROPERTY = "swt.autoScale.updateOnRuntime"; //$NON-NLS-1$ + private static final String SWT_AUTOSCALE = "swt.autoScale"; //$NON-NLS-1$ + private static final class StartupProgressBundleListener implements ServiceListener { private final SubMonitor subMonitor; @@ -704,6 +706,14 @@ private static void setRescaleAtRuntimePropertyFromPreference() { .getBoolean(IWorkbenchPreferenceConstants.RESCALING_AT_RUNTIME, true); System.setProperty(SWT_RESCALE_AT_RUNTIME_PROPERTY, Boolean.toString(rescaleAtRuntime)); } + + if (DPIUtil.isMonitorSpecificScalingActive() && !DPIUtil.isSetupCompatibleToMonitorSpecificScaling()) { + System.setProperty(SWT_RESCALE_AT_RUNTIME_PROPERTY, Boolean.toString(false)); + MessageDialog.openError(new Shell(Display.getDefault()), + WorkbenchMessages.RescaleAtRuntimeIncompatibilityTitle, + NLS.bind(WorkbenchMessages.RescaleAtRuntimeIncompatibilityDescription, + System.getProperty(SWT_AUTOSCALE))); + } } private static void setSearchContribution(MApplication app, boolean enabled) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java index 4592061f679..a2b10045e03 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java @@ -36,6 +36,12 @@ public class WorkbenchMessages extends NLS { public static String RescaleAtRuntimeDescription; + public static String RescaleAtRuntimeDisabledDescription; + + public static String RescaleAtRuntimeIncompatibilityTitle; + + public static String RescaleAtRuntimeIncompatibilityDescription; + public static String RescaleAtRuntimeEnabled; public static String RescaleAtRuntimeSettingChangeWarningTitle; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java index af350f44b9b..003ae8953ee 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java @@ -53,6 +53,7 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.fieldassist.ControlDecoration; import org.eclipse.jface.fieldassist.FieldDecorationRegistry; +import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.viewers.ArrayContentProvider; @@ -65,7 +66,9 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.internal.DPIUtil; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -222,7 +225,15 @@ private void createRescaleAtRuntimeCheckButton(Composite parent) { .getBoolean(IWorkbenchPreferenceConstants.RESCALING_AT_RUNTIME, true); rescaleAtRuntime = createCheckButton(parent, WorkbenchMessages.RescaleAtRuntimeEnabled, initialStateRescaleAtRuntime); - rescaleAtRuntime.setToolTipText(WorkbenchMessages.RescaleAtRuntimeDescription); + if (!DPIUtil.isSetupCompatibleToMonitorSpecificScaling()) { + rescaleAtRuntime.setEnabled(false); + Font font = parent.getFont(); + Composite note = createNoteComposite(font, parent, WorkbenchMessages.Preference_note, + WorkbenchMessages.RescaleAtRuntimeDisabledDescription); + note.setLayoutData(GridDataFactory.swtDefaults().span(2, 1).create()); + } else { + rescaleAtRuntime.setToolTipText(WorkbenchMessages.RescaleAtRuntimeDescription); + } } private void createThemeIndependentComposits(Composite comp) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties index 3cb4caeadc2..be87813a0dc 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties @@ -503,7 +503,10 @@ ThemeChangeWarningTitle = Theme Changed RescaleAtRuntimeSettingChangeWarningTitle = DPI Setting Changed RescaleAtRuntimeSettingChangeWarningText = Restart for the DPI setting changes to take effect RescaleAtRuntimeDescription = Activating this option will dynamically scale all windows according to the monitor they are currently in +RescaleAtRuntimeDisabledDescription = Incompatible value for system property "swt.autoScale" was defined RescaleAtRuntimeEnabled = Use monitor-specific UI &scaling +RescaleAtRuntimeIncompatibilityTitle = Monitor-Specific Scaling Deactivated +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. # --- Workbench ----- WorkbenchPreference_openMode=Open mode WorkbenchPreference_doubleClick=D&ouble click