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