16
16
17
17
18
18
import java .util .*;
19
+ import java .util .concurrent .atomic .*;
19
20
import java .util .stream .*;
20
21
21
22
import org .eclipse .swt .*;
@@ -4760,7 +4761,7 @@ public boolean setParent (Composite parent) {
4760
4761
if (parent .nativeZoom != nativeZoom ) {
4761
4762
int newZoom = parent .nativeZoom ;
4762
4763
Event zoomChangedEvent = createZoomChangedEvent (newZoom );
4763
- notifyListeners ( SWT . ZoomChanged , zoomChangedEvent );
4764
+ sendZoomChangedEvent ( zoomChangedEvent , getShell () );
4764
4765
}
4765
4766
int flags = OS .SWP_NOSIZE | OS .SWP_NOMOVE | OS .SWP_NOACTIVATE ;
4766
4767
OS .SetWindowPos (topHandle , OS .HWND_BOTTOM , 0 , 0 , 0 , 0 , flags );
@@ -4953,9 +4954,14 @@ LRESULT WM_DESTROY (long wParam, long lParam) {
4953
4954
return null ;
4954
4955
}
4955
4956
4956
- void handleMonitorSpecificDpiChange (int newNativeZoom , Rectangle newBoundsInPixels ) {
4957
+ private void handleMonitorSpecificDpiChange (int newNativeZoom , Rectangle newBoundsInPixels ) {
4957
4958
DPIUtil .setDeviceZoom (newNativeZoom );
4958
4959
Event zoomChangedEvent = createZoomChangedEvent (newNativeZoom );
4960
+ Shell shell = getShell ();
4961
+ if (shell .currentDpiChangeEvent != null ) {
4962
+ shell .currentDpiChangeEvent .doit = false ;
4963
+ }
4964
+ shell .currentDpiChangeEvent = zoomChangedEvent ;
4959
4965
notifyListeners (SWT .ZoomChanged , zoomChangedEvent );
4960
4966
this .setBoundsInPixels (newBoundsInPixels .x , newBoundsInPixels .y , newBoundsInPixels .width , newBoundsInPixels .height );
4961
4967
}
@@ -4966,6 +4972,7 @@ private Event createZoomChangedEvent(int zoom) {
4966
4972
event .widget = this ;
4967
4973
event .detail = zoom ;
4968
4974
event .doit = true ;
4975
+ event .data = new AtomicInteger (0 );
4969
4976
return event ;
4970
4977
}
4971
4978
@@ -4974,12 +4981,10 @@ LRESULT WM_DPICHANGED (long wParam, long lParam) {
4974
4981
int newNativeZoom = DPIUtil .mapDPIToZoom (OS .HIWORD (wParam ));
4975
4982
if (getDisplay ().isRescalingAtRuntime ()) {
4976
4983
Device .win32_destroyUnusedHandles (getDisplay ());
4977
- if (newNativeZoom != nativeZoom ) {
4978
- RECT rect = new RECT ();
4979
- COM .MoveMemory (rect , lParam , RECT .sizeof );
4980
- handleMonitorSpecificDpiChange (newNativeZoom , new Rectangle (rect .left , rect .top , rect .right - rect .left , rect .bottom -rect .top ));
4981
- return LRESULT .ZERO ;
4982
- }
4984
+ RECT rect = new RECT ();
4985
+ COM .MoveMemory (rect , lParam , RECT .sizeof );
4986
+ handleMonitorSpecificDpiChange (newNativeZoom , new Rectangle (rect .left , rect .top , rect .right - rect .left , rect .bottom -rect .top ));
4987
+ return LRESULT .ZERO ;
4983
4988
} else {
4984
4989
int newZoom = DPIUtil .getZoomForAutoscaleProperty (newNativeZoom );
4985
4990
int oldZoom = DPIUtil .getZoomForAutoscaleProperty (nativeZoom );
@@ -5879,6 +5884,29 @@ LRESULT wmScrollChild (long wParam, long lParam) {
5879
5884
return null ;
5880
5885
}
5881
5886
5887
+ void sendZoomChangedEvent (Event event , Shell shell ) {
5888
+ AtomicInteger handleDPIChangedScheduledTasksCount = (AtomicInteger ) event .data ;
5889
+ handleDPIChangedScheduledTasksCount .incrementAndGet ();
5890
+ getDisplay ().asyncExec (() -> {
5891
+ try {
5892
+ if (!this .isDisposed () && event .doit ) {
5893
+ notifyListeners (SWT .ZoomChanged , event );
5894
+ }
5895
+ } finally {
5896
+ if (shell .isDisposed ()) {
5897
+ return ;
5898
+ }
5899
+ if (handleDPIChangedScheduledTasksCount .decrementAndGet () <= 0 ) {
5900
+ if (event == shell .currentDpiChangeEvent ) {
5901
+ shell .currentDpiChangeEvent = null ;
5902
+ }
5903
+ if (event .doit ) {
5904
+ shell .WM_SIZE (0 , 0 );
5905
+ }
5906
+ }
5907
+ }
5908
+ });
5909
+ }
5882
5910
5883
5911
@ Override
5884
5912
void handleDPIChange (Event event , float scalingFactor ) {
0 commit comments