Ejemplo n.º 1
0
 public SoftwareMonitor(Screen screen, MonitorManager manager)
     : base(screen.DeviceName, manager)
 {
     // Initialize Brightness management
     overlay            = new SoftwareMonitorWindowOverlay(screen);
     SupportsBrightness = true;
     MinBrightness      = 20;
     mBrightness        = 100; // The window is always recreated with 100% transparency
 }
Ejemplo n.º 2
0
        public WmiMonitor(ManagementObject monitor, MonitorManager manager)
            : base(monitor.Properties["InstanceName"].Value.ToString(), manager)
        {
            this.monitor       = monitor;
            SupportsBrightness = true;

            try
            {
                ManagementScope          scope    = new ManagementScope("root\\WMI");
                String                   sQuery   = "SELECT * FROM WmiMonitorBrightness WHERE InstanceName='" + Name.Replace("\\", "\\\\") + "'";
                SelectQuery              query    = new SelectQuery(sQuery);
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
                foreach (var item in searcher.Get())
                {
                    mBrightness = (byte)item.Properties["CurrentBrightness"].Value;
                }
            }
            catch (ManagementException e)
            {
                MainWindow.Error("WMI monitor cannot read current Brightness: " + e.Message);
            }
        }
Ejemplo n.º 3
0
        public GammaRampMonitor(String name, MonitorManager manager)
            : base(name, manager)
        {
            //MainWindow.Trace("Creating GRAMP mon; " + screen.DeviceName);
            SupportsBrightness = true;
            MinBrightness      = 1;
            MaxBrightness      = 256;
            mBrightness        = WinApi.GammaBase; // The system is always loaded with full Brightness

            SupportsContrast = true;
            MaxContrast      = 255;
            mContrast        = 100; // Similarly as mBrightness

            SupportsTemperature = true;
            MinTemperature      = 2000;
            MaxTemperature      = 12000;
            mTemperature        = 3000; // TODO: What's default Temperature?

            try
            {
                WinApi.RAMP ramp = new WinApi.RAMP();
                if (WinApi.GetDeviceGammaRamp(WinApi.GetDC(IntPtr.Zero), ref ramp) != WinApi.WINAPI_GAMMARAMP_RESULT_SUCCESS)
                {
                    MainWindow.Error("Getting gamma ramp failed");
                    SupportsBrightness  = false;
                    SupportsContrast    = false;
                    SupportsTemperature = false;
                    return;
                }
                mBrightness = ramp.Red[1] - WinApi.GammaBase;
            }
            catch (NotSupportedException)
            {
                SupportsBrightness = false;
            }
        }
Ejemplo n.º 4
0
 protected Monitor(String name, MonitorManager manager)
 {
     Name    = name;
     Manager = manager;
 }
