fix: only flash window if NOT in foreground

This commit is contained in:
goat 2020-04-28 17:59:42 +02:00
parent fd18ba6e8e
commit 832c5f758f
2 changed files with 33 additions and 8 deletions

View file

@ -69,14 +69,16 @@ namespace Dalamud.Game.Network {
contentFinderCondition.Image = 112324;
}
var flashInfo = new NativeFunctions.FLASHWINFO();
flashInfo.cbSize = (uint) Marshal.SizeOf<NativeFunctions.FLASHWINFO>();
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<NativeFunctions.FLASHWINFO>();
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);

View file

@ -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
/// <summary>Returns true if the current application has focus, false otherwise</summary>
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);