Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel12321 authored Oct 20, 2021
2 parents 5ad0be4 + 416cc05 commit 0504f6d
Show file tree
Hide file tree
Showing 114 changed files with 3,488 additions and 1,318 deletions.
9 changes: 0 additions & 9 deletions .github/ISSUE_TEMPLATE/blank_issue.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
---
name: Bug report
about: Create a bug report to help us improve.
name: "\U0001F41B Bug report"
about: Report errors or unexpected behavior
title: 'Bug:'
labels: Bug
assignees: ''

---

<!-- 🟥🟥🟥 A few rules to keep in mind- 🟥🟥🟥
1. Please check if there is already an issue for the bug you are facing.
2. It would be best to create the issue in English language.
Expand All @@ -28,7 +30,7 @@ Steps to reproduce the behavior:
<!-- If applicable, add screenshots below this line to help explain your problem. -->

**OS Version:**
- Windows 10 Version: <!-- [e.g. Windows 10 20H2] -->
- Windows Version: <!-- [e.g. Windows 10 20H2] -->

**ModernFlyouts Version:**
- Version: <!-- [e.g. v0.9.1] -->
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
blank_issues_enabled: false
blank_issues_enabled: true
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/documentation-issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: "\U0001F4DA Documentation Issue"
about: Report issues in our documentation
title: ''
labels: ''
assignees: ''

---


Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
name: Feature request
name: "Feature request"
about: Suggest an idea for this app
title: 'Feature Request:'
labels: Enhancement
assignees: ''

---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: 'Language or Translation issue or request '
name: "\U0001F310 Localization/Translation issue"
about: Request support for a language or report incorrect translations
title: ''
labels: translation
labels: ''
assignees: Samuel12321

---
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<PropertyGroup>
<Authors>ModernFlyouts Community</Authors>
<LangVersion>latest</LangVersion>
<Version>0.9.3</Version>
<Version>0.10.0</Version>
</PropertyGroup>
</Project>
204 changes: 204 additions & 0 deletions ModernFlyouts.Core/Display/BrightnessController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
using System;
using System.Management;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using ModernFlyouts.Core.Interop;

namespace ModernFlyouts.Core.Display
{
public abstract class BrightnessController : ObservableObject, IDisposable
{
#region Properties

private DisplayMonitor associatedDisplayMonitor;

public DisplayMonitor AssociatedDisplayMonitor
{
get => associatedDisplayMonitor;
internal set => SetProperty(ref associatedDisplayMonitor, value);
}

private double minimum = 0.0;

public double Minimum
{
get => minimum;
protected set => SetProperty(ref minimum, value);
}

private double maximum = 100.0;

public double Maximum
{
get => maximum;
protected set => SetProperty(ref maximum, value);
}

private double brightness = 0.0;

public double Brightness
{
get => brightness;
set
{
value = Math.Min(Math.Max(minimum, value), maximum);
if (SetProperty(ref brightness, value))
{
SetBrightness(value);
}
}
}

#endregion

public BrightnessController()
{
Brightness = GetBrightness();
}

internal abstract double GetBrightness();

internal abstract void SetBrightness(double value);

internal void UpdateBrightness(double value)
{
value = Math.Min(Math.Max(minimum, value), maximum);
SetProperty(ref brightness, value, nameof(Brightness));
}

protected virtual void Dispose(bool disposing)
{
}

~BrightnessController()
{
Dispose(false);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}

public class MockBrightnessController : BrightnessController
{
internal override double GetBrightness()
{
return new Random().NextDouble() * 100.0;
}

internal override void SetBrightness(double value)
{
}
}

public class BuiltInDisplayBrightnessController : BrightnessController
{
internal BuiltInDisplayBrightnessController(byte[] levels)
{
Maximum = levels.Length - 1;
Minimum = levels[0];
}

internal override double GetBrightness()
{
try
{
var s = new ManagementScope("root\\WMI");
var q = new SelectQuery("WmiMonitorBrightness");
var mos = new ManagementObjectSearcher(s, q);
var moc = mos.Get();

foreach (var managementBaseObject in moc)
{
return Convert.ToDouble(managementBaseObject.GetPropertyValue("CurrentBrightness"));
}

moc.Dispose();
mos.Dispose();
}
catch { }

return 0.0;
}

internal override void SetBrightness(double value)
{
try
{
var s = new ManagementScope("root\\WMI");
var q = new SelectQuery("WmiMonitorBrightnessMethods");
var mos = new ManagementObjectSearcher(s, q);
var moc = mos.Get();

foreach (var managementBaseObject in moc)
{
var o = (ManagementObject)managementBaseObject;
o.InvokeMethod("WmiSetBrightness", new object[]
{
uint.MaxValue,
(int)Math.Truncate(value)
});
}

moc.Dispose();
mos.Dispose();
}
catch { }
}
}

public class ExternalDisplayBrightnessController : BrightnessController
{
private IntPtr hPhysicalMonitor;
private double currentValue;

internal ExternalDisplayBrightnessController(MonitorInfo info, DisplayMonitor displayMonitor)
{
Maximum = info.MaxValue;
Minimum = info.MinValue;
currentValue = info.CurrentValue;
hPhysicalMonitor = info.Handle;
Brightness = currentValue;

AssociatedDisplayMonitor = displayMonitor;
}

internal override double GetBrightness()
{
return currentValue;
}

internal override void SetBrightness(double value)
{
if (NativeMethods.SetMonitorBrightness(hPhysicalMonitor, (uint)Math.Truncate(value)))
{
currentValue = value;
}
}

private bool disposedValue;

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (!disposedValue)
{
AssociatedDisplayMonitor = null;
NativeMethods.DestroyPhysicalMonitor(hPhysicalMonitor);

disposedValue = true;
}
}
}

internal class MonitorInfo
{
public uint MinValue { get; set; }
public uint MaxValue { get; set; }
public IntPtr Handle { get; set; }
public uint CurrentValue { get; set; }
}
}
Loading

0 comments on commit 0504f6d

Please sign in to comment.