Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions SentryReplay/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace SentryReplay;
public partial class MainWindow : Window
{
private readonly MainWindowViewModel _viewModel;
private readonly HashSet<Window> _clickHookedSurfaces = [];
private bool _isClosing;
private bool _isReadyToClose;

Expand All @@ -30,6 +31,14 @@ public MainWindow()
_viewModel.PropertyChanged += ViewModelOnPropertyChanged;

DataContext = _viewModel;

// Clicking a player (incl. the mini previews) switches to that camera. Flyleaf renders each camera
// into its own native surface, so the click must be caught on the surface, not via a WPF overlay.
HookCameraClick(FrontFlyleafHost, MainWindowViewModel.FrontCameraView);
HookCameraClick(BackFlyleafHost, MainWindowViewModel.RearCameraView);
HookCameraClick(LeftFlyleafHost, MainWindowViewModel.LeftCameraView);
HookCameraClick(RightFlyleafHost, MainWindowViewModel.RightCameraView);

UpdateCameraHostLayout();
}

Expand Down Expand Up @@ -113,6 +122,27 @@ private void OnSearchBoxFocusRequested(object sender, EventArgs e)
SearchBox.SelectAll();
}

// The FlyleafHost creates its native Surface window when it loads (and reuses it across reparenting),
// so subscribe once it exists. handledEventsToo ensures we still see the click if Flyleaf marks it
// handled, and the HashSet guards against re-subscribing when Loaded fires again on a reparent.
private void HookCameraClick(FlyleafHost host, string cameraView)
{
host.Loaded += (_, _) =>
{
if (host.Surface is { } surface && _clickHookedSurfaces.Add(surface))
{
surface.AddHandler(
MouseLeftButtonUpEvent,
new MouseButtonEventHandler((_, e) =>
{
_viewModel.SelectCameraViewCommand.Execute(cameraView);
e.Handled = true;
}),
handledEventsToo: true);
}
};
}

private void UpdateCameraHostLayout()
{
if (PrimaryCameraHostSlot is null)
Expand Down