@@ -158,13 +158,14 @@ internal static int Run(int waitMilliseconds)
158158 var lastShellPoll = Stopwatch . StartNew ( ) ;
159159 var lastCenterFallback = Stopwatch . StartNew ( ) ;
160160 var eventSettle = new Stopwatch ( ) ;
161+ var transparencySettle = new Stopwatch ( ) ;
161162
162163 using ( var backdrops = new WallpaperBackdropManager ( ) )
163164 using ( var events = new TaskbarEventWatcher ( previous ) )
164165 {
165166 bool fullscreen = FullscreenState . IsForegroundFullscreen ( ) ;
166167 backdrops . SetVisible ( ! fullscreen ) ;
167- if ( ! backdrops . Refresh ( previous , true )
168+ if ( ! backdrops . Refresh ( previous , true , true )
168169 || ! TaskbarCenter . CenterImmediately ( previous ) )
169170 {
170171 return 3 ;
@@ -177,7 +178,11 @@ internal static int Run(int waitMilliseconds)
177178 {
178179 bool settling = eventSettle . IsRunning
179180 && eventSettle . ElapsedMilliseconds < EventSettleMilliseconds ;
180- int loopWaitMilliseconds = TaskbarCenter . HasActiveAnimation || settling
181+ bool transparencySettling = transparencySettle . IsRunning
182+ && transparencySettle . ElapsedMilliseconds < EventSettleMilliseconds ;
183+ int loopWaitMilliseconds = TaskbarCenter . HasActiveAnimation
184+ || settling
185+ || transparencySettling
181186 ? AnimationFrameMilliseconds
182187 : PollMilliseconds ;
183188 TaskbarEventKind eventKind = events . Wait ( loopWaitMilliseconds ) ;
@@ -187,13 +192,31 @@ internal static int Run(int waitMilliseconds)
187192 eventSettle . Restart ( ) ;
188193 }
189194
195+ bool transparencyEvent = IsTransparencyReassertEvent ( eventKind ) ;
196+ if ( transparencyEvent )
197+ {
198+ transparencySettle . Restart ( ) ;
199+ }
200+
190201 bool currentFullscreen = FullscreenState . IsForegroundFullscreen ( ) ;
191- if ( fullscreen != currentFullscreen )
202+ bool fullscreenChanged = fullscreen != currentFullscreen ;
203+ if ( fullscreenChanged )
192204 {
193205 fullscreen = currentFullscreen ;
194206 backdrops . SetVisible ( ! fullscreen ) ;
207+ }
208+
209+ bool transparencySettleDue = transparencySettle . IsRunning
210+ && transparencySettle . ElapsedMilliseconds >= EventSettleMilliseconds ;
211+ if ( fullscreenChanged || transparencyEvent || transparencySettleDue )
212+ {
195213 TaskbarAccent . Apply ( current , AccentState . EnableTransparentGradient ) ;
214+ backdrops . Refresh ( current , false , true ) ;
196215 lastApplied . Restart ( ) ;
216+ if ( transparencySettleDue )
217+ {
218+ transparencySettle . Reset ( ) ;
219+ }
197220 }
198221
199222 bool taskbarsChanged = false ;
@@ -217,7 +240,10 @@ internal static int Run(int waitMilliseconds)
217240
218241 bool refreshSource =
219242 lastSourceRefresh . ElapsedMilliseconds >= SourceRefreshMilliseconds ;
220- backdrops . Refresh ( current , refreshSource ) ;
243+ backdrops . Refresh (
244+ current ,
245+ refreshSource ,
246+ taskbarsChanged || refreshSource ) ;
221247 if ( refreshSource )
222248 {
223249 lastSourceRefresh . Restart ( ) ;
@@ -277,19 +303,27 @@ internal static bool HaveSameHandles(IList<IntPtr> left, IList<IntPtr> right)
277303
278304 return true ;
279305 }
306+
307+ internal static bool IsTransparencyReassertEvent ( TaskbarEventKind eventKind )
308+ {
309+ return eventKind == TaskbarEventKind . Centering
310+ || eventKind == TaskbarEventKind . Foreground ;
311+ }
280312 }
281313
282314 internal enum TaskbarEventKind
283315 {
284316 None ,
285317 Centering ,
286- Foreground
318+ Foreground ,
319+ ForegroundLocation
287320 }
288321
289322 internal sealed class TaskbarEventWatcher : IDisposable
290323 {
291324 private readonly AutoResetEvent _centeringChanged = new AutoResetEvent ( false ) ;
292325 private readonly AutoResetEvent _foregroundChanged = new AutoResetEvent ( false ) ;
326+ private readonly AutoResetEvent _foregroundLocationChanged = new AutoResetEvent ( false ) ;
293327 private readonly WaitHandle [ ] _waitHandles ;
294328 private readonly ManualResetEvent _ready = new ManualResetEvent ( false ) ;
295329 private readonly NativeMethods . WinEventProc _callback ;
@@ -306,7 +340,12 @@ internal sealed class TaskbarEventWatcher : IDisposable
306340 internal TaskbarEventWatcher ( IList < IntPtr > taskbars )
307341 {
308342 _callback = OnWinEvent ;
309- _waitHandles = new WaitHandle [ ] { _centeringChanged , _foregroundChanged } ;
343+ _waitHandles = new WaitHandle [ ]
344+ {
345+ _centeringChanged ,
346+ _foregroundChanged ,
347+ _foregroundLocationChanged
348+ } ;
310349 Refresh ( taskbars ) ;
311350 _thread = new Thread ( RunMessageLoop )
312351 {
@@ -325,8 +364,13 @@ internal TaskbarEventKind Wait(int milliseconds)
325364 return TaskbarEventKind . Centering ;
326365 }
327366
328- return result == 1
329- ? TaskbarEventKind . Foreground
367+ if ( result == 1 )
368+ {
369+ return TaskbarEventKind . Foreground ;
370+ }
371+
372+ return result == 2
373+ ? TaskbarEventKind . ForegroundLocation
330374 : TaskbarEventKind . None ;
331375 }
332376
@@ -375,6 +419,7 @@ public void Dispose()
375419 _thread . Join ( 5000 ) ;
376420 _centeringChanged . Dispose ( ) ;
377421 _foregroundChanged . Dispose ( ) ;
422+ _foregroundLocationChanged . Dispose ( ) ;
378423 _ready . Dispose ( ) ;
379424 }
380425
@@ -481,7 +526,7 @@ private void OnWinEvent(
481526 if ( eventType == NativeMethods . EventObjectLocationChange
482527 && window == _foregroundWindow )
483528 {
484- _foregroundChanged . Set ( ) ;
529+ _foregroundLocationChanged . Set ( ) ;
485530 }
486531
487532 if ( IsCenteringEvent ( eventType ) && _windows . Contains ( window ) )
@@ -576,7 +621,7 @@ internal sealed class WallpaperBackdropManager : IDisposable
576621 private IntPtr _source ;
577622 private bool _visible = true ;
578623
579- internal bool Refresh ( IList < IntPtr > taskbars , bool refreshSource )
624+ internal bool Refresh ( IList < IntPtr > taskbars , bool refreshSource , bool reassert )
580625 {
581626 var activeTaskbars = new HashSet < IntPtr > ( taskbars ) ;
582627 var removed = new List < IntPtr > ( ) ;
@@ -615,7 +660,7 @@ internal bool Refresh(IList<IntPtr> taskbars, bool refreshSource)
615660 _backdrops . Add ( taskbar , backdrop ) ;
616661 }
617662
618- success = backdrop . Refresh ( _source , refreshSource , _visible ) && success ;
663+ success = backdrop . Refresh ( _source , reassert , _visible ) && success ;
619664 }
620665
621666 return success ;
0 commit comments