///<summary> /// Sync AC and DC brightness settings in the current power scheme. /// The sync mutex is NOT acquired by this function. /// Call SyncBrightness() instead to prevent a race condition when multiple instances. ///</summary> void SyncBrightness_NoMutex() { // Get the current power scheme's AC & DC brightness levels BrightnessInfo current = GetBrightness(); if (current == null) { Console.WriteLine("Cannot read current brightness information. Doing nothing."); return; } ShowCurrentBrightnessInfo(ref current); if (current.AC == current.DC) { Console.WriteLine("Already in sync."); return; } // Sync if (current.isAC) { Console.WriteLine("Changing DC brightness to " + current.AC + "."); SetBrightness(PowerType.DC, current.AC); } else { Console.WriteLine("Changing AC brightness to " + current.DC + "."); SetBrightness(PowerType.AC, current.DC); } }
public SliderViewModel(BrightnessInfo info, int id) { Name = "Monitor"; Minimum = info.Minimum; Maximum = info.Maximum; Current = info.Current; Id = id; }
/// <summary> /// Returns the capabilities of the monitor /// </summary> private BrightnessInfo getCapabilities() { var info = new BrightnessInfo(); try { using (var monitors = new MonitorsCollector()) Dxva2.GetMonitorBrightness(monitors.Primary.hPhysicalMonitor, ref info.Minimum, ref info.Current, ref info.Maximum); info.Minimum = 0; info.Maximum = 100; } catch { } return(info); }
void ShowCurrentBrightnessInfo(ref BrightnessInfo current) { ShowHeader(); Console.WriteLine("Current power source: " + (current.isAC ? "AC" : "DC")); if (current.isAC || opt_verbose) { Console.WriteLine("AC brightness: " + current.AC); } if (!current.isAC || opt_verbose) { Console.WriteLine("DC brightness: " + current.DC); } }
BrightnessInfo GetBrightness() { uint result; IntPtr pGuid = NULL; BrightnessInfo info = new BrightnessInfo(); SYSTEM_POWER_STATUS stat; if (!GetSystemPowerStatus(out stat) || (stat._ACLineStatus != 0 && stat._ACLineStatus != 1)) { Console.WriteLine("Cannot determine the power mode. Doing nothing."); return(null); } info.isAC = (stat._ACLineStatus == 1); result = PowerGetActiveScheme(NULL, ref pGuid); if (result != 0) { Console.WriteLine("Could not get the active power scheme."); return(null); } Guid activeScheme = (Guid)Marshal.PtrToStructure(pGuid, typeof(Guid)); IntPtr brightness = NULL; int type = 0; uint size = 4; result = PowerReadACValue(NULL, activeScheme, VideoSubgroup, BrightnessKey, ref type, ref brightness, ref size); if (result != 0) { Console.WriteLine("Could not get the brightness of AC."); return(null); } info.AC = (int)brightness; result = PowerReadDCValue(NULL, activeScheme, VideoSubgroup, BrightnessKey, ref type, ref brightness, ref size); if (result != 0) { Console.WriteLine("Could not get the brightness of DC."); return(null); } info.DC = (int)brightness; return(info); }
public DisplayController() { this.wmiDriver.BrightnessChanged += (level) => this.BrightnessChanged?.Invoke(level); this.Capabilities = this.getCapabilities(); }