Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void testCorrectScaleUpUsingDifferentSetBoundsMethod() {
}

@ParameterizedTest
@CsvSource({ "0.5, 100, true", "1.0, 200, true", "2.0, 200, true", "2.0, quarter, true", "0.5, 100, false",
@CsvSource({ "2.0, quarter, true", "0.5, 100, false",
"1.0, 200, false", "2.0, 200, false", "2.0, quarter, false", })
public void testAutoScaleImageData(float scaleFactor, String autoScale, boolean monitorSpecificScaling) {
Win32DPIUtils.setMonitorSpecificScaling(monitorSpecificScaling);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ public static Optional<AutoScaleMethod> forString(String s) {

private static String autoScaleValue;

private static final Set<String> ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME = Set.of("quarter", "exact", "false");
private static final Set<String> ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME = Set.of("quarter", "exact");

/**
* System property that enforces to use autoScale value despite incompatibility
* For e.g. Monitor-specific scaling with int200 autoscale value
*/
private static final String SWT_AUTOSCALE_DISABLE_COMPATIBILITY_CHECK = "swt.autoScale.force";

/**
* System property to enable to scale the application on runtime
* when a DPI change is detected.
Expand Down Expand Up @@ -140,20 +147,20 @@ static void setAutoScaleValue(String autoScaleValueArg) {
* scaling.
*/
public static boolean isSetupCompatibleToMonitorSpecificScaling() {
if (DPIUtil.getAutoScaleValue() == null) {
// Per-monitor DPI supported only on Windows
if (!"win32".equals(SWT.getPlatform())) {
return false;
}

if (ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME.contains(DPIUtil.getAutoScaleValue().toLowerCase())) {
// Default means: treat as "quarter" (compatible)
if (autoScaleValue == null || "true".equalsIgnoreCase(System.getProperty(SWT_AUTOSCALE_DISABLE_COMPATIBILITY_CHECK))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of comparing string, I think it makes it cleaner to directly parse the property as boolean, using Boolean.parseBoolean(System.getProperty(SWT_AUTOSCALE_DISABLE_COMPATIBILITY_CHECK))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. It usually makes sense to use System.getProperty() when you want to allow that no value for the property needs to be specified to enable it, e.g., -Dswt.autoScale.force without =true. Then you can do something like

Object disableCompatibilityCheck = System.getProperty(SWT_AUTOSCALE_DISABLE_COMPATIBILITY_CHECK);
if (disableCompatibilityCheck  != null && !"false".equalsIgnoreCase(disableCompatibilityCheck) { 
... 
}

return true;
}
try {
Integer.parseInt(DPIUtil.getAutoScaleValue());
return true;
} catch (NumberFormatException e) {
// unsupported value, use default
}
return false;

String value = autoScaleValue.toLowerCase(Locale.ROOT);

// Compatible only if one of the known values
return ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME.contains(value);
}

public static boolean isMonitorSpecificScalingActive() {
Expand Down
Loading