2222using Flow . Launcher . Plugin ;
2323using static System . Windows . Forms . VisualStyles . VisualStyleElement ;
2424using TextBox = System . Windows . Controls . TextBox ;
25+ using System . Windows . Threading ;
26+ using static System . Windows . Forms . VisualStyles . VisualStyleElement . StartPanel ;
2527
2628namespace Flow . Launcher . Core . Resource
2729{
@@ -343,6 +345,68 @@ private Color GetWindowBorderStyleBackground()
343345 return Colors . Transparent ; // Default is transparent
344346 }
345347
348+ private void ApplyPreviewBackground ( Color bgColor )
349+ {
350+ Application . Current . Dispatcher . Invoke ( ( ) =>
351+ {
352+ Style baseStyle = null ;
353+
354+ // ✅ `WindowBorderStyle`이 존재하면 가져오기
355+ if ( Application . Current . Resources . Contains ( "WindowBorderStyle" ) )
356+ {
357+ baseStyle = Application . Current . Resources [ "WindowBorderStyle" ] as Style ;
358+ }
359+
360+ // ✅ `WindowBorderStyle`이 없으면 `Base.xaml`의 기본 스타일 사용
361+ if ( baseStyle == null && Application . Current . Resources . Contains ( "BaseWindowBorderStyle" ) )
362+ {
363+ baseStyle = Application . Current . Resources [ "BaseWindowBorderStyle" ] as Style ;
364+ }
365+
366+ // ✅ 투명도가 존재하면 불투명한 색상으로 변경
367+ if ( bgColor . A < 255 )
368+ {
369+ bgColor = Color . FromRgb ( bgColor . R , bgColor . G , bgColor . B ) ; // 알파값 제거
370+ }
371+
372+ // ✅ 기존 스타일이 존재하면 복사하여 새로운 스타일 생성
373+ if ( baseStyle != null )
374+ {
375+ var newStyle = new Style ( typeof ( Border ) ) ;
376+
377+ // ✅ 기존 스타일의 Setter를 복사 (Background 제외)
378+ foreach ( var setter in baseStyle . Setters . OfType < Setter > ( ) )
379+ {
380+ if ( setter . Property != Border . BackgroundProperty ) // Background는 새 값으로 대체
381+ {
382+ newStyle . Setters . Add ( new Setter ( setter . Property , setter . Value ) ) ;
383+ }
384+ }
385+
386+ // ✅ 새로운 Background Setter 추가
387+ newStyle . Setters . Add ( new Setter ( Border . BackgroundProperty , new SolidColorBrush ( bgColor ) ) ) ;
388+
389+ // ✅ 새 스타일을 `PreviewWindowBorderStyle`로 적용
390+ Application . Current . Resources [ "PreviewWindowBorderStyle" ] = newStyle ;
391+ }
392+ else
393+ {
394+ // ✅ `WindowBorderStyle`이 없으면 기본 스타일 생성
395+ var defaultStyle = new Style ( typeof ( Border ) ) ;
396+ defaultStyle . Setters . Add ( new Setter ( Border . BackgroundProperty , new SolidColorBrush ( bgColor ) ) ) ;
397+ defaultStyle . Setters . Add ( new Setter ( Border . BorderThicknessProperty , new Thickness ( 0 ) ) ) ;
398+ defaultStyle . Setters . Add ( new Setter ( Border . CornerRadiusProperty , new CornerRadius ( 5 ) ) ) ;
399+ defaultStyle . Setters . Add ( new Setter ( Border . UseLayoutRoundingProperty , true ) ) ;
400+ defaultStyle . Setters . Add ( new Setter ( Border . SnapsToDevicePixelsProperty , true ) ) ;
401+
402+ Application . Current . Resources [ "PreviewWindowBorderStyle" ] = defaultStyle ;
403+ }
404+ } , DispatcherPriority . Render ) ;
405+ }
406+
407+
408+
409+
346410 public void ThemeModeColor ( string Mode )
347411 {
348412 var dict = GetThemeResourceDictionary ( _settings . Theme ) ;
@@ -381,12 +445,14 @@ public void ThemeModeColor(string Mode)
381445 {
382446 if ( isDarkMode )
383447 {
448+ ApplyPreviewBackground ( darkBG ) ;
384449 mainWindow . Background = new SolidColorBrush ( darkBG ) ;
385450 Methods . SetWindowAttribute ( new WindowInteropHelper ( mainWindow ) . Handle , DWMWINDOWATTRIBUTE . DWMWA_USE_IMMERSIVE_DARK_MODE , 1 ) ;
386451 return ;
387452 }
388453 else
389454 {
455+ ApplyPreviewBackground ( lightBG ) ;
390456 mainWindow . Background = new SolidColorBrush ( lightBG ) ;
391457 Methods . SetWindowAttribute ( new WindowInteropHelper ( mainWindow ) . Handle , DWMWINDOWATTRIBUTE . DWMWA_USE_IMMERSIVE_DARK_MODE , 0 ) ;
392458 return ;
@@ -396,12 +462,14 @@ public void ThemeModeColor(string Mode)
396462 {
397463 if ( colorScheme == "Dark" )
398464 {
465+ ApplyPreviewBackground ( darkBG ) ;
399466 mainWindow . Background = new SolidColorBrush ( darkBG ) ;
400467 Methods . SetWindowAttribute ( new WindowInteropHelper ( mainWindow ) . Handle , DWMWINDOWATTRIBUTE . DWMWA_USE_IMMERSIVE_DARK_MODE , 1 ) ;
401468 return ;
402469 }
403470 else if ( colorScheme == "Light" )
404471 {
472+ ApplyPreviewBackground ( lightBG ) ;
405473 mainWindow . Background = new SolidColorBrush ( lightBG ) ;
406474 Methods . SetWindowAttribute ( new WindowInteropHelper ( mainWindow ) . Handle , DWMWINDOWATTRIBUTE . DWMWA_USE_IMMERSIVE_DARK_MODE , 0 ) ;
407475 return ;
@@ -411,17 +479,20 @@ public void ThemeModeColor(string Mode)
411479 else if ( Mode == "Dark" )
412480 {
413481 mainWindow . Background = new SolidColorBrush ( darkBG ) ;
482+ ApplyPreviewBackground ( darkBG ) ;
414483 Methods . SetWindowAttribute ( new WindowInteropHelper ( mainWindow ) . Handle , DWMWINDOWATTRIBUTE . DWMWA_USE_IMMERSIVE_DARK_MODE , 1 ) ;
415484 return ;
416485 }
417486 else if ( Mode == "Light" )
418487 {
419488 mainWindow . Background = new SolidColorBrush ( lightBG ) ;
489+ ApplyPreviewBackground ( lightBG ) ;
420490 Methods . SetWindowAttribute ( new WindowInteropHelper ( mainWindow ) . Handle , DWMWINDOWATTRIBUTE . DWMWA_USE_IMMERSIVE_DARK_MODE , 0 ) ;
421491 return ;
422492 }
423493 else
424494 {
495+ ApplyPreviewBackground ( lightBG ) ;
425496 mainWindow . Background = new SolidColorBrush ( Color . FromArgb ( 1 , 0 , 0 , 0 ) ) ;
426497 }
427498 }
@@ -464,12 +535,14 @@ public void ThemeModeColorforMica(string Mode)
464535 {
465536 if ( isDarkMode )
466537 {
538+ ApplyPreviewBackground ( darkBG ) ;
467539 mainWindow . Background = new SolidColorBrush ( Color . FromArgb ( 1 , 0 , 0 , 0 ) ) ;
468540 Methods . SetWindowAttribute ( new WindowInteropHelper ( mainWindow ) . Handle , DWMWINDOWATTRIBUTE . DWMWA_USE_IMMERSIVE_DARK_MODE , 1 ) ;
469541 return ;
470542 }
471543 else
472544 {
545+ ApplyPreviewBackground ( lightBG ) ;
473546 mainWindow . Background = new SolidColorBrush ( Color . FromArgb ( 1 , 0 , 0 , 0 ) ) ;
474547 Methods . SetWindowAttribute ( new WindowInteropHelper ( mainWindow ) . Handle , DWMWINDOWATTRIBUTE . DWMWA_USE_IMMERSIVE_DARK_MODE , 0 ) ;
475548 return ;
@@ -479,12 +552,14 @@ public void ThemeModeColorforMica(string Mode)
479552 {
480553 if ( colorScheme == "Dark" )
481554 {
555+ ApplyPreviewBackground ( darkBG ) ;
482556 mainWindow . Background = new SolidColorBrush ( Color . FromArgb ( 1 , 0 , 0 , 0 ) ) ;
483557 Methods . SetWindowAttribute ( new WindowInteropHelper ( mainWindow ) . Handle , DWMWINDOWATTRIBUTE . DWMWA_USE_IMMERSIVE_DARK_MODE , 1 ) ;
484558 return ;
485559 }
486560 else if ( colorScheme == "Light" )
487561 {
562+ ApplyPreviewBackground ( lightBG ) ;
488563 mainWindow . Background = new SolidColorBrush ( Color . FromArgb ( 1 , 0 , 0 , 0 ) ) ;
489564 Methods . SetWindowAttribute ( new WindowInteropHelper ( mainWindow ) . Handle , DWMWINDOWATTRIBUTE . DWMWA_USE_IMMERSIVE_DARK_MODE , 0 ) ;
490565 return ;
@@ -493,18 +568,21 @@ public void ThemeModeColorforMica(string Mode)
493568 }
494569 else if ( Mode == "Dark" )
495570 {
571+ ApplyPreviewBackground ( darkBG ) ;
496572 mainWindow . Background = new SolidColorBrush ( Color . FromArgb ( 1 , 0 , 0 , 0 ) ) ;
497573 Methods . SetWindowAttribute ( new WindowInteropHelper ( mainWindow ) . Handle , DWMWINDOWATTRIBUTE . DWMWA_USE_IMMERSIVE_DARK_MODE , 1 ) ;
498574 return ;
499575 }
500576 else if ( Mode == "Light" )
501577 {
578+ ApplyPreviewBackground ( lightBG ) ;
502579 mainWindow . Background = new SolidColorBrush ( Color . FromArgb ( 1 , 0 , 0 , 0 ) ) ;
503580 Methods . SetWindowAttribute ( new WindowInteropHelper ( mainWindow ) . Handle , DWMWINDOWATTRIBUTE . DWMWA_USE_IMMERSIVE_DARK_MODE , 0 ) ;
504581 return ;
505582 }
506583 else
507584 {
585+ ApplyPreviewBackground ( lightBG ) ;
508586 mainWindow . Background = new SolidColorBrush ( Color . FromArgb ( 1 , 0 , 0 , 0 ) ) ;
509587 }
510588 }
0 commit comments