[QuickAccent]Fix showing selector window (#22435)

* [Quick Accent] fix showing selector window

* Update layout before using size to calculate position

* Correct offset issues due to margin

* Up the offset to 24, as the margin value removed
This commit is contained in:
Taras 2022-12-05 00:28:05 +02:00 committed by GitHub
parent ec0fb6a4c7
commit 3afa124bea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View File

@ -20,7 +20,7 @@ namespace PowerAccent.Core.Tools
public static Point GetRawCoordinatesFromPosition(Position position, Rect screen, Size window)
{
int offset = 10;
int offset = 24;
double pointX = position switch
{

View File

@ -38,7 +38,7 @@
</Window.Resources>
<Grid Margin="24,24,24,24">
<Grid>
<Border
HorizontalAlignment="Center"
VerticalAlignment="Center"

View File

@ -63,14 +63,18 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged
{
CharacterNameVisibility = _powerAccent.ShowUnicodeDescription ? Visibility.Visible : Visibility.Collapsed;
this.Visibility = isActive ? Visibility.Visible : Visibility.Collapsed;
if (isActive)
{
characters.ItemsSource = chars;
CenterWindow();
this.UpdateLayout(); // Required for filling the actual width/height before positioning.
SetWindowPosition();
Show();
Microsoft.PowerToys.Telemetry.PowerToysTelemetry.Log.WriteEvent(new PowerAccent.Core.Telemetry.PowerAccentShowAccentMenuEvent());
}
else
{
Hide();
}
}
private void MenuExit_Click(object sender, RoutedEventArgs e)
@ -78,11 +82,10 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged
Application.Current.Shutdown();
}
private void CenterWindow()
private void SetWindowPosition()
{
UpdateLayout();
Size window = new (((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualWidth, ((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualHeight);
Point position = _powerAccent.GetDisplayCoordinates(window);
Size windowSize = new (((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualWidth, ((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualHeight);
Point position = _powerAccent.GetDisplayCoordinates(windowSize);
this.Left = position.X;
this.Top = position.Y;
}