예제 #1
0
        public Func <Window, VirtualDesktopManager, List <Window> > CreateHideBehavior()
        {
            return((w, m) =>
            {
                ApplicationBehaviorsProcess process = GetProcessSettings(w.WindowInfo);
                var windows = new List <WindowInfo>();

                // Ensure at least a default setting is included.
                var hideBehaviors = new List <object>();
                if (process == null || process.HideBehavior.Items.Length == 0)
                {
                    hideBehaviors.Add(new ApplicationBehaviorsProcessHideBehaviorDefault {
                        Hide = ApplicationBehaviorsProcessHideBehaviorDefaultHide.AllProcessWindows
                    });
                }
                else
                {
                    hideBehaviors = process.HideBehavior.Items.ToList();
                }

                // Go through all specified cut behaviors in order.
                foreach (var hideBehavior in hideBehaviors.Cast <ICutBehavior>())
                {
                    windows.AddRange(hideBehavior.ToCut(w.WindowInfo, m));
                }

                return windows.Distinct().Select(wi => new Window(wi)).ToList();
            });
        }
예제 #2
0
        ApplicationBehaviorsProcess GetProcessSettings(WindowInfo window)
        {
            // See whether settings are cached.
            if (_accessDeniedWindows.Contains(window))
            {
                return(_dontHandleProcess);
            }
            if (_windowProcessBehaviors.ContainsKey(window))
            {
                return(_windowProcessBehaviors[window]);
            }

            // Prevent cached settings from being kept in memory when windows are destroyed.
            var deniedToRemove = _accessDeniedWindows.Where(w => w.IsDestroyed()).ToArray();

            deniedToRemove.ForEach(w => _accessDeniedWindows.Remove(w));
            var processBehaviorsToRemove = _windowProcessBehaviors.Where(p => p.Key.IsDestroyed()).ToArray();

            processBehaviorsToRemove.ForEach(p => _windowProcessBehaviors.Remove(p.Key));

            // Get settings.
            Process process = window.GetProcess();

            try
            {
                // Find matching settings based on process file info.
                var matches = _settings.Process.Where(p => new TargetProcess(p.Name, p.CompanyName, p.Version).Matches(process)).ToList();

                // Select the most optimal match, or handle the process by default when no match found.
                ApplicationBehaviorsProcess processBehavior = matches.Count == 0
                                        ? _handleProcess
                                        : matches.MaxBy(p => p.Version?.Length ?? 0);    // Longest version number that matches is most 'specific'.
                _windowProcessBehaviors[window] = processBehavior;

                return(processBehavior);
            }
            catch (Win32Exception)
            {
                _accessDeniedWindows.Add(window);
                return(_dontHandleProcess);
            }
        }
예제 #3
0
        void AddBehaviors(ApplicationBehaviors newBehaviors)
        {
            // Add new common behaviors.
            _settings.CommonIgnoreWindows.Window = newBehaviors.CommonIgnoreWindows.Window
                                                   .Union(_settings.CommonIgnoreWindows.Window)
                                                   .ToArray();

            // Add new or overwrite existing process behaviors.
            List <ApplicationBehaviorsProcess> processes = _settings.Process.ToList();

            foreach (ApplicationBehaviorsProcess newProcess in newBehaviors.Process)
            {
                ApplicationBehaviorsProcess same = processes.FirstOrDefault(p => newProcess.Equals(p));
                if (same != null)
                {
                    processes.Remove(same);
                }
                processes.Add(newProcess);
            }
            _settings.Process = processes.ToArray();
        }
예제 #4
0
        public Func <Window, bool> CreateWindowFilter()
        {
            return(w =>
            {
                // Custom filter and common windows to filter.
                if (!_windowManagerFilter(w) || _settings.CommonIgnoreWindows.Window.FirstOrDefault(i => i.Equals(w.WindowInfo)) != null)
                {
                    return false;
                }

                // Check whether the process needs to be managed at all.
                ApplicationBehaviorsProcess process = GetProcessSettings(w.WindowInfo);
                if (!process.ShouldHandleProcess)
                {
                    return false;
                }

                // Process specific settings.
                ApplicationBehavior.Window listedWindow = process.IgnoreWindows.Window.FirstOrDefault(i => i.Equals(w.WindowInfo));
                return process.IgnoreWindows.Mode == ApplicationBehaviorsProcessIgnoreWindowsMode.NoneExcept
                                        ? listedWindow == null
                                        : listedWindow != null;
            });
        }