diff --git a/Dalamud/Game/Network/NetworkHandlers.cs b/Dalamud/Game/Network/NetworkHandlers.cs index f22b8745f..ad723e3c4 100644 --- a/Dalamud/Game/Network/NetworkHandlers.cs +++ b/Dalamud/Game/Network/NetworkHandlers.cs @@ -69,14 +69,16 @@ namespace Dalamud.Game.Network { contentFinderCondition.Image = 112324; } - var flashInfo = new NativeFunctions.FLASHWINFO(); - flashInfo.cbSize = (uint) Marshal.SizeOf(); - flashInfo.uCount = uint.MaxValue; - flashInfo.dwTimeout = 0; - flashInfo.dwFlags = NativeFunctions.FlashWindow.FLASHW_TRAY | - NativeFunctions.FlashWindow.FLASHW_TIMERNOFG; - flashInfo.hwnd = Process.GetCurrentProcess().MainWindowHandle; - NativeFunctions.FlashWindowEx(ref flashInfo); + if (!NativeFunctions.ApplicationIsActivated()) { + var flashInfo = new NativeFunctions.FLASHWINFO(); + flashInfo.cbSize = (uint)Marshal.SizeOf(); + flashInfo.uCount = uint.MaxValue; + flashInfo.dwTimeout = 0; + flashInfo.dwFlags = NativeFunctions.FlashWindow.FLASHW_ALL | + NativeFunctions.FlashWindow.FLASHW_TIMERNOFG; + flashInfo.hwnd = Process.GetCurrentProcess().MainWindowHandle; + NativeFunctions.FlashWindowEx(ref flashInfo); + } Task.Run(async () => { this.dalamud.Framework.Gui.Chat.Print("Duty pop: " + contentFinderCondition.Name); diff --git a/Dalamud/NativeFunctions.cs b/Dalamud/NativeFunctions.cs index 1b5f8a5be..37988eb48 100644 --- a/Dalamud/NativeFunctions.cs +++ b/Dalamud/NativeFunctions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Runtime.InteropServices; using System.Text; @@ -58,6 +59,28 @@ namespace Dalamud #endregion + /// Returns true if the current application has focus, false otherwise + public static bool ApplicationIsActivated() + { + var activatedHandle = GetForegroundWindow(); + if (activatedHandle == IntPtr.Zero) + { + return false; // No window is currently activated + } + + var procId = Process.GetCurrentProcess().Id; + int activeProcId; + GetWindowThreadProcessId(activatedHandle, out activeProcId); + + return activeProcId == procId; + } + + [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] + private static extern IntPtr GetForegroundWindow(); + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + private static extern int GetWindowThreadProcessId(IntPtr handle, out int processId); + [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FlashWindowEx(ref FLASHWINFO pwfi);