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);
        }
Exemple #2
0
        public WindowListProvider()
        {
            windowListSource = new SourceList <WindowHandle>();
            windowListSource
            .Connect()
            .Filter(x => !string.IsNullOrWhiteSpace(x.Title))
            .Sort(new SortExpressionComparer <WindowHandle>().ThenByAscending(x => x.Title).ThenByAscending(x => x.Title?.Length ?? int.MaxValue))
            .ObserveOnDispatcher()
            .Bind(out windowList)
            .Subscribe()
            .AddTo(Anchors);

            windowSeeker = new TaskWindowSeeker
            {
                SkipNotVisibleWindows = true
            };

            Observable.Timer(DateTimeOffset.Now, TimeSpan.FromSeconds(1))
            .Subscribe(RefreshWindowList)
            .AddTo(Anchors);
        }