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 .*;
@@ -78,6 +79,9 @@ public abstract class Control extends Widget implements Drawable {
78
79
Font font ;
79
80
int drawCount , foreground , background , backgroundAlpha = 255 ;
80
81
82
+ /** Cache for currently processed DPI change event to be able to cancel it if a new one is triggered */
83
+ private Event currentDpiChangeEvent ;
84
+
81
85
/**
82
86
* Prevents uninitialized instances from being created outside the package.
83
87
*/
@@ -4757,7 +4761,7 @@ public boolean setParent (Composite parent) {
4757
4761
if (parent .nativeZoom != nativeZoom ) {
4758
4762
int newZoom = parent .nativeZoom ;
4759
4763
Event zoomChangedEvent = createZoomChangedEvent (newZoom );
4760
- notifyListeners ( SWT . ZoomChanged , zoomChangedEvent );
4764
+ sendZoomChangedEvent ( zoomChangedEvent , getShell () );
4761
4765
}
4762
4766
int flags = OS .SWP_NOSIZE | OS .SWP_NOMOVE | OS .SWP_NOACTIVATE ;
4763
4767
OS .SetWindowPos (topHandle , OS .HWND_BOTTOM , 0 , 0 , 0 , 0 , flags );
@@ -4950,11 +4954,15 @@ LRESULT WM_DESTROY (long wParam, long lParam) {
4950
4954
return null ;
4951
4955
}
4952
4956
4953
- void handleMonitorSpecificDpiChange (int newNativeZoom , Rectangle newBoundsInPixels ) {
4957
+ private void handleMonitorSpecificDpiChange (int newNativeZoom , Rectangle newBoundsInPixels ) {
4954
4958
DPIUtil .setDeviceZoom (newNativeZoom );
4955
4959
Event zoomChangedEvent = createZoomChangedEvent (newNativeZoom );
4956
- notifyListeners (SWT .ZoomChanged , zoomChangedEvent );
4960
+ if (currentDpiChangeEvent != null ) {
4961
+ currentDpiChangeEvent .doit = false ;
4962
+ }
4963
+ currentDpiChangeEvent = zoomChangedEvent ;
4957
4964
this .setBoundsInPixels (newBoundsInPixels .x , newBoundsInPixels .y , newBoundsInPixels .width , newBoundsInPixels .height );
4965
+ sendZoomChangedEvent (zoomChangedEvent , getShell ());
4958
4966
}
4959
4967
4960
4968
private Event createZoomChangedEvent (int zoom ) {
@@ -4963,6 +4971,7 @@ private Event createZoomChangedEvent(int zoom) {
4963
4971
event .widget = this ;
4964
4972
event .detail = zoom ;
4965
4973
event .doit = true ;
4974
+ event .data = new AtomicInteger (0 );
4966
4975
return event ;
4967
4976
}
4968
4977
@@ -5876,6 +5885,27 @@ LRESULT wmScrollChild (long wParam, long lParam) {
5876
5885
return null ;
5877
5886
}
5878
5887
5888
+ void sendZoomChangedEvent (Event event , Shell shell ) {
5889
+ AtomicInteger handleDPIChangedScheduledTasksCount = (AtomicInteger ) event .data ;
5890
+ handleDPIChangedScheduledTasksCount .incrementAndGet ();
5891
+ getDisplay ().asyncExec (() -> {
5892
+ try {
5893
+ if (!this .isDisposed () && event .doit ) {
5894
+ notifyListeners (SWT .ZoomChanged , event );
5895
+ }
5896
+ } finally {
5897
+ if (shell .isDisposed ()) {
5898
+ return ;
5899
+ }
5900
+ if (handleDPIChangedScheduledTasksCount .decrementAndGet () <= 0 ) {
5901
+ currentDpiChangeEvent = null ;
5902
+ if (event .doit ) {
5903
+ shell .WM_SIZE (0 , 0 );
5904
+ }
5905
+ }
5906
+ }
5907
+ });
5908
+ }
5879
5909
5880
5910
@ Override
5881
5911
void handleDPIChange (Event event , float scalingFactor ) {
0 commit comments