1616
1717
1818import java .util .*;
19+ import java .util .concurrent .atomic .*;
1920import java .util .stream .*;
2021
2122import org .eclipse .swt .*;
@@ -4757,7 +4758,7 @@ public boolean setParent (Composite parent) {
47574758 if (parent .nativeZoom != nativeZoom ) {
47584759 int newZoom = parent .nativeZoom ;
47594760 Event zoomChangedEvent = createZoomChangedEvent (newZoom );
4760- notifyListeners ( SWT . ZoomChanged , zoomChangedEvent );
4761+ sendZoomChangedEvent ( zoomChangedEvent , getShell () );
47614762 }
47624763 int flags = OS .SWP_NOSIZE | OS .SWP_NOMOVE | OS .SWP_NOACTIVATE ;
47634764 OS .SetWindowPos (topHandle , OS .HWND_BOTTOM , 0 , 0 , 0 , 0 , flags );
@@ -4950,11 +4951,16 @@ LRESULT WM_DESTROY (long wParam, long lParam) {
49504951 return null ;
49514952}
49524953
4953- void handleMonitorSpecificDpiChange (int newNativeZoom , Rectangle newBoundsInPixels ) {
4954+ private void handleMonitorSpecificDpiChange (int newNativeZoom , Rectangle newBoundsInPixels ) {
49544955 DPIUtil .setDeviceZoom (newNativeZoom );
49554956 Event zoomChangedEvent = createZoomChangedEvent (newNativeZoom );
4956- notifyListeners (SWT .ZoomChanged , zoomChangedEvent );
4957+ Shell shell = getShell ();
4958+ if (shell .currentDpiChangeEvent != null ) {
4959+ shell .currentDpiChangeEvent .doit = false ;
4960+ }
4961+ shell .currentDpiChangeEvent = zoomChangedEvent ;
49574962 this .setBoundsInPixels (newBoundsInPixels .x , newBoundsInPixels .y , newBoundsInPixels .width , newBoundsInPixels .height );
4963+ sendZoomChangedEvent (zoomChangedEvent , shell );
49584964}
49594965
49604966private Event createZoomChangedEvent (int zoom ) {
@@ -4963,20 +4969,20 @@ private Event createZoomChangedEvent(int zoom) {
49634969 event .widget = this ;
49644970 event .detail = zoom ;
49654971 event .doit = true ;
4972+ event .data = new AtomicInteger (0 );
49664973 return event ;
49674974}
49684975
49694976LRESULT WM_DPICHANGED (long wParam , long lParam ) {
49704977 // Map DPI to Zoom and compare
49714978 int newNativeZoom = DPIUtil .mapDPIToZoom (OS .HIWORD (wParam ));
49724979 if (getDisplay ().isRescalingAtRuntime ()) {
4980+ System .out .println ("Handle change " + nativeZoom + " -> " + newNativeZoom );
49734981 Device .win32_destroyUnusedHandles (getDisplay ());
4974- if (newNativeZoom != nativeZoom ) {
4975- RECT rect = new RECT ();
4976- COM .MoveMemory (rect , lParam , RECT .sizeof );
4977- handleMonitorSpecificDpiChange (newNativeZoom , new Rectangle (rect .left , rect .top , rect .right - rect .left , rect .bottom -rect .top ));
4978- return LRESULT .ZERO ;
4979- }
4982+ RECT rect = new RECT ();
4983+ COM .MoveMemory (rect , lParam , RECT .sizeof );
4984+ handleMonitorSpecificDpiChange (newNativeZoom , new Rectangle (rect .left , rect .top , rect .right - rect .left , rect .bottom -rect .top ));
4985+ return LRESULT .ZERO ;
49804986 } else {
49814987 int newZoom = DPIUtil .getZoomForAutoscaleProperty (newNativeZoom );
49824988 int oldZoom = DPIUtil .getZoomForAutoscaleProperty (nativeZoom );
@@ -5876,6 +5882,29 @@ LRESULT wmScrollChild (long wParam, long lParam) {
58765882 return null ;
58775883}
58785884
5885+ void sendZoomChangedEvent (Event event , Shell shell ) {
5886+ AtomicInteger handleDPIChangedScheduledTasksCount = (AtomicInteger ) event .data ;
5887+ handleDPIChangedScheduledTasksCount .incrementAndGet ();
5888+ getDisplay ().asyncExec (() -> {
5889+ try {
5890+ if (!this .isDisposed () && event .doit ) {
5891+ notifyListeners (SWT .ZoomChanged , event );
5892+ }
5893+ } finally {
5894+ if (shell .isDisposed ()) {
5895+ return ;
5896+ }
5897+ if (handleDPIChangedScheduledTasksCount .decrementAndGet () <= 0 ) {
5898+ if (event == shell .currentDpiChangeEvent ) {
5899+ shell .currentDpiChangeEvent = null ;
5900+ }
5901+ if (event .doit ) {
5902+ shell .WM_SIZE (0 , 0 );
5903+ }
5904+ }
5905+ }
5906+ });
5907+ }
58795908
58805909@ Override
58815910void handleDPIChange (Event event , float scalingFactor ) {
0 commit comments