diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconController.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconController.cs index 45243cec..d24cc723 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconController.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconController.cs @@ -50,6 +50,11 @@ internal sealed class NotifyIconController : IDisposable xamlHostWindow.Dispose(); } + public RECT GetRect() + { + return NotifyIconMethods.GetRect(id, messageWindow.HWND); + } + private void OnRecreateNotifyIconRequested(NotifyIconMessageWindow window) { NotifyIconMethods.Delete(id); @@ -81,7 +86,6 @@ internal sealed class NotifyIconController : IDisposable [SuppressMessage("", "SH002")] private void OnContextMenuRequested(NotifyIconMessageWindow window, PointUInt16 point) { - RECT iconRect = NotifyIconMethods.GetRect(id, window.HWND); - xamlHostWindow.ShowFlyoutAt(lazyMenu.Value, new Windows.Foundation.Point(point.X, point.Y), iconRect); + xamlHostWindow.ShowFlyoutAt(lazyMenu.Value, new Windows.Foundation.Point(point.X, point.Y), GetRect()); } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs index 8715069e..2ebd955f 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs @@ -1,6 +1,7 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using CommunityToolkit.WinUI.Notifications; using Microsoft.UI; using Microsoft.UI.Composition.SystemBackdrops; using Microsoft.UI.Content; @@ -11,6 +12,7 @@ using Microsoft.UI.Xaml.Media; using Snap.Hutao.Core.LifeCycle; using Snap.Hutao.Core.Setting; using Snap.Hutao.Core.Windowing.Abstraction; +using Snap.Hutao.Core.Windowing.NotifyIcon; using Snap.Hutao.Service; using Snap.Hutao.Win32; using Snap.Hutao.Win32.Foundation; @@ -102,6 +104,15 @@ internal sealed class XamlWindowController args.Handled = true; window.Hide(); + RECT iconRect = serviceProvider.GetRequiredService().GetRect(); + RECT primaryRect = StructMarshal.RECT(DisplayArea.Primary.OuterBounds); + if (!IntersectRect(out _, in primaryRect, in iconRect)) + { + new ToastContentBuilder() + .AddText(SH.CoreWindowingNotifyIconPromotedHint) + .Show(); + } + ICurrentXamlWindowReference currentXamlWindowReference = serviceProvider.GetRequiredService(); if (currentXamlWindowReference.Window == window) { diff --git a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx index 3a86e8ec..1914b6b8 100644 --- a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx +++ b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx @@ -198,6 +198,9 @@ 启动游戏 + + 胡桃已进入后台运行 + 窗口 diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/Foundation/RECT.cs b/src/Snap.Hutao/Snap.Hutao/Win32/Foundation/RECT.cs index ea6417e6..180e40a1 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/Foundation/RECT.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/Foundation/RECT.cs @@ -10,4 +10,12 @@ internal struct RECT public int top; public int right; public int bottom; + + public RECT(int left, int top, int right, int bottom) + { + this.left = left; + this.top = top; + this.right = right; + this.bottom = bottom; + } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/StructMarshal.cs b/src/Snap.Hutao/Snap.Hutao/Win32/StructMarshal.cs index 94be5c4b..204a6202 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/StructMarshal.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/StructMarshal.cs @@ -33,6 +33,11 @@ internal static class StructMarshal return new(0, 0, size.X, size.Y); } + public static RECT RECT(RectInt32 rect) + { + return new(rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height); + } + public static RectInt32 RectInt32(RECT rect) { return new(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs b/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs index 99979651..ba11aaa0 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs @@ -125,6 +125,24 @@ internal static class User32 } } + [DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)] + [SupportedOSPlatform("windows5.0")] + public static unsafe extern BOOL IntersectRect([Out] RECT* lprcDst, RECT* lprcSrc1, RECT* lprcSrc2); + + public static unsafe BOOL IntersectRect(out RECT rcDst, ref readonly RECT rcSrc1, ref readonly RECT rcSrc2) + { + fixed (RECT* lprcDst = &rcDst) + { + fixed (RECT* lprcSrc1 = &rcSrc1) + { + fixed (RECT* lprcSrc2 = &rcSrc2) + { + return IntersectRect(lprcDst, lprcSrc1, lprcSrc2); + } + } + } + } + [DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)] [SupportedOSPlatform("windows5.0")] public static extern BOOL IsIconic(HWND hWnd);