ReSharper
This commit is contained in:
parent
8df5d8e14e
commit
321f930733
@ -14,8 +14,11 @@ public class Blur
|
|||||||
private readonly OBSWebsocket _websocket = new ();
|
private readonly OBSWebsocket _websocket = new ();
|
||||||
private string _currentObsScene = "";
|
private string _currentObsScene = "";
|
||||||
private readonly string _displayCaptureName;
|
private readonly string _displayCaptureName;
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public readonly List<string> EnabledObsScenes = new();
|
public readonly List<string> EnabledObsScenes = new();
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public readonly List<string> BlurPrograms = new();
|
public readonly List<string> BlurPrograms = new();
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public readonly List<string> BlurWindows = new();
|
public readonly List<string> BlurWindows = new();
|
||||||
private readonly Dictionary<IntPtr, uint> _windowHandleSceneItems = new();
|
private readonly Dictionary<IntPtr, uint> _windowHandleSceneItems = new();
|
||||||
private readonly ILogger? _logger;
|
private readonly ILogger? _logger;
|
||||||
@ -164,29 +167,29 @@ public class Blur
|
|||||||
this._yOffset = sceneItemTransformInfo.Y;
|
this._yOffset = sceneItemTransformInfo.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WindowManagerOnWindowZOrderChanged(IntPtr[] neworder)
|
private void WindowManagerOnWindowZOrderChanged(IntPtr[] newOrder)
|
||||||
{
|
{
|
||||||
|
|
||||||
uint i = 0;
|
uint i = 0;
|
||||||
string prnt = $"Z-order changed\n{"Z",-3} | {"hWnd",-8} | {"PID",-8} | {"Name",-17} | {"Window Title",-17} | {"State",-13} | BBox\n";
|
string print = $"Z-order changed\n{"Z",-3} | {"hWnd",-8} | {"PID",-8} | {"Name",-17} | {"Window Title",-17} | {"State",-13} | BBox\n";
|
||||||
foreach (IntPtr windowHandle in neworder)
|
foreach (IntPtr windowHandle in newOrder)
|
||||||
{
|
{
|
||||||
WindowInfo windowInfo = _windowManager.WindowInfos.FirstOrDefault(w => w.WindowHandle == windowHandle);
|
WindowInfo windowInfo = _windowManager.WindowInfos.FirstOrDefault(w => w.WindowHandle == windowHandle);
|
||||||
if (windowInfo.WindowHandle is 0x0)
|
if (windowInfo.WindowHandle is 0x0)
|
||||||
continue;
|
continue;
|
||||||
prnt += $"{++i,3} | {windowInfo}\n";
|
print += $"{++i,3} | {windowInfo}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger?.LogInformation(prnt);
|
_logger?.LogInformation(print);
|
||||||
UpdateBlurs();
|
UpdateBlurs();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WindowManagerOnWindowsChanged(WindowInfo[] before, WindowInfo[] after)
|
private void WindowManagerOnWindowsChanged(WindowInfo[] before, WindowInfo[] after)
|
||||||
{
|
{
|
||||||
string prnt = "Window changed\n";
|
string print = "Window changed\n";
|
||||||
foreach (WindowInfo windowInfo in after)
|
foreach (WindowInfo windowInfo in after)
|
||||||
prnt += $"{windowInfo}\n";
|
print += $"{windowInfo}\n";
|
||||||
_logger?.LogInformation(prnt);
|
_logger?.LogInformation(print);
|
||||||
UpdateBlurs();
|
UpdateBlurs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ public struct Point
|
|||||||
public int X;
|
public int X;
|
||||||
public int Y;
|
public int Y;
|
||||||
|
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public Point(int x, int y)
|
public Point(int x, int y)
|
||||||
{
|
{
|
||||||
this.X = x;
|
this.X = x;
|
||||||
|
@ -7,6 +7,7 @@ public struct Rectangle
|
|||||||
{
|
{
|
||||||
public int Left, Top, Right, Bottom;
|
public int Left, Top, Right, Bottom;
|
||||||
|
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public Rectangle(int left, int top, int right, int bottom)
|
public Rectangle(int left, int top, int right, int bottom)
|
||||||
{
|
{
|
||||||
Left = left;
|
Left = left;
|
||||||
@ -15,42 +16,63 @@ public struct Rectangle
|
|||||||
Bottom = bottom;
|
Bottom = bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public Rectangle(System.Drawing.Rectangle r) : this(r.Left, r.Top, r.Right, r.Bottom) { }
|
public Rectangle(System.Drawing.Rectangle r) : this(r.Left, r.Top, r.Right, r.Bottom) { }
|
||||||
|
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public int X
|
public int X
|
||||||
{
|
{
|
||||||
get { return Left; }
|
get => Left;
|
||||||
set { Right -= (Left - value); Left = value; }
|
set
|
||||||
|
{
|
||||||
|
Right -= (Left - value);
|
||||||
|
Left = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public int Y
|
public int Y
|
||||||
{
|
{
|
||||||
get { return Top; }
|
get => Top;
|
||||||
set { Bottom -= (Top - value); Top = value; }
|
set
|
||||||
|
{
|
||||||
|
Bottom -= (Top - value);
|
||||||
|
Top = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public int Height
|
public int Height
|
||||||
{
|
{
|
||||||
get { return Bottom - Top; }
|
get => Bottom - Top;
|
||||||
set { Bottom = value + Top; }
|
set => Bottom = value + Top;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public int Width
|
public int Width
|
||||||
{
|
{
|
||||||
get { return Right - Left; }
|
get => Right - Left;
|
||||||
set { Right = value + Left; }
|
set => Right = value + Left;
|
||||||
}
|
}
|
||||||
|
|
||||||
public System.Drawing.Point Location
|
public System.Drawing.Point Location
|
||||||
{
|
{
|
||||||
get { return new System.Drawing.Point(Left, Top); }
|
get => new(Left, Top);
|
||||||
set { X = value.X; Y = value.Y; }
|
set
|
||||||
|
{
|
||||||
|
X = value.X;
|
||||||
|
Y = value.Y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public System.Drawing.Size Size
|
public System.Drawing.Size Size
|
||||||
{
|
{
|
||||||
get { return new System.Drawing.Size(Width, Height); }
|
get => new(Width, Height);
|
||||||
set { Width = value.Width; Height = value.Height; }
|
set
|
||||||
|
{
|
||||||
|
Width = value.Width;
|
||||||
|
Height = value.Height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static implicit operator System.Drawing.Rectangle(Rectangle r)
|
public static implicit operator System.Drawing.Rectangle(Rectangle r)
|
||||||
@ -78,10 +100,10 @@ public struct Rectangle
|
|||||||
return r.Left == Left && r.Top == Top && r.Right == Right && r.Bottom == Bottom;
|
return r.Left == Left && r.Top == Top && r.Right == Right && r.Bottom == Bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object? obj)
|
||||||
{
|
{
|
||||||
if (obj is Rectangle)
|
if (obj is Rectangle rectangle)
|
||||||
return Equals((Rectangle)obj);
|
return Equals(rectangle);
|
||||||
else if (obj is System.Drawing.Rectangle)
|
else if (obj is System.Drawing.Rectangle)
|
||||||
return Equals(new Rectangle((System.Drawing.Rectangle)obj));
|
return Equals(new Rectangle((System.Drawing.Rectangle)obj));
|
||||||
return false;
|
return false;
|
||||||
@ -94,6 +116,6 @@ public struct Rectangle
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{{LTRB {Left,-6:####0},{Top,-6:####0},{Right,-6:####0},{Bottom,-6:####0}}}";
|
return $"{{L{Left,-6:####0} T{Top,-6:####0} R{Right,-6:####0} B{Bottom,-6:####0}}}";
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
namespace OBSBlur.Window;
|
// ReSharper disable InvalidXmlDocComment
|
||||||
|
namespace OBSBlur.Window;
|
||||||
|
|
||||||
public enum ShowWindowCommands
|
public enum ShowWindowCommands
|
||||||
{
|
{
|
||||||
@ -51,6 +52,7 @@ public enum ShowWindowCommands
|
|||||||
/// similar to <see cref="Win32.ShowWindowCommand.Show"/>, except the
|
/// similar to <see cref="Win32.ShowWindowCommand.Show"/>, except the
|
||||||
/// window is not activated.
|
/// window is not activated.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
// ReSharper disable once InconsistentNaming
|
||||||
ShowNA = 8,
|
ShowNA = 8,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Activates and displays the window. If the window is minimized or
|
/// Activates and displays the window. If the window is minimized or
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
namespace OBSBlur.Window;
|
namespace OBSBlur.Window;
|
||||||
|
|
||||||
public struct WindowInfo
|
// ReSharper disable once InconsistentNaming
|
||||||
|
public readonly struct WindowInfo
|
||||||
{
|
{
|
||||||
internal IntPtr WindowHandle { get; init; }
|
internal IntPtr WindowHandle { get; init; }
|
||||||
public ShowWindowCommands WindowCommands { get; init; }
|
public ShowWindowCommands WindowCommands { get; init; }
|
||||||
@ -24,7 +25,7 @@ public struct WindowInfo
|
|||||||
return obj is WindowInfo other && Equals(other);
|
return obj is WindowInfo other && Equals(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Equals(WindowInfo other)
|
private bool Equals(WindowInfo other)
|
||||||
{
|
{
|
||||||
return WindowHandle == other.WindowHandle &&
|
return WindowHandle == other.WindowHandle &&
|
||||||
WindowCommands == other.WindowCommands &&
|
WindowCommands == other.WindowCommands &&
|
||||||
|
@ -2,14 +2,18 @@
|
|||||||
|
|
||||||
namespace OBSBlur.Window;
|
namespace OBSBlur.Window;
|
||||||
|
|
||||||
|
// ReSharper disable once InconsistentNaming
|
||||||
public partial class WindowManager : IDisposable
|
public partial class WindowManager : IDisposable
|
||||||
{
|
{
|
||||||
private readonly HashSet<WindowInfo> _windows = new(1024);
|
private readonly HashSet<WindowInfo> _windows = new(1024);
|
||||||
private List<IntPtr> _zOrder = GetWindowZOrder();
|
private List<IntPtr> _zOrder = GetWindowZOrder();
|
||||||
public IntPtr[] WindowZOrder => _zOrder.ToArray();
|
public IntPtr[] WindowZOrder => _zOrder.ToArray();
|
||||||
public WindowInfo[] WindowInfos => _windows.ToArray();
|
public WindowInfo[] WindowInfos => _windows.ToArray();
|
||||||
|
// ReSharper disable once FieldCanBeMadeReadOnly.Global
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public int UpdateInterval = 10;
|
public int UpdateInterval = 10;
|
||||||
private bool _keepUpdating = true;
|
private bool _keepUpdating = true;
|
||||||
|
|
||||||
public WindowManager()
|
public WindowManager()
|
||||||
{
|
{
|
||||||
Thread t = new (() =>
|
Thread t = new (() =>
|
||||||
@ -47,14 +51,14 @@ public partial class WindowManager : IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
public delegate void WindowsUpdatedHandler(WindowInfo[] windowInfos);
|
public delegate void WindowsUpdatedHandler(WindowInfo[] windowInfos);
|
||||||
public event WindowsUpdatedHandler WindowsUpdated;
|
public event WindowsUpdatedHandler? WindowsUpdated;
|
||||||
|
|
||||||
public delegate void WindowsChangedHandler(WindowInfo[] before, WindowInfo[] after);
|
public delegate void WindowsChangedHandler(WindowInfo[] before, WindowInfo[] after);
|
||||||
public event WindowsChangedHandler WindowsChanged;
|
public event WindowsChangedHandler? WindowsChanged;
|
||||||
|
|
||||||
public delegate void WindowsZOrderChangedHandler(IntPtr[] newOrder);
|
public delegate void WindowsZOrderChangedHandler(IntPtr[] newOrder);
|
||||||
|
|
||||||
public event WindowsZOrderChangedHandler ZOrderChanged;
|
public event WindowsZOrderChangedHandler? ZOrderChanged;
|
||||||
|
|
||||||
private bool GetWindowInfo(IntPtr windowHandle, IntPtr lParam)
|
private bool GetWindowInfo(IntPtr windowHandle, IntPtr lParam)
|
||||||
{
|
{
|
||||||
@ -65,9 +69,8 @@ public partial class WindowManager : IDisposable
|
|||||||
|
|
||||||
WindowPlacement placement = new ();
|
WindowPlacement placement = new ();
|
||||||
GetWindowPlacement(windowHandle, ref placement);
|
GetWindowPlacement(windowHandle, ref placement);
|
||||||
|
|
||||||
uint pid;
|
GetWindowThreadProcessId(windowHandle, out uint pid);
|
||||||
GetWindowThreadProcessId(windowHandle, out pid);
|
|
||||||
Process processInfo = Process.GetProcessById((int)pid);
|
Process processInfo = Process.GetProcessById((int)pid);
|
||||||
//nvcontainer does not have a window name
|
//nvcontainer does not have a window name
|
||||||
if (processInfo.ProcessName.Equals("nvcontainer"))
|
if (processInfo.ProcessName.Equals("nvcontainer"))
|
||||||
|
@ -3,6 +3,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace OBSBlur.Window;
|
namespace OBSBlur.Window;
|
||||||
|
|
||||||
|
// ReSharper disable once InconsistentNaming
|
||||||
public partial class WindowManager
|
public partial class WindowManager
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -23,7 +24,9 @@ public partial class WindowManager
|
|||||||
|
|
||||||
static List<IntPtr> GetWindowZOrder()
|
static List<IntPtr> GetWindowZOrder()
|
||||||
{
|
{
|
||||||
|
// ReSharper disable once InconsistentNaming
|
||||||
const uint GW_HWNDNEXT = 2;
|
const uint GW_HWNDNEXT = 2;
|
||||||
|
// ReSharper disable once InconsistentNaming
|
||||||
const uint GW_HWNDLAST = 1;
|
const uint GW_HWNDLAST = 1;
|
||||||
IntPtr desktopWindow = GetDesktopWindow();
|
IntPtr desktopWindow = GetDesktopWindow();
|
||||||
IntPtr topWindow = GetTopWindow(desktopWindow);
|
IntPtr topWindow = GetTopWindow(desktopWindow);
|
||||||
@ -47,6 +50,7 @@ public partial class WindowManager
|
|||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public static extern bool GetWindowPlacement(IntPtr windowHandle, ref WindowPlacement lpwndpl);
|
public static extern bool GetWindowPlacement(IntPtr windowHandle, ref WindowPlacement lpwndpl);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
@ -54,8 +58,9 @@ public partial class WindowManager
|
|||||||
|
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||||
static extern IntPtr SendMessage(IntPtr windowHandle, uint message, IntPtr wParam, [Out] StringBuilder lParam);
|
static extern IntPtr SendMessage(IntPtr windowHandle, uint message, IntPtr wParam, [Out] StringBuilder? lParam);
|
||||||
|
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public static string GetWindowTextRaw(IntPtr windowHandle)
|
public static string GetWindowTextRaw(IntPtr windowHandle)
|
||||||
{
|
{
|
||||||
// ReSharper disable twice InconsistentNaming
|
// ReSharper disable twice InconsistentNaming
|
||||||
|
@ -7,6 +7,7 @@ namespace OBSBlur.Window;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
// ReSharper disable once InconsistentNaming
|
||||||
public struct WindowPlacement
|
public struct WindowPlacement
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user