Ejemplo n.º 5
0
        public HardwareMonitor(IntPtr hMonitor, String name, MonitorManager manager)
            : base(name, manager)
        {
            this.hMonitor = hMonitor;

            uint monitorCapabilities        = 0;
            uint supportedColorTemperatures = 0;

            if (!HwmWinApi.GetMonitorCapabilities(hMonitor, ref monitorCapabilities, ref supportedColorTemperatures))
            {
                MainWindow.Win32Error("Monitor " + name + " cannot GetMonitorCapabilities(). However, we'll try to communicate with that monitor anyway.");
                monitorCapabilities        = HwmWinApi.MC_CAPS_BRIGHTNESS | HwmWinApi.MC_CAPS_CONTRAST | HwmWinApi.MC_CAPS_COLOR_TEMPERATURE;
                supportedColorTemperatures = 0xFFFFFFFF;
            }

            if ((monitorCapabilities & HwmWinApi.MC_CAPS_BRIGHTNESS) > 0)
            {
                SupportsBrightness = true;

                uint minBrightness = 0u, currBrightness = 0u, maxBrightness = 0u;
                if (HwmWinApi.GetMonitorBrightness(hMonitor, ref minBrightness, ref currBrightness, ref maxBrightness))
                {
                    MinBrightness = (int)minBrightness;
                    MaxBrightness = (int)maxBrightness;
                    mBrightness   = (int)currBrightness; // Don't call property. Just update the value. Monitor's Brightness is already set to that value, so no need to waste time calling monitor API
                }
                else
                {
                    MainWindow.Win32Error("HardwareMonitor Cannot GetMonitorBrightness()");
                }
            }

            if ((monitorCapabilities & HwmWinApi.MC_CAPS_CONTRAST) > 0)
            {
                SupportsContrast = true;

                uint minContrast = 0u, currContrast = 0u, maxContrast = 0u;
                if (HwmWinApi.GetMonitorContrast(hMonitor, ref minContrast, ref currContrast, ref maxContrast))
                {
                    MinContrast = (int)minContrast;
                    MaxContrast = (int)maxContrast;
                    mContrast   = (int)currContrast; // Don't call property. Just update the value. Monitor's Brightness is already set to that value, so no need to waste time calling monitor API
                }
                else
                {
                    MainWindow.Win32Error("HardwareMonitor Cannot GetMonitorContrast()");
                }
            }

            SupportedColorTemperaturesList = new DoubleCollection();
            if ((monitorCapabilities & HwmWinApi.MC_CAPS_COLOR_TEMPERATURE) > 0)
            {
                SupportsTemperature = true;

                HwmWinApi.MC_COLOR_TEMPERATURE currentColorTemperature = HwmWinApi.MC_COLOR_TEMPERATURE.MC_COLOR_TEMPERATURE_UNKNOWN;
                if (HwmWinApi.GetMonitorColorTemperature(hMonitor, ref currentColorTemperature))
                {
                    mTemperature = ConverWinTemperature(currentColorTemperature);
                }
                else
                {
                    MainWindow.Win32Error("HardwareMonitor Cannot GetMonitorColorTemperature()");
                }

                if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_4000K) > 0)
                {
                    SupportedColorTemperaturesList.Add(4000);
                }
                if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_5000K) > 0)
                {
                    SupportedColorTemperaturesList.Add(5000);
                }
                if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_6500K) > 0)
                {
                    SupportedColorTemperaturesList.Add(6500);
                }
                if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_7500K) > 0)
                {
                    SupportedColorTemperaturesList.Add(7500);
                }
                if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_8200K) > 0)
                {
                    SupportedColorTemperaturesList.Add(8200);
                }
                if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_9300K) > 0)
                {
                    SupportedColorTemperaturesList.Add(9300);
                }
                if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_10000K) > 0)
                {
                    SupportedColorTemperaturesList.Add(10000);
                }
                if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_11500K) > 0)
                {
                    SupportedColorTemperaturesList.Add(11500);
                }

                if (SupportedColorTemperaturesList.Count == 0)
                {
                    SupportsTemperature = false;
                }
            }

            MainWindow.Trace("DBG HWMON CAP STR " + name + ":");

            uint capabilitiesStringLength = 0;

            if (!HwmWinApi.GetCapabilitiesStringLength(hMonitor, ref capabilitiesStringLength))
            {
                MainWindow.Win32Error("Cannot get GetCapabilitiesStringLength()");
                return;
            }

            StringBuilder capabilities = new StringBuilder((int)capabilitiesStringLength);

            if (!HwmWinApi.CapabilitiesRequestAndCapabilitiesReply(hMonitor, capabilities, capabilitiesStringLength))
            {
                MainWindow.Win32Error("Cannot get CapabilitiesRequestAndCapabilitiesReply()");
                return;
            }

            MainWindow.Trace("CAPABILITIES STR --> " + capabilities);
            MainWindow.Trace(" - " + monitorCapabilities);
            MainWindow.Trace(" - " + supportedColorTemperatures);
        }