Merge pull request #3388 from onesounds/050326-FixClockAndIconDisplay

Fix Clock/Search Icon show logic
This commit is contained in:
DB P 2025-03-27 17:11:27 +09:00 committed by GitHub
commit e3a1489a92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 102 additions and 81 deletions

View file

@ -58,7 +58,6 @@ namespace Flow.Launcher
// Window Animation
private const double DefaultRightMargin = 66; //* this value from base.xaml
private bool _animating;
private bool _isClockPanelAnimating = false;
// IDisposable
@ -76,7 +75,7 @@ namespace Flow.Launcher
DataContext = _viewModel;
InitializeComponent();
UpdatePosition(true);
UpdatePosition();
InitSoundEffects();
DataObject.AddPastingHandler(QueryTextBox, QueryTextBox_OnPaste);
@ -112,7 +111,7 @@ namespace Flow.Launcher
}
// Hide window if need
UpdatePosition(true);
UpdatePosition();
if (_settings.HideOnStartup)
{
_viewModel.Hide();
@ -139,7 +138,7 @@ namespace Flow.Launcher
InitProgressbarAnimation();
// Force update position
UpdatePosition(true);
UpdatePosition();
// Refresh frame
await Ioc.Default.GetRequiredService<Theme>().RefreshFrameAsync();
@ -167,7 +166,7 @@ namespace Flow.Launcher
SoundPlay();
}
UpdatePosition(false);
UpdatePosition();
_viewModel.ResetPreview();
Activate();
QueryTextBox.Focus();
@ -234,7 +233,7 @@ namespace Flow.Launcher
// Detect History.Visibility changes
DependencyPropertyDescriptor
.FromProperty(VisibilityProperty, typeof(StackPanel)) // History는 StackPanel이라고 가정
.FromProperty(VisibilityProperty, typeof(StackPanel))
.AddValueChanged(History, (s, e) => UpdateClockPanelVisibility());
}
@ -269,8 +268,6 @@ namespace Flow.Launcher
private void OnLocationChanged(object sender, EventArgs e)
{
if (_animating) return;
if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation)
{
_settings.WindowLeft = Left;
@ -282,9 +279,11 @@ namespace Flow.Launcher
{
_settings.WindowLeft = Left;
_settings.WindowTop = Top;
ClockPanel.Opacity = 0;
SearchIcon.Opacity = 0;
//This condition stops extra hide call when animator is on,
// This condition stops extra hide call when animator is on,
// which causes the toggling to occasional hide instead of show.
if (_viewModel.MainWindowVisibilityStatus)
{
@ -292,7 +291,6 @@ namespace Flow.Launcher
// This also stops the mainwindow from flickering occasionally after Settings window is opened
// and always after Settings window is closed.
if (_settings.UseAnimation)
await Task.Delay(100);
if (_settings.HideWhenDeactivated && !_viewModel.ExternalPreviewVisible)
@ -590,13 +588,8 @@ namespace Flow.Launcher
#region Window Position
private void UpdatePosition(bool force)
private void UpdatePosition()
{
if (_animating && !force)
{
return;
}
// Initialize call twice to work around multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
InitializePosition();
InitializePosition();
@ -770,19 +763,17 @@ namespace Flow.Launcher
private void WindowAnimation()
{
if (_animating)
return;
_isArrowKeyPressed = true;
_animating = true;
UpdatePosition(false);
ClockPanel.Opacity = 0;
SearchIcon.Opacity = 0;
UpdatePosition();
var opacity = _settings.UseAnimation ? 0.0 : 1.0;
ClockPanel.Opacity = opacity;
SearchIcon.Opacity = opacity;
var clocksb = new Storyboard();
var iconsb = new Storyboard();
CircleEase easing = new CircleEase { EasingMode = EasingMode.EaseInOut };
var easing = new CircleEase { EasingMode = EasingMode.EaseInOut };
var animationLength = _settings.AnimationSpeed switch
{
@ -810,7 +801,7 @@ namespace Flow.Launcher
FillBehavior = FillBehavior.HoldEnd
};
double TargetIconOpacity = GetOpacityFromStyle(SearchIcon.Style, 1.0);
var TargetIconOpacity = GetOpacityFromStyle(SearchIcon.Style, 1.0);
var IconOpacity = new DoubleAnimation
{
@ -821,7 +812,7 @@ namespace Flow.Launcher
FillBehavior = FillBehavior.HoldEnd
};
double rightMargin = GetThicknessFromStyle(ClockPanel.Style, new Thickness(0, 0, DefaultRightMargin, 0)).Right;
var rightMargin = GetThicknessFromStyle(ClockPanel.Style, new Thickness(0, 0, DefaultRightMargin, 0)).Right;
var thicknessAnimation = new ThicknessAnimation
{
@ -848,16 +839,11 @@ namespace Flow.Launcher
clocksb.Children.Add(ClockOpacity);
iconsb.Children.Add(IconMotion);
iconsb.Children.Add(IconOpacity);
clocksb.Completed += (_, _) => _animating = false;
_settings.WindowLeft = Left;
_isArrowKeyPressed = false;
if (QueryTextBox.Text.Length == 0)
{
clocksb.Begin(ClockPanel);
}
clocksb.Begin(ClockPanel);
iconsb.Begin(SearchIcon);
}

View file

@ -115,6 +115,8 @@
<SolidColorBrush x:Key="InfoBarWarningIcon" Color="#FCE100" />
<SolidColorBrush x:Key="InfoBarWarningBG" Color="#433519" />
<SolidColorBrush x:Key="InfoBarBD" Color="#19000000" />
<SolidColorBrush x:Key="MouseOverWindowCloseButtonForegroundBrush" Color="#ffffff" />
<SolidColorBrush x:Key="ButtonOutBorder" Color="Transparent" />
<SolidColorBrush x:Key="ButtonInsideBorder" Color="#3f3f3f" />

View file

@ -107,6 +107,7 @@
<SolidColorBrush x:Key="InfoBarWarningBG" Color="#FFF4CE" />
<SolidColorBrush x:Key="InfoBarBD" Color="#0F000000" />
<SolidColorBrush x:Key="MouseOverWindowCloseButtonForegroundBrush" Color="#ffffff" />
<SolidColorBrush x:Key="ButtonOutBorder" Color="#e5e5e5" />
<SolidColorBrush x:Key="ButtonInsideBorder" Color="#d3d3d3" />

View file

@ -18,6 +18,8 @@
Loaded="OnLoaded"
MouseDown="window_MouseDown"
ResizeMode="CanResize"
SnapsToDevicePixels="True"
UseLayoutRounding="True"
StateChanged="Window_StateChanged"
Top="{Binding SettingWindowTop, Mode=TwoWay}"
WindowStartupLocation="Manual"
@ -54,6 +56,7 @@
Width="16"
Height="16"
Margin="10 4 4 4"
RenderOptions.BitmapScalingMode="HighQuality"
Source="/Images/app.png" />
<TextBlock
Grid.Row="0"

View file

@ -2,13 +2,13 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Windows.Input;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using CommunityToolkit.Mvvm.DependencyInjection;
@ -630,7 +630,15 @@ namespace Flow.Launcher.ViewModel
/// <param name="isReQuery">Force query even when Query Text doesn't change</param>
public void ChangeQueryText(string queryText, bool isReQuery = false)
{
Application.Current.Dispatcher.Invoke(() =>
_ = ChangeQueryTextAsync(queryText, isReQuery);
}
/// <summary>
/// Async version of <see cref="ChangeQueryText"/>
/// </summary>
private async Task ChangeQueryTextAsync(string queryText, bool isReQuery = false)
{
await Application.Current.Dispatcher.InvokeAsync(async () =>
{
BackToQueryResults();
@ -644,7 +652,7 @@ namespace Flow.Launcher.ViewModel
}
else if (isReQuery)
{
Query(isReQuery: true);
await QueryAsync(isReQuery: true);
}
QueryTextCursorMovedToEnd = true;
@ -1016,10 +1024,15 @@ namespace Flow.Launcher.ViewModel
#region Query
private void Query(bool isReQuery = false)
{
_ = QueryAsync(isReQuery);
}
private async Task QueryAsync(bool isReQuery = false)
{
if (QueryResultsSelected())
{
_ = QueryResultsAsync(isReQuery);
await QueryResultsAsync(isReQuery);
}
else if (ContextMenuSelected())
{
@ -1053,10 +1066,10 @@ namespace Flow.Launcher.ViewModel
(
r =>
{
var match = StringMatcher.FuzzySearch(query, r.Title);
var match = App.API.FuzzySearch(query, r.Title);
if (!match.IsSearchPrecisionScoreMet())
{
match = StringMatcher.FuzzySearch(query, r.SubTitle);
match = App.API.FuzzySearch(query, r.SubTitle);
}
if (!match.IsSearchPrecisionScoreMet()) return false;
@ -1098,7 +1111,7 @@ namespace Flow.Launcher.ViewModel
Action = _ =>
{
SelectedResults = Results;
ChangeQueryText(h.Query);
App.API.ChangeQuery(h.Query);
return false;
}
};
@ -1109,8 +1122,8 @@ namespace Flow.Launcher.ViewModel
{
var filtered = results.Where
(
r => StringMatcher.FuzzySearch(query, r.Title).IsSearchPrecisionScoreMet() ||
StringMatcher.FuzzySearch(query, r.SubTitle).IsSearchPrecisionScoreMet()
r => App.API.FuzzySearch(query, r.Title).IsSearchPrecisionScoreMet() ||
App.API.FuzzySearch(query, r.SubTitle).IsSearchPrecisionScoreMet()
).ToList();
History.AddResults(filtered, id);
}
@ -1429,36 +1442,57 @@ namespace Flow.Launcher.ViewModel
#region Public Methods
public void Show()
#pragma warning disable VSTHRD100 // Avoid async void methods
public async void Show()
{
Application.Current.Dispatcher.Invoke(() =>
await Application.Current.Dispatcher.InvokeAsync(() =>
{
if (Application.Current.MainWindow is MainWindow mainWindow)
{
// 📌 Remove DWM Cloak (Make the window visible normally)
Win32Helper.DWMSetCloakForWindow(mainWindow, false);
// Clock and SearchIcon hide when show situation
var opacity = Settings.UseAnimation ? 0.0 : 1.0;
mainWindow.ClockPanel.Opacity = opacity;
mainWindow.SearchIcon.Opacity = opacity;
if (QueryText.Length != 0)
{
mainWindow.ClockPanel.Visibility = Visibility.Collapsed;
}
else
{
mainWindow.ClockPanel.Visibility = Visibility.Visible;
}
if (PluginIconSource != null)
{
mainWindow.SearchIcon.Opacity = 0;
}
else
{
SearchIconVisibility = Visibility.Visible;
}
// 📌 Restore UI elements
mainWindow.ClockPanel.Visibility = Visibility.Visible;
//mainWindow.SearchIcon.Visibility = Visibility.Visible;
SearchIconVisibility = Visibility.Visible;
}
}, DispatcherPriority.Render);
// Update WPF properties
MainWindowVisibility = Visibility.Visible;
MainWindowOpacity = 1;
MainWindowVisibilityStatus = true;
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = true });
// Update WPF properties
MainWindowVisibility = Visibility.Visible;
MainWindowOpacity = 1;
MainWindowVisibilityStatus = true;
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = true });
if (StartWithEnglishMode)
{
Win32Helper.SwitchToEnglishKeyboardLayout(true);
}
});
if (StartWithEnglishMode)
{
Win32Helper.SwitchToEnglishKeyboardLayout(true);
}
}
#pragma warning disable VSTHRD100 // Avoid async void methods
public async void Hide()
{
lastHistoryIndex = 1;
@ -1473,52 +1507,47 @@ namespace Flow.Launcher.ViewModel
SelectedResults = Results;
}
// 📌 Immediately apply text reset + force UI update
if (Settings.LastQueryMode == LastQueryMode.Empty)
{
ChangeQueryText(string.Empty);
await Task.Delay(1); // Wait for one frame to ensure UI reflects changes
Application.Current.Dispatcher.Invoke(Application.Current.MainWindow.UpdateLayout); // Force UI update
}
switch (Settings.LastQueryMode)
{
case LastQueryMode.Empty:
await ChangeQueryTextAsync(string.Empty);
break;
case LastQueryMode.Preserved:
case LastQueryMode.Selected:
LastQuerySelected = (Settings.LastQueryMode == LastQueryMode.Preserved);
LastQuerySelected = Settings.LastQueryMode == LastQueryMode.Preserved;
break;
case LastQueryMode.ActionKeywordPreserved:
case LastQueryMode.ActionKeywordSelected:
var newQuery = _lastQuery.ActionKeyword;
if (!string.IsNullOrEmpty(newQuery))
newQuery += " ";
ChangeQueryText(newQuery);
await ChangeQueryTextAsync(newQuery);
if (Settings.LastQueryMode == LastQueryMode.ActionKeywordSelected)
LastQuerySelected = false;
break;
}
if (Application.Current.MainWindow is MainWindow mainWindow)
await Application.Current.Dispatcher.InvokeAsync(() =>
{
// 📌 Set Opacity of icon and clock to 0 and apply Visibility.Hidden
Application.Current.Dispatcher.Invoke(() =>
if (Application.Current.MainWindow is MainWindow mainWindow)
{
mainWindow.ClockPanel.Opacity = 0;
mainWindow.SearchIcon.Opacity = 0;
// 📌 Set Opacity of icon and clock to 0 and apply Visibility.Hidden
var opacity = Settings.UseAnimation ? 0.0 : 1.0;
mainWindow.ClockPanel.Opacity = opacity;
mainWindow.SearchIcon.Opacity = opacity;
mainWindow.ClockPanel.Visibility = Visibility.Hidden;
//mainWindow.SearchIcon.Visibility = Visibility.Hidden;
SearchIconVisibility = Visibility.Hidden;
// Force UI update
mainWindow.ClockPanel.UpdateLayout();
mainWindow.SearchIcon.UpdateLayout();
}, DispatcherPriority.Render);
// 📌 Apply DWM Cloak (Completely hide the window)
Win32Helper.DWMSetCloakForWindow(mainWindow, true);
}
// 📌 Apply DWM Cloak (Completely hide the window)
Win32Helper.DWMSetCloakForWindow(mainWindow, true);
}
});
if (StartWithEnglishMode)
{