From b4ca8ee0e6f10c4157b229d4d3646eb2db80e592 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Sat, 29 Mar 2025 12:51:21 +0100 Subject: [PATCH] Add DPIUtil method for running code in custom auto-scale mode --- .../common/org/eclipse/swt/internal/DPIUtil.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java index f65e782ab5f..91c993bed75 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java @@ -605,10 +605,6 @@ public static int getDeviceZoom() { return deviceZoom; } -public static int getDeviceZoom(String autoScaleProperty) { - return getZoomForAutoscaleProperty(nativeDeviceZoom, autoScaleProperty); -} - public static void setDeviceZoom (int nativeDeviceZoom) { DPIUtil.nativeDeviceZoom = nativeDeviceZoom; int deviceZoom = getZoomForAutoscaleProperty (nativeDeviceZoom); @@ -676,6 +672,16 @@ private static int getZoomForAutoscaleProperty (int nativeDeviceZoom, String aut return zoom; } +public static void runWithAutoScaleValue(String autoScaleValue, Runnable runnable) { + String initialAutoScaleValue = DPIUtil.autoScaleValue; + DPIUtil.autoScaleValue = autoScaleValue; + try { + runnable.run(); + } finally { + DPIUtil.autoScaleValue = initialAutoScaleValue; + } +} + public static void setMonitorSpecificScaling(boolean activate) { System.setProperty(SWT_AUTOSCALE_UPDATE_ON_RUNTIME, Boolean.toString(activate)); }