2022-04-19 22:00:28 +02: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;
|
2024-10-17 05:14:57 -04:00
|
|
|
|
|
2022-04-29 11:06:50 +02:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Helpers;
|
2022-04-19 22:00:28 +02: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;
|
2024-08-08 15:26:43 +01:00
|
|
|
|
using PowerToys.Interop;
|
2022-04-20 17:08:25 +02:00
|
|
|
|
using Windows.Graphics;
|
2023-04-21 18:59:08 +02:00
|
|
|
|
using WinUIEx;
|
2023-09-07 15:36:47 +07:00
|
|
|
|
using WinUIEx.Messaging;
|
2022-04-19 22:00:28 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// An empty window that can be used on its own or navigated to within a Frame.
|
|
|
|
|
|
/// </summary>
|
2024-01-26 14:29:18 +01:00
|
|
|
|
public sealed partial class OobeWindow : WindowEx, IDisposable
|
2022-04-19 22:00:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
private PowerToysModules initialModule;
|
|
|
|
|
|
|
2022-04-29 11:06:50 +02: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;
|
2024-01-26 14:29:18 +01:00
|
|
|
|
private WindowMessageMonitor _msgMonitor;
|
|
|
|
|
|
private bool disposedValue;
|
2022-04-29 11:06:50 +02:00
|
|
|
|
|
2023-11-23 18:19:57 +01:00
|
|
|
|
public OobeWindow(PowerToysModules initialModule)
|
2022-04-19 22:00:28 +02:00
|
|
|
|
{
|
2024-04-17 16:39:19 +02:00
|
|
|
|
App.ThemeService.ThemeChanged += OnThemeChanged;
|
|
|
|
|
|
App.ThemeService.ApplyTheme();
|
|
|
|
|
|
|
2022-04-19 22:00:28 +02:00
|
|
|
|
this.InitializeComponent();
|
|
|
|
|
|
|
|
|
|
|
|
// Set window icon
|
2022-04-29 11:06:50 +02:00
|
|
|
|
_hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
|
|
|
|
|
_windowId = Win32Interop.GetWindowIdFromWindow(_hWnd);
|
|
|
|
|
|
_appWindow = AppWindow.GetFromWindowId(_windowId);
|
2023-07-20 00:12:46 +01:00
|
|
|
|
_appWindow.SetIcon("Assets\\Settings\\icon.ico");
|
2022-04-19 22:00:28 +02:00
|
|
|
|
|
2022-04-29 11:06:50 +02:00
|
|
|
|
OverlappedPresenter presenter = _appWindow.Presenter as OverlappedPresenter;
|
2022-04-20 17:08:25 +02:00
|
|
|
|
presenter.IsMinimizable = false;
|
|
|
|
|
|
presenter.IsMaximizable = false;
|
|
|
|
|
|
|
2022-04-29 11:06:50 +02: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 17:08:25 +02:00
|
|
|
|
SizeInt32 size;
|
2022-04-29 11:06:50 +02:00
|
|
|
|
size.Width = width;
|
|
|
|
|
|
size.Height = height;
|
|
|
|
|
|
_appWindow.Resize(size);
|
2022-04-20 17:08:25 +02:00
|
|
|
|
|
2022-04-19 22:00:28 +02:00
|
|
|
|
this.initialModule = initialModule;
|
|
|
|
|
|
|
2024-01-26 14:29:18 +01:00
|
|
|
|
_msgMonitor = new WindowMessageMonitor(this);
|
|
|
|
|
|
_msgMonitor.WindowMessageReceived += (_, e) =>
|
2023-09-07 15:36:47 +07:00
|
|
|
|
{
|
|
|
|
|
|
const int WM_NCLBUTTONDBLCLK = 0x00A3;
|
|
|
|
|
|
if (e.Message.MessageId == WM_NCLBUTTONDBLCLK)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Disable double click on title bar to maximize window
|
|
|
|
|
|
e.Result = 0;
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-04-29 11:06:50 +02:00
|
|
|
|
this.SizeChanged += OobeWindow_SizeChanged;
|
|
|
|
|
|
|
2023-07-20 00:12:46 +01:00
|
|
|
|
var loader = Helpers.ResourceLoaderInstance.ResourceLoader;
|
2022-04-19 22:00:28 +02:00
|
|
|
|
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);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-21 14:19:11 -05:00
|
|
|
|
public void SetAppWindow(PowerToysModules module)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (shellPage != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
shellPage.NavigateToModule(module);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-04-29 11:06:50 +02: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-19 22:00:28 +02:00
|
|
|
|
private void Window_Closed(object sender, WindowEventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
App.ClearOobeWindow();
|
2022-05-19 15:12:59 +02:00
|
|
|
|
|
|
|
|
|
|
var mainWindow = App.GetSettingsWindow();
|
|
|
|
|
|
if (mainWindow != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
mainWindow.CloseHiddenWindow();
|
|
|
|
|
|
}
|
2024-04-17 16:39:19 +02:00
|
|
|
|
|
|
|
|
|
|
App.ThemeService.ThemeChanged -= OnThemeChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnThemeChanged(object sender, ElementTheme theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
WindowHelper.SetTheme(this, theme);
|
2022-04-19 22:00:28 +02:00
|
|
|
|
}
|
2024-01-26 14:29:18 +01:00
|
|
|
|
|
|
|
|
|
|
private void Dispose(bool disposing)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!disposedValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
_msgMonitor?.Dispose();
|
|
|
|
|
|
|
|
|
|
|
|
disposedValue = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
|
|
|
|
|
Dispose(disposing: true);
|
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
|
}
|
2022-04-19 22:00:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|