From 1ca17aa2db317190aa66159f8ebcccc789938d7b Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 16 Mar 2025 17:48:22 +0800 Subject: [PATCH] Code cleanup --- Flow.Launcher.Infrastructure/Win32Helper.cs | 16 +++++++++++++++- Flow.Launcher/MainWindow.xaml.cs | 18 ++---------------- Flow.Launcher/ViewModel/MainViewModel.cs | 9 ++++----- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Win32Helper.cs b/Flow.Launcher.Infrastructure/Win32Helper.cs index 5b7e0784c..08452b721 100644 --- a/Flow.Launcher.Infrastructure/Win32Helper.cs +++ b/Flow.Launcher.Infrastructure/Win32Helper.cs @@ -16,7 +16,21 @@ namespace Flow.Launcher.Infrastructure { // Windows 11 (22000) 이상에서만 Mica 및 Acrylic 효과 지원 return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && - Environment.OSVersion.Version.Build >= 22000; + Environment.OSVersion.Version.Build >= 22000; + } + + public static unsafe bool DWMSetCloakForWindow(Window window, bool cloak) + { + var windowHelper = new WindowInteropHelper(window); + windowHelper.EnsureHandle(); + + var cloaked = cloak ? 1 : 0; + + return PInvoke.DwmSetWindowAttribute( + new(windowHelper.Handle), + DWMWINDOWATTRIBUTE.DWMWA_CLOAK, + &cloaked, + (uint)Marshal.SizeOf()).Succeeded; } public static unsafe bool DWMSetBackdropForWindow(Window window, BackdropTypes backdrop) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 8a3137b86..5aba73aa3 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -186,12 +186,11 @@ namespace Flow.Launcher InitializeColorScheme(); WindowsInteropHelper.DisableControlBox(this); InitProgressbarAnimation(); - // Move the window out of screen because setting backdrop will cause flicker with a rectangle - Left = Top = -10000; - await ThemeManager.Instance.RefreshFrameAsync(); // Initialize call twice to work around multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910 InitializePosition(); InitializePosition(); + // Refresh frame + await ThemeManager.Instance.RefreshFrameAsync(); PreviewReset(); // Since the default main window visibility is visible, so we need set focus during startup QueryTextBox.Focus(); @@ -825,26 +824,13 @@ namespace Flow.Launcher public void HideStartup() { - //_viewModel.MainWindowOpacity = 0.2; /*Fix Render Blinking */ if (_settings.HideOnStartup) { - // 📌 최초 실행 시 창이 깜빡이는 문제 방지 (완전히 숨긴 상태로 시작) - //System.Windows.Application.Current.MainWindow.Visibility = Visibility.Hidden; - - //Dispatcher.BeginInvoke((Action)(() => - //{ - // _viewModel.Hide(); - // System.Windows.Application.Current.MainWindow.Visibility = Visibility.Collapsed; - //}), DispatcherPriority.Background); _viewModel.Hide(); } else { - // 📌 최초 실행 시 그림자 효과를 미리 적용하여 Show() 할 때 렌더링이 느려지지 않도록 함 - //ThemeManager.Instance.SetBlurForWindow(); - //ThemeManager.Instance.AutoDropShadow(); _viewModel.Show(); - //_viewModel.MainWindowOpacity = 1; } } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 72ab1d0b6..476479405 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1386,10 +1386,8 @@ namespace Flow.Launcher.ViewModel { if (Application.Current.MainWindow is MainWindow mainWindow) { - IntPtr hWnd = new WindowInteropHelper(mainWindow).Handle; - - // 📌 창을 보이도록 설정 (Cloak 사용 안 함) - //ShowWindow(hWnd, SW_SHOW); + // 📌 DWM Cloak 해제 (창을 정상적으로 표시) + Win32Helper.DWMSetCloakForWindow(mainWindow, false); // 📌 UI 요소 복원 mainWindow.ClockPanel.Visibility = Visibility.Visible; @@ -1433,7 +1431,8 @@ namespace Flow.Launcher.ViewModel mainWindow.SearchIcon.UpdateLayout(); }, DispatcherPriority.Render); - //await Task.Delay(10); // UI 반영 대기 + // 📌 DWM Cloak 적용 (창을 완전히 숨김) + Win32Helper.DWMSetCloakForWindow(mainWindow, true); } // 📌 텍스트 초기화 즉시 적용 + UI 강제 업데이트