Skip to content

Commit 70e7f82

Browse files
committed
Fix Blink
1 parent 3966290 commit 70e7f82

File tree

2 files changed

+46
-28
lines changed

2 files changed

+46
-28
lines changed

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
using Window = System.Windows.Window;
3131
using System.Linq;
3232
using System.Windows.Shapes;
33+
using ModernWpf.Controls.Primitives;
34+
using System.Runtime.InteropServices;
3335

3436
namespace Flow.Launcher
3537
{
@@ -827,29 +829,44 @@ private void OnLocationChanged(object sender, EventArgs e)
827829

828830
public void HideStartup()
829831
{
830-
//_viewModel.MainWindowOpacity = 0.2; /*Fix Render Blinking */
832+
IntPtr hwnd = new WindowInteropHelper(System.Windows.Application.Current.MainWindow).Handle;
833+
831834
if (_settings.HideOnStartup)
832835
{
833-
// 📌 최초 실행 시 창이 깜빡이는 문제 방지 (완전히 숨긴 상태로 시작)
834-
//System.Windows.Application.Current.MainWindow.Visibility = Visibility.Hidden;
835-
836-
//Dispatcher.BeginInvoke((Action)(() =>
837-
//{
838-
// _viewModel.Hide();
839-
// System.Windows.Application.Current.MainWindow.Visibility = Visibility.Collapsed;
840-
//}), DispatcherPriority.Background);
841-
_viewModel.Hide();
836+
CloakWindow(System.Windows.Application.Current.MainWindow);
837+
838+
Dispatcher.BeginInvoke((Action)(() =>
839+
{
840+
_viewModel.Hide();
841+
System.Windows.Application.Current.MainWindow.Visibility = Visibility.Collapsed;
842+
}), DispatcherPriority.Background);
842843
}
843844
else
844845
{
845-
// 📌 최초 실행 시 그림자 효과를 미리 적용하여 Show() 할 때 렌더링이 느려지지 않도록 함
846-
//ThemeManager.Instance.SetBlurForWindow();
847-
//ThemeManager.Instance.AutoDropShadow();
846+
UncloakWindow(System.Windows.Application.Current.MainWindow);
848847
_viewModel.Show();
849-
//_viewModel.MainWindowOpacity = 1;
850848
}
851849
}
852850

851+
private const int DWMWA_CLOAK = 13;
852+
853+
[DllImport("dwmapi.dll")]
854+
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int dwAttribute, ref int pvAttribute, int cbAttribute);
855+
856+
public static void CloakWindow(Window window)
857+
{
858+
IntPtr hwnd = new WindowInteropHelper(window).Handle;
859+
int cloak = 1;
860+
DwmSetWindowAttribute(hwnd, DWMWA_CLOAK, ref cloak, sizeof(int));
861+
}
862+
863+
public static void UncloakWindow(Window window)
864+
{
865+
IntPtr hwnd = new WindowInteropHelper(window).Handle;
866+
int cloak = 0;
867+
DwmSetWindowAttribute(hwnd, DWMWA_CLOAK, ref cloak, sizeof(int));
868+
}
869+
853870
public Screen SelectedScreen()
854871
{
855872
Screen screen;

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
using CommunityToolkit.Mvvm.DependencyInjection;
2929
using System.Windows.Threading;
3030
using System.Windows.Interop;
31+
using System.Runtime.InteropServices;
3132

3233
namespace Flow.Launcher.ViewModel
3334
{
@@ -1388,12 +1389,13 @@ public void Show()
13881389
{
13891390
IntPtr hWnd = new WindowInteropHelper(mainWindow).Handle;
13901391

1391-
// 📌 창을 보이도록 설정 (Cloak 사용 안 함)
1392-
//ShowWindow(hWnd, SW_SHOW);
1392+
// 📌 DWM Cloak 해제 (창을 정상적으로 표시)
1393+
int cloak = 0;
1394+
DwmSetWindowAttribute(hWnd, 13, ref cloak, sizeof(int));
13931395

13941396
// 📌 UI 요소 복원
13951397
mainWindow.ClockPanel.Visibility = Visibility.Visible;
1396-
//mainWindow.SearchIcon.Visibility = Visibility.Visible;
1398+
mainWindow.ClockPanel.Opacity = 1;
13971399
SearchIconVisibility = Visibility.Visible;
13981400
}
13991401

@@ -1419,21 +1421,24 @@ public async void Hide()
14191421

14201422
if (Application.Current.MainWindow is MainWindow mainWindow)
14211423
{
1422-
// 📌 아이콘과 시계 Opacity를 0으로 설정하고 Visibility.Hidden 적용
1424+
IntPtr hWnd = new WindowInteropHelper(mainWindow).Handle;
1425+
1426+
// 📌 UI 요소 숨기기
14231427
Application.Current.Dispatcher.Invoke(() =>
14241428
{
14251429
mainWindow.ClockPanel.Opacity = 0;
14261430
mainWindow.SearchIcon.Opacity = 0;
14271431
mainWindow.ClockPanel.Visibility = Visibility.Hidden;
1428-
//mainWindow.SearchIcon.Visibility = Visibility.Hidden;
14291432
SearchIconVisibility = Visibility.Hidden;
14301433

14311434
// 강제 UI 업데이트
14321435
mainWindow.ClockPanel.UpdateLayout();
14331436
mainWindow.SearchIcon.UpdateLayout();
14341437
}, DispatcherPriority.Render);
14351438

1436-
//await Task.Delay(10); // UI 반영 대기
1439+
// 📌 DWM Cloak 적용 (창을 완전히 숨김)
1440+
int cloak = 1;
1441+
DwmSetWindowAttribute(hWnd, 13, ref cloak, sizeof(int));
14371442
}
14381443

14391444
// 📌 텍스트 초기화 즉시 적용 + UI 강제 업데이트
@@ -1466,20 +1471,16 @@ public async void Hide()
14661471
break;
14671472
}
14681473

1469-
//if (Application.Current.MainWindow is MainWindow mainWindow2)
1470-
//{
1471-
// IntPtr hWnd = new WindowInteropHelper(mainWindow2).Handle;
1472-
1473-
// // 📌 Cloak을 사용하지 않고 일반적인 `ShowWindow(SW_HIDE)` 사용 → Mica/Acrylic 유지됨
1474-
// ShowWindow(hWnd, SW_HIDE);
1475-
//}
1476-
14771474
// WPF 속성 업데이트
14781475
MainWindowVisibilityStatus = false;
14791476
MainWindowVisibility = Visibility.Collapsed;
14801477
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = false });
14811478
}
14821479

1480+
// 📌 DWM API 추가 (P/Invoke)
1481+
[DllImport("dwmapi.dll")]
1482+
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int dwAttribute, ref int pvAttribute, int cbAttribute);
1483+
14831484
/// <summary>
14841485
/// Checks if Flow Launcher should ignore any hotkeys
14851486
/// </summary>

0 commit comments

Comments
 (0)