using System.Runtime.InteropServices;
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Windows.Graphics;
using WinRT.Interop;
namespace XFEWarframe.Player.Utilities.Helpers;
internal static class WindowHelper
{
public static void Configure(Window window, double width, double height)
{
window.ExtendsContentIntoTitleBar = true;
window.AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Tall;
window.AppWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
window.AppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
// XAML dimensions are DIPs; AppWindow bounds are physical pixels.
var scale = Math.Max(GetDpiForWindow(WindowNative.GetWindowHandle(window)), 96) / 96d;
var work = DisplayArea.GetFromWindowId(window.AppWindow.Id, DisplayAreaFallback.Primary).WorkArea;
var w = Math.Min((int)(width * scale), Math.Max(1, work.Width - (int)(48 * scale)));
var h = Math.Min((int)(height * scale), Math.Max(1, work.Height - (int)(48 * scale)));
window.AppWindow.MoveAndResize(new RectInt32(work.X + (work.Width - w) / 2, work.Y + (work.Height - h) / 2, w, h));
}
[DllImport("user32.dll", ExactSpelling = true)]
private static extern uint GetDpiForWindow(nint hwnd);
}
using System.Runtime.InteropServices;
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Windows.Graphics;
using WinRT.Interop;
namespace XFEWarframe.Player.Utilities.Helpers;
internal static class WindowHelper
{
public static void Configure(Window window, double width, double height)
{
window.ExtendsContentIntoTitleBar = true;
window.AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Tall;
window.AppWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
window.AppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
// XAML dimensions are DIPs; AppWindow bounds are physical pixels.
var scale = Math.Max(GetDpiForWindow(WindowNative.GetWindowHandle(window)), 96) / 96d;
var work = DisplayArea.GetFromWindowId(window.AppWindow.Id, DisplayAreaFallback.Primary).WorkArea;
var w = Math.Min((int)(width * scale), Math.Max(1, work.Width - (int)(48 * scale)));
var h = Math.Min((int)(height * scale), Math.Max(1, work.Height - (int)(48 * scale)));
window.AppWindow.MoveAndResize(new RectInt32(work.X + (work.Width - w) / 2, work.Y + (work.Height - h) / 2, w, h));
}
[DllImport("user32.dll", ExactSpelling = true)]
private static extern uint GetDpiForWindow(nint hwnd);
}