2022-04-20 04:00:28 +08:00
|
|
|
|
// 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 System;
|
|
|
|
|
using interop;
|
2022-04-29 17:06:50 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Helpers;
|
2022-04-20 04:00:28 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.OOBE.Enums;
|
|
|
|
|
using Microsoft.PowerToys.Settings.UI.OOBE.Views;
|
|
|
|
|
using Microsoft.UI;
|
|
|
|
|
using Microsoft.UI.Windowing;
|
|
|
|
|
using Microsoft.UI.Xaml;
|
|
|
|
|
using Windows.ApplicationModel.Resources;
|
2022-04-20 23:08:25 +08:00
|
|
|
|
using Windows.Graphics;
|
2022-04-20 04:00:28 +08:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// An empty window that can be used on its own or navigated to within a Frame.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed partial class OobeWindow : Window
|
|
|
|
|
{
|
|
|
|
|
private PowerToysModules initialModule;
|
|
|
|
|
|
2022-04-29 17:06:50 +08:00
|
|
|
|
private const int ExpectedWidth = 1100;
|
|
|
|
|
private const int ExpectedHeight = 700;
|
|
|
|
|
private const int DefaultDPI = 96;
|
|
|
|
|
private int _currentDPI;
|
|
|
|
|
private WindowId _windowId;
|
|
|
|
|
private IntPtr _hWnd;
|
|
|
|
|
private AppWindow _appWindow;
|
|
|
|
|
|
2022-04-20 04:00:28 +08:00
|
|
|
|
public OobeWindow(PowerToysModules initialModule)
|
|
|
|
|
{
|
|
|
|
|
this.InitializeComponent();
|
|
|
|
|
|
|
|
|
|
// Set window icon
|
2022-04-29 17:06:50 +08:00
|
|
|
|
_hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
|
|
|
|
_windowId = Win32Interop.GetWindowIdFromWindow(_hWnd);
|
|
|
|
|
_appWindow = AppWindow.GetFromWindowId(_windowId);
|
|
|
|
|
_appWindow.SetIcon("icon.ico");
|
2022-04-20 04:00:28 +08:00
|
|
|
|
|
2022-04-29 17:06:50 +08:00
|
|
|
|
OverlappedPresenter presenter = _appWindow.Presenter as OverlappedPresenter;
|
2022-04-20 23:08:25 +08:00
|
|
|
|
presenter.IsMinimizable = false;
|
|
|
|
|
presenter.IsMaximizable = false;
|
|
|
|
|
|
2022-04-29 17:06:50 +08:00
|
|
|
|
var dpi = NativeMethods.GetDpiForWindow(_hWnd);
|
|
|
|
|
_currentDPI = dpi;
|
|
|
|
|
float scalingFactor = (float)dpi / DefaultDPI;
|
|
|
|
|
int width = (int)(ExpectedWidth * scalingFactor);
|
|
|
|
|
int height = (int)(ExpectedHeight * scalingFactor);
|
|
|
|
|
|
2022-04-20 23:08:25 +08:00
|
|
|
|
SizeInt32 size;
|
2022-04-29 17:06:50 +08:00
|
|
|
|
size.Width = width;
|
|
|
|
|
size.Height = height;
|
|
|
|
|
_appWindow.Resize(size);
|
2022-04-20 23:08:25 +08:00
|
|
|
|
|
2022-04-20 04:00:28 +08:00
|
|
|
|
this.initialModule = initialModule;
|
|
|
|
|
|
2022-04-29 17:06:50 +08:00
|
|
|
|
this.SizeChanged += OobeWindow_SizeChanged;
|
|
|
|
|
|
2022-04-20 04:00:28 +08:00
|
|
|
|
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();
|
|
|
|
|
Title = loader.GetString("OobeWindow_Title");
|
|
|
|
|
|
|
|
|
|
if (shellPage != null)
|
|
|
|
|
{
|
|
|
|
|
shellPage.NavigateToModule(this.initialModule);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OobeShellPage.SetRunSharedEventCallback(() =>
|
|
|
|
|
{
|
|
|
|
|
return Constants.PowerLauncherSharedEvent();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
OobeShellPage.SetColorPickerSharedEventCallback(() =>
|
|
|
|
|
{
|
|
|
|
|
return Constants.ShowColorPickerSharedEvent();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
OobeShellPage.SetOpenMainWindowCallback((Type type) =>
|
|
|
|
|
{
|
|
|
|
|
App.OpenSettingsWindow(type);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-29 17:06:50 +08:00
|
|
|
|
private void OobeWindow_SizeChanged(object sender, WindowSizeChangedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var dpi = NativeMethods.GetDpiForWindow(_hWnd);
|
|
|
|
|
if (_currentDPI != dpi)
|
|
|
|
|
{
|
|
|
|
|
// Reacting to a DPI change. Should not cause a resize -> sizeChanged loop.
|
|
|
|
|
_currentDPI = dpi;
|
|
|
|
|
float scalingFactor = (float)dpi / DefaultDPI;
|
|
|
|
|
int width = (int)(ExpectedWidth * scalingFactor);
|
|
|
|
|
int height = (int)(ExpectedHeight * scalingFactor);
|
|
|
|
|
SizeInt32 size;
|
|
|
|
|
size.Width = width;
|
|
|
|
|
size.Height = height;
|
|
|
|
|
_appWindow.Resize(size);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-20 04:00:28 +08:00
|
|
|
|
private void Window_Closed(object sender, WindowEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
App.ClearOobeWindow();
|
2022-05-19 21:12:59 +08:00
|
|
|
|
|
|
|
|
|
var mainWindow = App.GetSettingsWindow();
|
|
|
|
|
if (mainWindow != null)
|
|
|
|
|
{
|
|
|
|
|
mainWindow.CloseHiddenWindow();
|
|
|
|
|
}
|
2022-04-20 04:00:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|