2727using System . Windows . Media . Animation ;
2828using System . Windows . Shell ;
2929using Wpf . Ui . Violeta . Controls ;
30+ using static QuickLook . Common . NativeMethods . Dwmapi ;
3031using Brush = System . Windows . Media . Brush ;
3132using FontFamily = System . Windows . Media . FontFamily ;
3233using Size = System . Windows . Size ;
@@ -157,6 +158,12 @@ internal ViewerWindow()
157158 base . Close ( ) ;
158159 }
159160
161+ protected override void OnSourceInitialized ( EventArgs e )
162+ {
163+ base . OnSourceInitialized ( e ) ;
164+ ApplyWindowBackgroundEffects ( ) ;
165+ }
166+
160167 public override void OnApplyTemplate ( )
161168 {
162169 base . OnApplyTemplate ( ) ;
@@ -171,31 +178,14 @@ private void ApplyWindowBackgroundEffects()
171178 var useTransparency = SettingHelper . Get ( "UseTransparency" , true )
172179 && SystemParameters . IsGlassEnabled
173180 && ! App . IsGPUInBlacklist ;
181+ var backdrop = GetBackdropOption ( ) ;
174182
175183 var windowChrome = WindowChrome . GetWindowChrome ( this ) ;
176184 windowChrome ? . GlassFrameThickness = useTransparency ? new Thickness ( 1 ) : new Thickness ( 0 ) ;
177185
178186 if ( useTransparency )
179187 {
180- if ( App . IsWin11 )
181- {
182- if ( Environment . OSVersion . Version >= new Version ( 10 , 0 , 22523 ) )
183- {
184- WindowHelper . EnableBackdropMicaBlur ( this , CurrentTheme == Themes . Dark ) ;
185- }
186- else
187- {
188- WindowHelper . EnableMicaBlur ( this , CurrentTheme == Themes . Dark ) ;
189- }
190- }
191- else if ( App . IsWin10 )
192- {
193- WindowHelper . EnableBlur ( this ) ;
194- }
195- else
196- {
197- Background = ( Brush ) FindResource ( "MainWindowBackgroundNoTransparent" ) ;
198- }
188+ ApplyBackdrop ( backdrop ) ;
199189 }
200190 else
201191 {
@@ -216,6 +206,123 @@ private void ApplyWindowBackgroundEffects()
216206 }
217207 }
218208
209+ private void ApplyBackdrop ( SystembackdropType backdrop )
210+ {
211+ switch ( backdrop )
212+ {
213+ case SystembackdropType . None :
214+ Background = ( Brush ) FindResource ( "MainWindowBackgroundNoTransparent" ) ;
215+ break ;
216+
217+ case SystembackdropType . Mica :
218+ if ( App . IsWin11 )
219+ {
220+ if ( Environment . OSVersion . Version >= new Version ( 10 , 0 , 22523 ) )
221+ {
222+ WindowHelper . DisableDwmBlur ( this ) ;
223+ WindowHelper . EnableBackdropMicaBlur ( this , CurrentTheme == Themes . Dark ) ;
224+ }
225+ else
226+ {
227+ WindowHelper . DisableDwmBlur ( this ) ;
228+ WindowHelper . EnableMicaBlur ( this , CurrentTheme == Themes . Dark ) ;
229+ }
230+ }
231+ else if ( App . IsWin10 )
232+ {
233+ WindowHelper . DisableDwmBlur ( this ) ;
234+ WindowHelper . EnableBlur ( this ) ;
235+ }
236+ else
237+ {
238+ Background = ( Brush ) FindResource ( "MainWindowBackgroundNoTransparent" ) ;
239+ }
240+
241+ break ;
242+
243+ case SystembackdropType . Acrylic :
244+ if ( App . IsWin11 && Environment . OSVersion . Version >= new Version ( 10 , 0 , 22523 ) )
245+ {
246+ WindowHelper . DisableDwmBlur ( this ) ;
247+ WindowHelper . EnableBackdropAcrylicBlur ( this , CurrentTheme == Themes . Dark ) ;
248+ }
249+ else if ( App . IsWin10 )
250+ {
251+ WindowHelper . DisableDwmBlur ( this ) ;
252+ WindowHelper . EnableBlur ( this ) ;
253+ }
254+ else
255+ {
256+ Background = ( Brush ) FindResource ( "MainWindowBackgroundNoTransparent" ) ;
257+ }
258+
259+ break ;
260+
261+ case SystembackdropType . Tabbed :
262+ if ( App . IsWin11 && Environment . OSVersion . Version >= new Version ( 10 , 0 , 22523 ) )
263+ {
264+ WindowHelper . DisableDwmBlur ( this ) ;
265+ WindowHelper . EnableBackdropTabbedBlur ( this , CurrentTheme == Themes . Dark ) ;
266+ }
267+ else if ( App . IsWin10 )
268+ {
269+ WindowHelper . DisableDwmBlur ( this ) ;
270+ WindowHelper . EnableBlur ( this ) ;
271+ }
272+ else
273+ {
274+ Background = ( Brush ) FindResource ( "MainWindowBackgroundNoTransparent" ) ;
275+ }
276+
277+ break ;
278+
279+ case SystembackdropType . Auto :
280+ default :
281+ if ( App . IsWin11 )
282+ {
283+ if ( Environment . OSVersion . Version >= new Version ( 10 , 0 , 22523 ) )
284+ {
285+ WindowHelper . DisableDwmBlur ( this ) ;
286+ WindowHelper . EnableBackdropMicaBlur ( this , CurrentTheme == Themes . Dark ) ;
287+ }
288+ else
289+ {
290+ WindowHelper . DisableDwmBlur ( this ) ;
291+ WindowHelper . EnableMicaBlur ( this , CurrentTheme == Themes . Dark ) ;
292+ }
293+ }
294+ else if ( App . IsWin10 )
295+ {
296+ WindowHelper . DisableDwmBlur ( this ) ;
297+ WindowHelper . EnableBlur ( this ) ;
298+ }
299+ else
300+ {
301+ Background = ( Brush ) FindResource ( "MainWindowBackgroundNoTransparent" ) ;
302+ }
303+
304+ break ;
305+ }
306+ }
307+
308+ private static SystembackdropType GetBackdropOption ( )
309+ {
310+ var option = SettingHelper . Get ( "WindowBackdrop" , nameof ( SystembackdropType . Auto ) , "QuickLook" ) ? . Trim ( ) ;
311+
312+ if ( string . IsNullOrEmpty ( option ) )
313+ return SystembackdropType . Auto ;
314+
315+ if ( string . Equals ( option , nameof ( SystembackdropType . Acrylic ) , StringComparison . OrdinalIgnoreCase ) )
316+ return SystembackdropType . Acrylic ;
317+
318+ if ( string . Equals ( option , nameof ( SystembackdropType . Tabbed ) , StringComparison . OrdinalIgnoreCase ) )
319+ return SystembackdropType . Tabbed ;
320+
321+ return Enum . TryParse ( option , true , out SystembackdropType parsed )
322+ ? parsed
323+ : SystembackdropType . Auto ;
324+ }
325+
219326 private void SaveWindowSizeOnSizeChanged ( object sender , SizeChangedEventArgs e )
220327 {
221328 // first shown?
0 commit comments