internal static Task <Selection> Select(SelectControl.ModeType mode, Rect previousRegion, Monitor currentMonitor, bool quickSelection = false) { _taskCompletionSource = new TaskCompletionSource <Selection>(); Selectors.Clear(); var monitors = Monitor.AllMonitorsGranular(); //If in quick screen selection mode and there's just one screen, select that one. if (quickSelection && mode == SelectControl.ModeType.Fullscreen && monitors.Count == 1) { return(Task.FromResult(new Selection(monitors.FirstOrDefault(), monitors[0].Bounds))); } foreach (var monitor in monitors) { var selector = new RegionSelector(); selector.Select(monitor, mode, monitor.Handle == currentMonitor?.Handle ? previousRegion : Rect.Empty, RegionSelected, RegionChanged, RegionGotHover, RegionAborted); Selectors.Add(selector); } //Return only when the region gets selected. return(_taskCompletionSource.Task); }
public void Select(Monitor monitor, SelectControl.ModeType mode, Rect previousRegion, Action <Rect> selected, Action <Monitor> changed, Action <Monitor> gotHover, Action aborted) { //Resize to fit given window. Left = monitor.Bounds.Left; Top = monitor.Bounds.Top; Width = monitor.Bounds.Width; Height = monitor.Bounds.Height; Monitor = monitor; _scale = monitor.Dpi / 96d; _selected = selected; _changed = changed; _gotHover = gotHover; _aborted = aborted; SelectControl.Scale = monitor.Scale; SelectControl.ParentLeft = Left; SelectControl.ParentTop = Top; SelectControl.BackImage = CaptureBackground(); SelectControl.Mode = mode; if (mode == Controls.SelectControl.ModeType.Region) { //Since each region selector is attached to a single screen, the selection must be translated. SelectControl.Selected = previousRegion.Translate(monitor.Bounds.Left * -1, monitor.Bounds.Top * -1); SelectControl.Windows.Clear(); } else if (mode == Controls.SelectControl.ModeType.Window) { //Get only the windows that are located inside the given screen. var win = Native.EnumerateWindowsByMonitor(monitor); //Since each region selector is attached to a single screen, the list of positions must be translated. SelectControl.Windows = win.AdjustPosition(monitor.Bounds.Left, monitor.Bounds.Top); } else if (mode == Controls.SelectControl.ModeType.Fullscreen) { //Each selector is the whole screen. SelectControl.Windows = new List <DetectedRegion> { new DetectedRegion(monitor.Handle, new Rect(new Size(monitor.Bounds.Width, monitor.Bounds.Height)), monitor.Name) }; } //Call the selector to select the region. SelectControl.IsPickingRegion = true; Show(); }
internal static Task <Rect> Select(SelectControl.ModeType mode, Rect previousRegion) { _taskCompletionSource = new TaskCompletionSource <Rect>(); Selectors.Clear(); foreach (var monitor in Monitor.AllMonitorsGranular()) { var selector = new RegionSelector(); selector.Select(monitor, mode, previousRegion, RegionSelected, RegionChanged, RegionGotHover, RegionAborted); Selectors.Add(selector); } //Return only when the region gets selected. return(_taskCompletionSource.Task); }