-
Notifications
You must be signed in to change notification settings - Fork 186
Make DPI_CHANGED event handling async #2520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
akoch-yatta
merged 1 commit into
eclipse-platform:master
from
vi-eclipse:amartya4256/dpi_performance_improvement/async_dpi_scaling
Oct 2, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/DPITestUtil.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/DPITestUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2024 Yatta Solutions | ||
| * | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * Yatta Solutions - initial API and implementation | ||
| *******************************************************************************/ | ||
| package org.eclipse.swt.widgets; | ||
|
|
||
| import java.time.*; | ||
| import java.util.concurrent.atomic.*; | ||
|
|
||
| import org.eclipse.swt.internal.*; | ||
| import org.eclipse.swt.widgets.Control.*; | ||
|
|
||
| public final class DPITestUtil { | ||
|
|
||
| private DPITestUtil() { | ||
| } | ||
|
|
||
| private static final int TIMEOUT_MILLIS = 10000; | ||
|
|
||
| public static void changeDPIZoom (Shell shell, int nativeZoom) { | ||
| DPIUtil.setDeviceZoom(nativeZoom); | ||
| Event event = shell.createZoomChangedEvent(nativeZoom); | ||
| shell.sendZoomChangedEvent(event, shell); | ||
| DPIChangeExecution data = (DPIChangeExecution) event.data; | ||
| waitForDPIChange(shell, TIMEOUT_MILLIS, data.taskCount); | ||
| } | ||
|
|
||
| private static void waitForDPIChange(Shell shell, int timeout, AtomicInteger scalingCounter) { | ||
| waitForPassCondition(shell, timeout, scalingCounter); | ||
| } | ||
|
|
||
| private static void waitForPassCondition(Shell shell, int timeout, AtomicInteger scalingCounter) { | ||
| final Instant timeOut = Instant.now().plusMillis(timeout); | ||
| final Display display = shell == null ? Display.getDefault() : shell.getDisplay(); | ||
|
|
||
| while (Instant.now().isBefore(timeOut) && scalingCounter.get() != 0) { | ||
| if (!display.isDisposed()) { | ||
| display.readAndDispatch(); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WM_DPICHANGEDdoes nothing ifnativeZoom == newNativeZoom. Since all events are processed asynchronous (even handling the initial DPI change event for the shell) it can happen that a shell is moved back and forth and the second event is not processed because of the above condition, leading to the shell having a wrong scaling. As an example, imagine you move a shell from 100% to 125% monitor.WM_DPICHANGEDforwards this event as100 != 125and the event is queued. Then the shell is immediately moved back from 125% to 100%.WM_DPICHANGEDdoes not forward the event because the shell's native zoom is still 100 (the event to change it is only queued but not processed), just like the new zoom. So only the first event will be processed, leaving behind a 125% shell on a 100% monitor.A solution would be to remove the condition such that every call to
WM_DPICHANGEDwill result in an event to be processed. As an alternative, the initial event on shell level could be processed synchronously to immediately set the shell's native zoom.Another effect of the above issue is that the shell can shrink or enlarge when rapidly moving around. That will also be fixed with the solution proposals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I removed this condition. I don't see any harm in doing it, actually I just verified it by injecting the same multiple events for the same zoom change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you now made the event processing at shell level synchronous, it would probably be possible to revert that change.