Broadcast Text pull-out (Live screen) + launch geometry 1920x1040/1366x768 with restore
This commit is contained in:
@@ -29,6 +29,7 @@ public partial class MainWindow : Window
|
||||
UpdateTaskbarOverlay();
|
||||
UpdateSelectionOverlay();
|
||||
LoadAvatarImage();
|
||||
RestoreWindowGeometry();
|
||||
AppLog.Write("MainWindow ctor: end");
|
||||
}
|
||||
|
||||
@@ -37,6 +38,52 @@ public partial class MainWindow : Window
|
||||
AppLog.Write("MainWindow loaded");
|
||||
}
|
||||
|
||||
// ─── Window geometry persistence (launch size/position) ───
|
||||
// Saved on close (RestoreBounds so a maximized window remembers its
|
||||
// un-maximize rect); restored in the ctor before the window is shown.
|
||||
// Values clamp to the minimums and to the primary work area — a position
|
||||
// saved on a since-disconnected secondary monitor falls back on-screen.
|
||||
|
||||
private void RestoreWindowGeometry()
|
||||
{
|
||||
try
|
||||
{
|
||||
var saved = _viewModel.RestoreWindowState();
|
||||
if (saved == null) return;
|
||||
var (left, top, width, height, state) = saved.Value;
|
||||
|
||||
var work = SystemParameters.WorkArea;
|
||||
width = Math.Clamp(width, MinWidth, work.Width);
|
||||
height = Math.Clamp(height, MinHeight, work.Height);
|
||||
left = Math.Clamp(left, work.Left - width + 120, work.Right - 120);
|
||||
top = Math.Clamp(top, work.Top, work.Bottom - 80);
|
||||
|
||||
Left = left;
|
||||
Top = top;
|
||||
Width = width;
|
||||
Height = height;
|
||||
if (state == "Maximized") WindowState = WindowState.Maximized;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLog.Write($"Window geometry restore failed: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveWindowGeometry()
|
||||
{
|
||||
try
|
||||
{
|
||||
var bounds = RestoreBounds;
|
||||
var state = WindowState == WindowState.Maximized ? "Maximized" : "Normal";
|
||||
_viewModel.PersistWindowState(bounds.Left, bounds.Top, bounds.Width, bounds.Height, state);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLog.Write($"Window geometry save failed: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private ytLive.Services.GlobalHotkeyManager? _hotkeys;
|
||||
|
||||
protected override void OnSourceInitialized(EventArgs e)
|
||||
@@ -66,6 +113,7 @@ public partial class MainWindow : Window
|
||||
|
||||
private void MainWindow_Closing(object? sender, CancelEventArgs e)
|
||||
{
|
||||
SaveWindowGeometry();
|
||||
_viewModel.Shutdown();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user