mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
[Flyout][Hotfix]Appear next to the tray icon position (#23772)
* [Flyout]Appear next to the tray icon position * fix spellchecker
This commit is contained in:
@@ -37,12 +37,12 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
ShowOobeWindow,
|
||||
ShowScoobeWindow,
|
||||
ShowFlyout,
|
||||
SettingsWindow,
|
||||
ContainsSettingsWindow,
|
||||
ContainsFlyoutPosition,
|
||||
}
|
||||
|
||||
// Quantity of arguments
|
||||
private const int RequiredArgumentsQty = 10;
|
||||
private const int RequiredAndOptionalArgumentsQty = 11;
|
||||
private const int RequiredArgumentsQty = 12;
|
||||
|
||||
// Create an instance of the IPC wrapper.
|
||||
private static TwoWayPipeMessageIPCManaged ipcmanager;
|
||||
@@ -122,11 +122,16 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
ShowOobe = cmdArgs[(int)Arguments.ShowOobeWindow] == "true";
|
||||
ShowScoobe = cmdArgs[(int)Arguments.ShowScoobeWindow] == "true";
|
||||
ShowFlyout = cmdArgs[(int)Arguments.ShowFlyout] == "true";
|
||||
bool containsSettingsWindow = cmdArgs[(int)Arguments.ContainsSettingsWindow] == "true";
|
||||
bool containsFlyoutPosition = cmdArgs[(int)Arguments.ContainsFlyoutPosition] == "true";
|
||||
|
||||
if (cmdArgs.Length == RequiredAndOptionalArgumentsQty)
|
||||
// To keep track of variable arguments
|
||||
int currentArgumentIndex = RequiredArgumentsQty;
|
||||
|
||||
if (containsSettingsWindow)
|
||||
{
|
||||
// open specific window
|
||||
switch (cmdArgs[(int)Arguments.SettingsWindow])
|
||||
switch (cmdArgs[currentArgumentIndex])
|
||||
{
|
||||
case "Overview": StartupPage = typeof(Views.GeneralPage); break;
|
||||
case "AlwaysOnTop": StartupPage = typeof(Views.AlwaysOnTopPage); break;
|
||||
@@ -148,6 +153,17 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
case "Hosts": StartupPage = typeof(Views.HostsPage); break;
|
||||
default: Debug.Assert(false, "Unexpected SettingsWindow argument value"); break;
|
||||
}
|
||||
|
||||
currentArgumentIndex++;
|
||||
}
|
||||
|
||||
int flyout_x = 0;
|
||||
int flyout_y = 0;
|
||||
if (containsFlyoutPosition)
|
||||
{
|
||||
// get the flyout position arguments
|
||||
int.TryParse(cmdArgs[currentArgumentIndex++], out flyout_x);
|
||||
int.TryParse(cmdArgs[currentArgumentIndex++], out flyout_y);
|
||||
}
|
||||
|
||||
RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
|
||||
@@ -193,7 +209,13 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
}
|
||||
else if (ShowFlyout)
|
||||
{
|
||||
ShellPage.OpenFlyoutCallback();
|
||||
POINT? p = null;
|
||||
if (containsFlyoutPosition)
|
||||
{
|
||||
p = new POINT(flyout_x, flyout_y);
|
||||
}
|
||||
|
||||
ShellPage.OpenFlyoutCallback(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
using Microsoft.PowerToys.Settings.UI.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events;
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels.Flyout;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.UI;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Windows.Graphics;
|
||||
using WinUIEx;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI
|
||||
@@ -21,23 +23,65 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
|
||||
public FlyoutViewModel ViewModel { get; set; }
|
||||
|
||||
public FlyoutWindow()
|
||||
public POINT? FlyoutAppearPosition { get; set; }
|
||||
|
||||
public FlyoutWindow(POINT? initialPosition)
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.Activated += FlyoutWindow_Activated;
|
||||
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
||||
WindowId windowId = Win32Interop.GetWindowIdFromWindow(hwnd);
|
||||
DisplayArea displayArea = DisplayArea.GetFromWindowId(windowId, DisplayAreaFallback.Nearest);
|
||||
double dpiScale = (float)this.GetDpiForWindow() / 96;
|
||||
double x = displayArea.WorkArea.Width - (dpiScale * (WindowWidth + WindowMargin));
|
||||
double y = displayArea.WorkArea.Height - (dpiScale * (WindowHeight + WindowMargin));
|
||||
this.MoveAndResize(x, y, WindowWidth, WindowHeight);
|
||||
FlyoutAppearPosition = initialPosition;
|
||||
ViewModel = new FlyoutViewModel();
|
||||
}
|
||||
|
||||
private void FlyoutWindow_Activated(object sender, Microsoft.UI.Xaml.WindowActivatedEventArgs args)
|
||||
{
|
||||
PowerToysTelemetry.Log.WriteEvent(new TrayFlyoutActivatedEvent());
|
||||
if (args.WindowActivationState == Microsoft.UI.Xaml.WindowActivationState.CodeActivated)
|
||||
{
|
||||
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
||||
WindowId windowId = Win32Interop.GetWindowIdFromWindow(hwnd);
|
||||
if (!FlyoutAppearPosition.HasValue)
|
||||
{
|
||||
DisplayArea displayArea = DisplayArea.GetFromWindowId(windowId, DisplayAreaFallback.Nearest);
|
||||
double dpiScale = (float)this.GetDpiForWindow() / 96;
|
||||
double x = displayArea.WorkArea.Width - (dpiScale * (WindowWidth + WindowMargin));
|
||||
double y = displayArea.WorkArea.Height - (dpiScale * (WindowHeight + WindowMargin));
|
||||
this.MoveAndResize(x, y, WindowWidth, WindowHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
DisplayArea displayArea = DisplayArea.GetFromPoint(new PointInt32(FlyoutAppearPosition.Value.X, FlyoutAppearPosition.Value.Y), DisplayAreaFallback.Nearest);
|
||||
|
||||
// Move the window to the correct screen as a little blob, so we can get the accurate dpi for the screen to calculate the best position to show it.
|
||||
this.MoveAndResize(FlyoutAppearPosition.Value.X, FlyoutAppearPosition.Value.Y, 1, 1);
|
||||
double dpiScale = (float)this.GetDpiForWindow() / 96;
|
||||
|
||||
// Position the window so that it's inside the display are closest to the point.
|
||||
POINT newPosition = new POINT(FlyoutAppearPosition.Value.X - (int)(dpiScale * WindowWidth / 2), FlyoutAppearPosition.Value.Y - (int)(dpiScale * WindowHeight / 2));
|
||||
if (newPosition.X < displayArea.WorkArea.X)
|
||||
{
|
||||
newPosition.X = displayArea.WorkArea.X;
|
||||
}
|
||||
|
||||
if (newPosition.Y < displayArea.WorkArea.Y)
|
||||
{
|
||||
newPosition.Y = displayArea.WorkArea.Y;
|
||||
}
|
||||
|
||||
if (newPosition.X + (dpiScale * WindowWidth) > displayArea.WorkArea.X + displayArea.WorkArea.Width)
|
||||
{
|
||||
newPosition.X = (int)(displayArea.WorkArea.X + displayArea.WorkArea.Width - (dpiScale * WindowWidth));
|
||||
}
|
||||
|
||||
if (newPosition.Y + (dpiScale * WindowHeight) > displayArea.WorkArea.Y + displayArea.WorkArea.Height)
|
||||
{
|
||||
newPosition.Y = (int)(displayArea.WorkArea.Y + displayArea.WorkArea.Height - (dpiScale * WindowHeight));
|
||||
}
|
||||
|
||||
this.MoveAndResize(newPosition.X, newPosition.Y, WindowWidth, WindowHeight);
|
||||
}
|
||||
}
|
||||
|
||||
if (args.WindowActivationState == Microsoft.UI.Xaml.WindowActivationState.Deactivated)
|
||||
{
|
||||
if (ViewModel.CanHide)
|
||||
|
||||
@@ -171,16 +171,17 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
});
|
||||
|
||||
// open flyout
|
||||
ShellPage.SetOpenFlyoutCallback(() =>
|
||||
ShellPage.SetOpenFlyoutCallback((POINT? p) =>
|
||||
{
|
||||
this.DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
|
||||
{
|
||||
if (App.GetFlyoutWindow() == null)
|
||||
{
|
||||
App.SetFlyoutWindow(new FlyoutWindow());
|
||||
App.SetFlyoutWindow(new FlyoutWindow(p));
|
||||
}
|
||||
|
||||
FlyoutWindow flyout = App.GetFlyoutWindow();
|
||||
flyout.FlyoutAppearPosition = p;
|
||||
flyout.Activate();
|
||||
|
||||
// https://github.com/microsoft/microsoft-ui-xaml/issues/7595 - Activate doesn't bring window to the foreground
|
||||
@@ -196,7 +197,7 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
{
|
||||
if (App.GetFlyoutWindow() == null)
|
||||
{
|
||||
App.SetFlyoutWindow(new FlyoutWindow());
|
||||
App.SetFlyoutWindow(new FlyoutWindow(null));
|
||||
}
|
||||
|
||||
App.GetFlyoutWindow().ViewModel.DisableHiding();
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
/// <summary>
|
||||
/// Declaration for the opening flyout window callback function.
|
||||
/// </summary>
|
||||
public delegate void FlyoutOpeningCallback();
|
||||
public delegate void FlyoutOpeningCallback(POINT? point);
|
||||
|
||||
/// <summary>
|
||||
/// Declaration for the disabling hide of flyout window callback function.
|
||||
@@ -330,13 +330,28 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
{
|
||||
if (json != null)
|
||||
{
|
||||
if (json.ToString().StartsWith("{\"ShowYourself\":"))
|
||||
IJsonValue whatToShowJson;
|
||||
if (json.TryGetValue("ShowYourself", out whatToShowJson))
|
||||
{
|
||||
if (json.ToString().EndsWith("\"flyout\"}"))
|
||||
if (whatToShowJson.ValueType == JsonValueType.String && whatToShowJson.GetString().Equals("flyout"))
|
||||
{
|
||||
OpenFlyoutCallback();
|
||||
POINT? p = null;
|
||||
|
||||
IJsonValue flyoutPointX;
|
||||
IJsonValue flyoutPointY;
|
||||
if (json.TryGetValue("x_position", out flyoutPointX) && json.TryGetValue("y_position", out flyoutPointY))
|
||||
{
|
||||
if (flyoutPointX.ValueType == JsonValueType.Number && flyoutPointY.ValueType == JsonValueType.Number)
|
||||
{
|
||||
int flyout_x = (int)flyoutPointX.GetNumber();
|
||||
int flyout_y = (int)flyoutPointY.GetNumber();
|
||||
p = new POINT(flyout_x, flyout_y);
|
||||
}
|
||||
}
|
||||
|
||||
OpenFlyoutCallback(p);
|
||||
}
|
||||
else if (json.ToString().EndsWith("\"main_page\"}"))
|
||||
else if (whatToShowJson.ValueType == JsonValueType.String && whatToShowJson.GetString().Equals("main_page"))
|
||||
{
|
||||
OpenMainWindowCallback();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user