Esempio n. 1
0
        private void App_OnStartup(object sender, StartupEventArgs e)
        {
            InitializeTrayIcon();

            windowMonitor.StartMonitoringAsync();
            windowMonitor.ForegroundWindowInfoUpdated += windowInfo =>
            {
                var process = processLocator.GetProcessInfo(windowInfo);
                ApplicationProfile profile = null;
                if (process != null)
                {
                    profile = configurationManager.GetProfileForExecutable(process.ExecutablePath);
                }

                if (process == null || profile == null)
                {
                    Debug.WriteLine("Process: " + process?.ExecutablePath);
                    Debug.WriteLine("No process or profile. Resetting clipping.");
                    // reset cursor clip
                    Cursor.Clip = new Rectangle();
                    return;
                }

                Debug.WriteLine("Setting window clipping.");
                Cursor.Clip = new System.Drawing.Rectangle(
                    new System.Drawing.Point(windowInfo.Left + windowBorder, windowInfo.Top),
                    new System.Drawing.Size(
                        windowInfo.Right - windowInfo.Left - windowBorder * 2,
                        windowInfo.Bottom - windowInfo.Top - windowBorder));
            };
        }
        private ApplicationProfileObservable ProfilesToObservable(ApplicationProfile profile)
        {
            if (profile == null)
            {
                return(null);
            }

            return(new ApplicationProfileObservable()
            {
                ExecutablePath = profile.ExecutablePath
            });
        }