public RegionSelectorViewModel( [NotNull] ISelectionAdornerViewModel selectionAdorner, [NotNull][Dependency(WellKnownSchedulers.UI)] IScheduler uiScheduler, [NotNull][Dependency(WellKnownSchedulers.Background)] IScheduler bgScheduler) { SelectionAdorner = selectionAdorner.AddTo(Anchors); windowSeeker = new TaskWindowSeeker { SkipNotVisibleWindows = true }; var refreshRequest = new Subject <Unit>(); SelectionAdorner.WhenAnyValue(x => x.MousePosition, x => x.Owner).ToUnit() .Merge(refreshRequest) .Select(x => new { SelectionAdorner.MousePosition, SelectionAdorner.Owner }) .Where(x => x.Owner != null) .Sample(ThrottlingPeriod, bgScheduler) .ObserveOn(uiScheduler) .Select(x => x.MousePosition.ToScreen(x.Owner)) .Select(x => new Rectangle(x.X, x.Y, 1, 1)) .Select(ToRegionResult) .Do(x => Log.Debug($"Selection candidate: {x}")) .Subscribe(x => SelectionCandidate = x) .AddTo(Anchors); refreshRequest .Subscribe(() => windowSeeker.Refresh()) .AddTo(Anchors); Observable.Timer(DateTimeOffset.Now, TimeSpan.FromSeconds(1), bgScheduler).ToUnit() .Subscribe(refreshRequest) .AddTo(Anchors); }
private void RefreshWindowList() { windowSeeker.Refresh(); var existingWindows = windowListSource.Items.ToArray(); var itemsToAdd = windowSeeker.Windows.Except(existingWindows, WindowComparer).ToArray(); var itemsToRemove = existingWindows.Except(windowSeeker.Windows, WindowComparer).ToArray(); windowListSource.RemoveMany(itemsToRemove); windowListSource.AddRange(itemsToAdd); }