using CursorLang.Models; namespace CursorLang.Services; /// /// Ties layout tracking to showing the popup. /// Lives for as long as the application runs, regardless of the open windows. /// public sealed class LayoutNotificationCoordinator : IDisposable { private readonly IKeyboardLayoutService _layoutService; private readonly ILayoutPopupService _popupService; public LayoutNotificationCoordinator(IKeyboardLayoutService layoutService, ILayoutPopupService popupService) { _layoutService = layoutService; _popupService = popupService; } public void Start() { _layoutService.LayoutChanged += OnLayoutChanged; _layoutService.Start(); } public void Dispose() { _layoutService.LayoutChanged -= OnLayoutChanged; _layoutService.Stop(); } private void OnLayoutChanged(object? sender, LayoutChangedEventArgs e) { // When moving to another application the layout changes without the user // taking part, and a popup would be intrusive if (e.Reason == LayoutChangeReason.UserSwitched) { _popupService.Show(e.Layout); } } }