Web source: fix rendering — fixed 1920×1080 viewport (OBS pattern), Stretch=Uniform, startup registration

This commit is contained in:
2026-08-28 10:23:59 -07:00
parent fd6e02b687
commit e917c41a48
6 changed files with 88 additions and 207 deletions
+6 -17
View File
@@ -40,10 +40,13 @@ public sealed class WebView2Manager : IDisposable
{
if (_sessions.ContainsKey(source.Id)) return;
// OBS pattern: the browser viewport is the canvas size (1920×1080),
// never the element box. The page renders full at its designed size;
// the preview scales the captured frame independently (Stretch=Uniform).
var webView = new WebView2
{
Width = source.Width > 0 ? source.Width : 640,
Height = source.Height > 0 ? source.Height : 480,
Width = 1920,
Height = 1080,
DefaultBackgroundColor = System.Drawing.Color.Transparent,
Visibility = System.Windows.Visibility.Visible,
};
@@ -65,21 +68,6 @@ public sealed class WebView2Manager : IDisposable
_sessions[source.Id] = session;
source.PropertyChanged += (_, e) =>
{
if (e.PropertyName == nameof(Source.Width) || e.PropertyName == nameof(Source.Height))
{
var w = Math.Max(1, (int)source.Width);
var h = Math.Max(1, (int)source.Height);
if (Math.Abs(session.Control.Width - w) > 0.5 ||
Math.Abs(session.Control.Height - h) > 0.5)
{
session.Control.Width = w;
session.Control.Height = h;
}
}
};
timer.Tick += (_, _) =>
{
if (!session.Disposed && session.Initialized)
@@ -132,6 +120,7 @@ public sealed class WebView2Manager : IDisposable
_ = cws.ExecuteScriptAsync(
"document.documentElement.style.background='transparent';" +
"document.body.style.background='transparent';");
_ = CaptureFrame(source.Id);
};
session.Initialized = true;