예제 #1
0
        public MainWindow()
        {
            var container = new Container();

            container.Register <IConfigService, ConfigService>();
            container.Register <IScreenColorService, ScreenColorService>();
            container.Register <IMonitorService, MonitorService>();
            container.Verify();

            _configService      = container.GetInstance <IConfigService>();
            _temperatureService = container.GetInstance <IScreenColorService>();
            _monitorService     = container.GetInstance <IMonitorService>();

            Monitors        = new ObservableCollection <Monitor>(_monitorService.GetMonitors());
            SelectedMonitor = Monitors.FirstOrDefault();

            bool exists = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)).Length > 1;

            if (exists)            //If this program already has an instance
            {
                try
                {
                    NamedPipeClientStream pipeStream = new NamedPipeClientStream(".", "instance", PipeDirection.Out, PipeOptions.None);

                    pipeStream.Connect();

                    Environment.Exit(0);
                }
                catch (TimeoutException oEx)
                {
                    Debug.WriteLine(oEx.Message);
                }
            }
            else            //If the program is not already running
            {
                _pipeServer = new NamedPipeServerStream("instance", PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);

                _pipeServer.BeginWaitForConnection(WaitForConnectionCallBack, _pipeServer);
            }

            AssignKeyToConfigCommand = new RelayCommand(AssignKeyToConfig);
            SaveConfigCommand        = new RelayCommand(SaveConfig);
            DeleteConfigCommand      = new RelayCommand(DeleteConfig);
            MoveConfigUpCommand      = new RelayCommand(MoveConfigUp);
            MoveConfigDownCommand    = new RelayCommand(MoveConfigDown);
            RefreshMonitorsCommand   = new RelayCommand(RefreshMonitors);


            _notifyIcon.Icon    = Properties.Resources.icon;
            _notifyIcon.Click  += NotifyIconOnClick;
            _notifyIcon.Visible = true;

            SystemEvents.SessionSwitch          += SystemEventsOnSessionSwitch;
            SystemEvents.UserPreferenceChanging += SystemEvents_UserPreferenceChanging;
            SystemEvents.PaletteChanged         += SystemEvents_PaletteChanged;
            SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;

            InitializeComponent();
        }
예제 #2
0
        /// <summary>
        /// Changes screen color from a Config
        /// </summary>
        public unsafe void ChangeScreenColorFromConfig(Config config)
        {
            ushort *gArray = stackalloc ushort[3 * 256];

            foreach (Monitor monitor in _monitorService.GetMonitors())
            {
                ChangeScreenColorFromKelvin(6600, monitor);
            }

            foreach (Monitor monitor in config.Monitors)
            {
                for (int i = 0; i < 256 * 3; i++)
                {
                    gArray[i] = monitor.Rgb[i];
                }

                SetDeviceGammaRamp(_monitorService.GetHdcByMonitorIndex(monitor.Index).ToInt32(), gArray);
            }
        }
예제 #3
0
 private void RefreshMonitors(object o)
 {
     Monitors        = new ObservableCollection <Monitor>(_monitorService.GetMonitors(true));
     SelectedMonitor = Monitors.FirstOrDefault();
 }