46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using System.Diagnostics;
|
|
|
|
namespace OBSBlur.Window;
|
|
|
|
public struct WindowInfo
|
|
{
|
|
internal IntPtr WindowHandle { get; init; }
|
|
public WindowPlacement WindowPlacement { get; init; }
|
|
public string WindowTitle { get; init; }
|
|
public Process ProcessInfo { get; init; }
|
|
|
|
public WindowInfo(IntPtr windowHandle, string windowTitle, Process processInfo, WindowPlacement windowPlacement)
|
|
{
|
|
this.WindowHandle = windowHandle;
|
|
this.ProcessInfo = processInfo;
|
|
this.WindowPlacement = windowPlacement;
|
|
this.WindowTitle = windowTitle;
|
|
}
|
|
|
|
public override bool Equals(object? obj)
|
|
{
|
|
return obj is WindowInfo other && Equals(other);
|
|
}
|
|
|
|
public bool Equals(WindowInfo other)
|
|
{
|
|
return WindowHandle == other.WindowHandle &&
|
|
WindowPlacement.Equals(other.WindowPlacement) &&
|
|
WindowTitle.Equals(other.WindowTitle) &&
|
|
ProcessInfo.ProcessName.Equals(other.ProcessInfo.ProcessName) &&
|
|
ProcessInfo.Id == other.ProcessInfo.Id;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return HashCode.Combine(WindowHandle, WindowPlacement, WindowTitle, ProcessInfo);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
const int cutoffStr = 17;
|
|
string processNameStr = ProcessInfo.ProcessName.Substring(0, Math.Min(cutoffStr, ProcessInfo.ProcessName.Length));
|
|
string windowTitleStr = WindowTitle.Substring(0, Math.Min(cutoffStr, WindowTitle.Length));
|
|
return $"{WindowHandle,8} {ProcessInfo.Id,8} {processNameStr,cutoffStr} {windowTitleStr,-cutoffStr} {WindowPlacement}";
|
|
}
|
|
} |