diff --git a/OBSBlur/OBS/Blur.cs b/OBSBlur/OBS/Blur.cs index e7cf939..6b46f90 100644 --- a/OBSBlur/OBS/Blur.cs +++ b/OBSBlur/OBS/Blur.cs @@ -17,6 +17,7 @@ public class Blur private readonly List _blurPrograms = new(); private readonly Dictionary _windowHandleSceneItems = new(); private readonly ILogger? _logger; + private float _scaleWidth = 1, _scaleHeight = 1; public Blur(string obsUrl, string obsPassword, string[] enabledObsScenes, string[] blurPrograms, ILogger? logger = null) { @@ -113,10 +114,10 @@ public class Blur SceneItemTransformInfo info = new() { - X = windowInfo.WindowRectangle.X, - Y = windowInfo.WindowRectangle.Y, - BoundsHeight = windowInfo.WindowRectangle.Height, - BoundsWidth = windowInfo.WindowRectangle.Width, + X = windowInfo.WindowRectangle.X * _scaleWidth, + Y = windowInfo.WindowRectangle.Y * _scaleHeight, + BoundsWidth = windowInfo.WindowRectangle.Width * _scaleWidth, + BoundsHeight = windowInfo.WindowRectangle.Height * _scaleHeight, BoundsType = SceneItemBoundsType.OBS_BOUNDS_STRETCH, Alignnment = 5 }; @@ -202,6 +203,25 @@ public class Blur } } + private void SetScaleFactors() + { + try + { + JObject response = _websocket.SendRequest("GetVideoSettings"); + if(!response.TryGetValue("baseWidth", out JToken? baseWidth) || !response.TryGetValue("baseHeight", out JToken? baseHeight)) + throw new KeyNotFoundException("Response missing key baseWidth or baseHeight"); + Rectangle desktopRectangle = _windowManager.GetDesktopRectangle(); + this._scaleWidth = baseWidth.Value() / desktopRectangle.Width; + this._scaleHeight = baseHeight.Value() / desktopRectangle.Height; + } + catch (Exception e) + { + _logger?.LogError(e, "Request 'GetVideoSettings'"); + throw; + } + + } + private void WindowManagerOnWindowZOrderChanged(IntPtr[] neworder) { @@ -237,6 +257,8 @@ public class Blur { _currentObsScene = _websocket.GetCurrentProgramScene(); _logger?.LogInformation($"Obs Connected. Current Scene '{_currentObsScene}'"); + SetScaleFactors(); + _logger?.LogInformation($"Scale-Factors: Width={this._scaleWidth:F} Height={this._scaleHeight:F}"); UpdateBlurs(); } diff --git a/OBSBlur/Window/WindowManager.cs b/OBSBlur/Window/WindowManager.cs index 2557a83..0582739 100644 --- a/OBSBlur/Window/WindowManager.cs +++ b/OBSBlur/Window/WindowManager.cs @@ -77,14 +77,17 @@ public partial class WindowManager : IDisposable if (windowTitle.Length < 1) return true; - Rectangle rect; - GetWindowRect(windowHandle, out rect); + GetWindowRect(windowHandle, out Rectangle rect); _windows.Add(new WindowInfo(windowHandle, windowTitle, processInfo, placement.ShowCmd, rect)); return true; } - - + + public Rectangle GetDesktopRectangle() + { + GetWindowRect(GetDesktopWindow(), out Rectangle rect); + return rect; + } public void Dispose() {