private static bool IsForegroundValid(Win32App foreground, ForegroundMatchData fromData,
            ForegroundMatchData toData)
        {
            var oldTitle = _foregroundTitle;
            var oldFullscreen = _isForegroundFullscreen;
            _foregroundTitle = foreground.GetTitle();
            _isForegroundFullscreen = foreground.IsFullScreen();

            if (_foregroundTitle == null)
                _foregroundTitle = string.Empty;
            if (oldTitle == null)
                oldTitle = string.Empty;

            bool isTitleFromValid;
            bool isFullscreenFromValid;
            bool isTitleToValid;
            bool isFullscreenToValid;

            switch (fromData.TitleMatchMode)
            {
                case StringMatchMode.Any:
                    isTitleFromValid = true;
                    break;
                case StringMatchMode.Equals:
                    isTitleFromValid = oldTitle == fromData.Title;
                    break;
                case StringMatchMode.Contains:
                    isTitleFromValid = oldTitle.Contains(fromData.Title);
                    break;
                default:
                    isTitleFromValid = false;
                    break;
            }
            switch (toData.TitleMatchMode)
            {
                case StringMatchMode.Any:
                    isTitleToValid = true;
                    break;
                case StringMatchMode.Equals:
                    isTitleToValid = _foregroundTitle == toData.Title;
                    break;
                case StringMatchMode.Contains:
                    isTitleToValid = _foregroundTitle.Contains(toData.Title);
                    break;
                default:
                    isTitleToValid = false;
                    break;
            }
            switch (fromData.Fullscreen)
            {
                case YesNoAny.Any:
                    isFullscreenFromValid = true;
                    break;
                case YesNoAny.Yes:
                    isFullscreenFromValid = oldFullscreen;
                    break;
                case YesNoAny.No:
                    isFullscreenFromValid = !oldFullscreen;
                    break;
                default:
                    isFullscreenFromValid = false;
                    break;
            }
            switch (toData.Fullscreen)
            {
                case YesNoAny.Any:
                    isFullscreenToValid = true;
                    break;
                case YesNoAny.Yes:
                    isFullscreenToValid = _isForegroundFullscreen;
                    break;
                case YesNoAny.No:
                    isFullscreenToValid = !_isForegroundFullscreen;
                    break;
                default:
                    isFullscreenToValid = false;
                    break;
            }

            return isTitleFromValid && isFullscreenFromValid && isTitleToValid && isFullscreenToValid;
        }
 public static bool DoesMonitorHaveFullscreenApp(Rect bounds, Win32App ignoreApp)
     => DoesMonitorHaveFullscreenApp(ScreenHelper.GetScreen(bounds), ignoreApp);
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            if (!HasLoaded)
                return;

            var hwnd = new WindowInteropHelper(this).Handle;
            var widgetSrc = HwndSource.FromHwnd(hwnd);

            widgetSrc?.AddHook(WndProc);

            ThisApp = new Win32App(hwnd);

            if (Settings.Unclickable)
                ThisApp.SetWindowExTransparent();

            if (Settings.IsAppBar)
                SetAsAppBar();

            UpdateUi(false);

            ViewModel.OnUiLoad();

            //FocusMainElement();

            HasSourceLoaded = true;
        }
 private static bool DoesMonitorHaveFullscreenApp(Screen screen, Win32App ignoreApp)
 {
     var foregroundApp = Win32Helper.GetForegroundApp();
     return foregroundApp.Hwnd != ignoreApp?.Hwnd && foregroundApp.IsFullScreen(screen);
 }
        private static bool IsForegroundValid(Win32App foreground, ForegroundMatchData fromData,
                                              ForegroundMatchData toData)
        {
            var oldTitle      = _foregroundTitle;
            var oldFullscreen = _isForegroundFullscreen;

            _foregroundTitle        = foreground.GetTitle();
            _isForegroundFullscreen = foreground.IsFullScreen();

            if (_foregroundTitle == null)
            {
                _foregroundTitle = string.Empty;
            }
            if (oldTitle == null)
            {
                oldTitle = string.Empty;
            }

            bool isTitleFromValid;
            bool isFullscreenFromValid;
            bool isTitleToValid;
            bool isFullscreenToValid;

            switch (fromData.TitleMatchMode)
            {
            case StringMatchMode.Any:
                isTitleFromValid = true;
                break;

            case StringMatchMode.Equals:
                isTitleFromValid = oldTitle == fromData.Title;
                break;

            case StringMatchMode.Contains:
                isTitleFromValid = oldTitle.Contains(fromData.Title);
                break;

            default:
                isTitleFromValid = false;
                break;
            }
            switch (toData.TitleMatchMode)
            {
            case StringMatchMode.Any:
                isTitleToValid = true;
                break;

            case StringMatchMode.Equals:
                isTitleToValid = _foregroundTitle == toData.Title;
                break;

            case StringMatchMode.Contains:
                isTitleToValid = _foregroundTitle.Contains(toData.Title);
                break;

            default:
                isTitleToValid = false;
                break;
            }
            switch (fromData.Fullscreen)
            {
            case YesNoAny.Any:
                isFullscreenFromValid = true;
                break;

            case YesNoAny.Yes:
                isFullscreenFromValid = oldFullscreen;
                break;

            case YesNoAny.No:
                isFullscreenFromValid = !oldFullscreen;
                break;

            default:
                isFullscreenFromValid = false;
                break;
            }
            switch (toData.Fullscreen)
            {
            case YesNoAny.Any:
                isFullscreenToValid = true;
                break;

            case YesNoAny.Yes:
                isFullscreenToValid = _isForegroundFullscreen;
                break;

            case YesNoAny.No:
                isFullscreenToValid = !_isForegroundFullscreen;
                break;

            default:
                isFullscreenToValid = false;
                break;
            }

            return(isTitleFromValid && isFullscreenFromValid && isTitleToValid && isFullscreenToValid);
        }