8000 g-helper/app/Settings.cs at eco_toggle · AIahmedshrf/g-helper · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
2111 lines (1705 loc) · 72.3 KB

Settings.cs

File metadata and controls

2111 lines (1705 loc) · 72.3 KB
using GHelper.Ally;
using GHelper.AnimeMatrix;
using GHelper.AutoUpdate;
using GHelper.Battery;
using GHelper.Display;
using GHelper.Fan;
using GHelper.Gpu;
using GHelper.Helpers;
using GHelper.Input;
using GHelper.Mode;
using GHelper.Peripherals;
using GHelper.Peripherals.Mouse;
using GHelper.Properties;
using GHelper.UI;
using GHelper.USB;
using System.Diagnostics;
using System.Timers;
namespace GHelper
{
public partial class SettingsForm : RForm
{
ContextMenuStrip contextMenuStrip = new CustomContextMenu();
ToolStripMenuItem menuEco, menuStandard, menuUltimate, menuOptimized;
DonateControl donateControl;
public GPUModeControl gpuControl;
public AllyControl allyControl;
AutoUpdateControl updateControl;
AsusMouseSettings? mouseSettings;
public AniMatrixControl matrixControl;
public static System.Timers.Timer sensorTimer = default!;
public Matrix? matrixForm;
public Fans? fansForm;
public Extra? extraForm;
public Updates? updatesForm;
public Handheld? handheldForm;
static long lastRefresh;
static long lastBatteryRefresh;
static long lastLostFocus;
bool isGpuSection = true;
bool batteryMouseOver = false;
bool batteryFullMouseOver = false;
bool sliderGammaIgnore = false;
bool activateCheck = false;
public SettingsForm()
{
InitializeComponent();
InitTheme(true);
gpuControl = new GPUModeControl(this);
updateControl = new AutoUpdateControl(this);
matrixControl = new AniMatrixControl(this);
allyControl = new AllyControl(this);
buttonSilent.Text = Properties.Strings.Silent;
buttonBalanced.Text = Properties.Strings.Balanced;
buttonTurbo.Text = Properties.Strings.Turbo;
buttonFans.Text = Properties.Strings.FansPower;
buttonEco.Text = Properties.Strings.EcoMode;
buttonUltimate.Text = Properties.Strings.UltimateMode;
8000
buttonStandard.Text = Properties.Strings.StandardMode;
buttonOptimized.Text = Properties.Strings.Optimized;
buttonStopGPU.Text = Properties.Strings.StopGPUApps;
buttonScreenAuto.Text = Properties.Strings.AutoMode;
buttonMiniled.Text = Properties.Strings.Multizone;
buttonKeyboardColor.Text = Properties.Strings.Color;
buttonKeyboard.Text = Properties.Strings.Extra;
labelPerf.Text = Properties.Strings.PerformanceMode;
labelGPU.Text = Properties.Strings.GPUMode;
labelSreen.Text = Properties.Strings.LaptopScreen;
labelKeyboard.Text = Properties.Strings.LaptopKeyboard;
labelMatrix.Text = Properties.Strings.AnimeMatrix;
labelBatteryTitle.Text = Properties.Strings.BatteryChargeLimit;
checkMatrix.Text = Properties.Strings.TurnOffOnBattery;
checkMatrixLid.Text = Properties.Strings.DisableOnLidClose;
checkStartup.Text = Properties.Strings.RunOnStartup;
buttonMatrix.Text = Properties.Strings.PictureGif;
buttonQuit.Text = Properties.Strings.Quit;
buttonUpdates.Text = Properties.Strings.Updates;
buttonDonate.Text = Properties.Strings.Donate;
buttonController.Text = Properties.Strings.Controller;
labelAlly.Text = Properties.Strings.AllyController;
// Accessible Labels
panelMatrix.AccessibleName = Properties.Strings.AnimeMatrix;
sliderBattery.AccessibleName = Properties.Strings.BatteryChargeLimit;
buttonQuit.AccessibleName = Properties.Strings.Quit;
buttonUpdates.AccessibleName = Properties.Strings.BiosAndDriverUpdates;
panelPerformance.AccessibleName = Properties.Strings.PerformanceMode;
buttonSilent.AccessibleName = Properties.Strings.Silent;
buttonBalanced.AccessibleName = Properties.Strings.Balanced;
buttonTurbo.AccessibleName = Properties.Strings.Turbo;
buttonFans.AccessibleName = Properties.Strings.FansAndPower;
panelGPU.AccessibleName = Properties.Strings.GPUMode;
buttonEco.AccessibleName = Properties.Strings.EcoMode;
buttonStandard.AccessibleName = Properties.Strings.StandardMode;
buttonOptimized.AccessibleName = Properties.Strings.Optimized;
buttonUltimate.AccessibleName = Properties.Strings.UltimateMode;
panelScreen.AccessibleName = Properties.Strings.LaptopScreen;
buttonScreenAuto.AccessibleName = Properties.Strings.AutoMode;
//button60Hz.AccessibleName = "60Hz Refresh Rate";
//button120Hz.AccessibleName = "Maximum Refresh Rate";
panelKeyboard.AccessibleName = Properties.Strings.LaptopKeyboard;
buttonKeyboard.AccessibleName = Properties.Strings.ExtraSettings;
buttonKeyboardColor.AccessibleName = Properties.Strings.LaptopKeyboard + " " + Properties.Strings.Color;
comboKeyboard.AccessibleName = Properties.Strings.LaptopBacklight;
FormClosing += SettingsForm_FormClosing;
Deactivate += SettingsForm_LostFocus;
Activated += SettingsForm_Focused;
buttonSilent.BorderColor = colorEco;
buttonBalanced.BorderColor = colorStandard;
buttonTurbo.BorderColor = colorTurbo;
buttonFans.BorderColor = colorCustom;
buttonEco.BorderColor = colorEco;
buttonStandard.BorderColor = colorStandard;
buttonUltimate.BorderColor = colorTurbo;
buttonOptimized.BorderColor = colorEco;
buttonXGM.BorderColor = colorTurbo;
button60Hz.BorderColor = colorGray;
button120Hz.BorderColor = colorGray;
buttonScreenAuto.BorderColor = colorGray;
buttonMiniled.BorderColor = colorTurbo;
buttonEnergySaver.BackColor = colorEco;
buttonEnergySaver.ForeColor = SystemColors.ControlLightLight;
buttonEnergySaver.Click += ButtonEnergySaver_Click;
buttonAmdOled.BackColor = colorTurbo;
buttonAmdOled.ForeColor = SystemColors.ControlLightLight;
buttonAmdOled.Click += ButtonAmdOled_Click;
buttonArmoury.BackColor = colorTurbo;
buttonArmoury.ForeColor = SystemColors.ControlLightLight;
buttonArmoury.Click += ButtonArmoury_Click;
buttonSilent.Click += ButtonSilent_Click;
buttonBalanced.Click += ButtonBalanced_Click;
buttonTurbo.Click += ButtonTurbo_Click;
buttonEco.Click += ButtonEco_Click;
buttonStandard.Click += ButtonStandard_Click;
buttonUltimate.Click += ButtonUltimate_Click;
buttonOptimized.Click += ButtonOptimized_Click;
buttonStopGPU.Click += ButtonStopGPU_Click;
VisibleChanged += SettingsForm_VisibleChanged;
button60Hz.Click += Button60Hz_Click;
button120Hz.Click += Button120Hz_Click;
buttonScreenAuto.Click += ButtonScreenAuto_Click;
buttonMiniled.Click += ButtonMiniled_Click;
buttonFHD.Click += ButtonFHD_Click;
buttonHDRControl.Click += ButtonHDRControl_Click;
buttonQuit.Click += ButtonQuit_Click;
buttonKeyboardColor.Click += ButtonKeyboardColor_Click;
buttonFans.Click += ButtonFans_Click;
buttonKeyboard.Click += ButtonKeyboard_Click;
buttonController.Click += ButtonHandheld_Click;
pictureColor.Click += PictureColor_Click;
pictureColor2.Click += PictureColor2_Click;
labelCPUFan.Click += LabelCPUFan_Click;
labelGPUFan.Click += LabelCPUFan_Click;
comboMatrix.DropDownStyle = ComboBoxStyle.DropDownList;
comboMatrixRunning.DropDownStyle = ComboBoxStyle.DropDownList;
comboInterval.DropDownStyle = ComboBoxStyle.DropDownList;
comboMatrix.DropDownClosed += ComboMatrix_SelectedValueChanged;
comboMatrixRunning.DropDownClosed += ComboMatrixRunning_SelectedValueChanged;
comboInterval.DropDownClosed += ComboInterval_DropDownClosed;
buttonMatrix.Click += ButtonMatrix_Click;
checkStartup.Checked = Startup.IsScheduled();
checkStartup.CheckedChanged += CheckStartup_CheckedChanged;
labelVersion.Click += LabelVersion_Click;
labelVersion.ForeColor = Color.FromArgb(128, Color.Gray);
buttonOptimized.MouseMove += ButtonOptimized_MouseHover;
buttonOptimized.MouseLeave += ButtonGPU_MouseLeave;
buttonEco.MouseMove += ButtonEco_MouseHover;
buttonEco.MouseLeave += ButtonGPU_MouseLeave;
buttonStandard.MouseMove += ButtonStandard_MouseHover;
buttonStandard.MouseLeave += ButtonGPU_MouseLeave;
buttonUltimate.MouseMove += ButtonUltimate_MouseHover;
buttonUltimate.MouseLeave += ButtonGPU_MouseLeave;
tableGPU.MouseMove += ButtonXGM_MouseMove;
tableGPU.MouseLeave += ButtonGPU_MouseLeave;
buttonXGM.Click += ButtonXGM_Click;
buttonScreenAuto.MouseMove += ButtonScreenAuto_MouseHover;
buttonScreenAuto.MouseLeave += ButtonScreen_MouseLeave;
button60Hz.MouseMove += Button60Hz_MouseHover;
button60Hz.MouseLeave += ButtonScreen_MouseLeave;
button120Hz.MouseMove += Button120Hz_MouseHover;
button120Hz.MouseLeave += ButtonScreen_MouseLeave;
buttonFHD.MouseMove += ButtonFHD_MouseHover;
buttonFHD.MouseLeave += ButtonScreen_MouseLeave;
buttonUpdates.Click += ButtonUpdates_Click;
sliderBattery.MouseUp += SliderBattery_MouseUp;
sliderBattery.KeyUp += SliderBattery_KeyUp;
sliderBattery.ValueChanged += SliderBattery_ValueChanged;
sensorTimer = new System.Timers.Timer(AppConfig.Get("sensor_timer", 1000));
sensorTimer.Elapsed += OnTimedEvent;
sensorTimer.Enabled = false;
labelCharge.MouseEnter += PanelBattery_MouseEnter;
labelCharge.MouseLeave += PanelBattery_MouseLeave;
labelBattery.Click += LabelBattery_Click;
buttonPeripheral1.Click += ButtonPeripheral_Click;
buttonPeripheral2.Click += ButtonPeripheral_Click;
buttonPeripheral3.Click += ButtonPeripheral_Click;
buttonPeripheral1.MouseEnter += ButtonPeripheral_MouseEnter;
buttonPeripheral2.MouseEnter += ButtonPeripheral_MouseEnter;
buttonPeripheral3.MouseEnter += ButtonPeripheral_MouseEnter;
buttonBatteryFull.MouseEnter += ButtonBatteryFull_MouseEnter;
buttonBatteryFull.MouseLeave += ButtonBatteryFull_MouseLeave;
buttonBatteryFull.Click += ButtonBatteryFull_Click;
buttonControllerMode.Click += ButtonControllerMode_Click;
buttonBacklight.Click += ButtonBacklight_Click;
buttonFPS.Click += ButtonFPS_Click;
buttonOverlay.Click += ButtonOverlay_Click;
buttonAutoTDP.Click += ButtonAutoTDP_Click;
buttonAutoTDP.BorderColor = colorTurbo;
Text = "G-Helper " + (ProcessHelper.IsUserAdministrator() ? "—" : "-") + " " + AppConfig.GetModelShort();
TopMost = AppConfig.Is("topmost");
//This will auto position the window again when it resizes. Might mess with position if people drag the window somewhere else.
this.Resize += SettingsForm_Resize;
VisualiseFnLock();
buttonFnLock.Click += ButtonFnLock_Click;
labelVisual.Click += LabelVisual_Click;
labelCharge.Click += LabelCharge_Click;
donateControl = new DonateControl(this, buttonDonate);
donateControl.Init();
labelBacklight.ForeColor = colorStandard;
labelBacklight.Click += LabelBacklight_Click;
panelPerformance.Focus();
InitVisual();
}
private void ButtonArmoury_Click(object? sender, EventArgs e)
{
var dialogResult = MessageBox.Show(this, "Armoury Crate is active, download official uninstaller app?", "Armoury Crate", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes) AsusService.RunArmouryUninstaller();
}
private void ButtonAmdOled_Click(object? sender, EventArgs e)
{
AmdDisplay.RunAdrenaline();
activateCheck = true;
}
private void LabelBattery_Click(object? sender, EventArgs e)
{
HardwareControl.chargeWatt = !HardwareControl.chargeWatt;
RefreshSensors(true);
}
private void ButtonEnergySaver_Click(object? sender, EventArgs e)
{
KeyboardHook.KeyKeyPress(Keys.LWin, Keys.A);
activateCheck = true;
}
private void LabelBacklight_Click(object? sender, EventArgs e)
{
if (AppConfig.IsDynamicLighting() && DynamicLightingHelper.IsEnabled()) DynamicLightingHelper.OpenSettings();
}
private void ButtonFHD_Click(object? sender, EventArgs e)
{
ScreenControl.ToogleFHD();
}
private void ButtonHDRControl_Click(object? sender, EventArgs e)
{
ScreenControl.ToogleHDRControl();
}
private void SliderBattery_ValueChanged(object? sender, EventArgs e)
{
VisualiseBatteryTitle(sliderBattery.Value);
}
private void SliderBattery_KeyUp(object? sender, KeyEventArgs e)
{
BatteryControl.SetBatteryChargeLimit(sliderBattery.Value);
}
private void SliderBattery_MouseUp(object? sender, MouseEventArgs e)
{
BatteryControl.SetBatteryChargeLimit(sliderBattery.Value);
}
private void ButtonAutoTDP_Click(object? sender, EventArgs e)
{
allyControl.ToggleAutoTDP();
}
private void LabelCharge_Click(object? sender, EventArgs e)
{
BatteryControl.BatteryReport();
}
private void LabelVisual_Click(object? sender, EventArgs e)
{
labelVisual.Visible = false;
VisualControl.forceVisual = true;
}
public void InitVisual()
{
if (AppConfig.Is("hide_visual")) return;
if (AppConfig.IsOLED())
{
panelGamma.Visible = true;
sliderGamma.Visible = true;
labelGammaTitle.Text = Properties.Strings.FlickerFreeDimming + " / " + Properties.Strings.VisualMode;
VisualiseBrightness();
sliderGamma.ValueChanged += SliderGamma_ValueChanged;
sliderGamma.MouseUp += SliderGamma_ValueChanged;
}
else
{
labelGammaTitle.Text = Properties.Strings.VisualMode;
}
var gamuts = VisualControl.GetGamutModes();
// Color profiles exist
if (gamuts.Count > 0)
{
tableVisual.ColumnCount = 3;
buttonInstallColor.Visible = false;
}
else
{
// If it's possible to retrieve color profiles
if (ColorProfileHelper.ProfileExists())
{
tableVisual.ColumnCount = 2;
buttonInstallColor.Text = Properties.Strings.DownloadColorProfiles;
buttonInstallColor.Visible = true;
buttonInstallColor.Click += ButtonInstallColorProfile_Click;
panelGamma.Visible = true;
tableVisual.Visible = true;
}
return;
}
panelGamma.Visible = true;
tableVisual.Visible = true;
var visualValue = (SplendidCommand)AppConfig.Get("visual", (int)VisualControl.GetDefaultVisualMode());
var colorTempValue = AppConfig.Get("color_temp", VisualControl.DefaultColorTemp);
comboVisual.DropDownStyle = ComboBoxStyle.DropDownList;
comboVisual.DataSource = new BindingSource(VisualControl.GetVisualModes(), null);
comboVisual.DisplayMember = "Value";
comboVisual.ValueMember = "Key";
comboVisual.SelectedValue = visualValue;
comboColorTemp.DropDownStyle = ComboBoxStyle.DropDownList;
comboColorTemp.DataSource = new BindingSource(VisualControl.GetTemperatures(), null);
comboColorTemp.DisplayMember = "Value";
comboColorTemp.ValueMember = "Key";
comboColorTemp.SelectedValue = colorTempValue;
VisualControl.SetVisual(visualValue, colorTempValue, true);
comboVisual.SelectedValueChanged += ComboVisual_SelectedValueChanged;
comboVisual.Visible = true;
VisualiseDisabled();
comboColorTemp.SelectedValueChanged += ComboVisual_SelectedValueChanged;
comboColorTemp.Visible = true;
if (gamuts.Count <= 1) return;
comboGamut.DropDownStyle = ComboBoxStyle.DropDownList;
comboGamut.DataSource = new BindingSource(gamuts, null);
comboGamut.DisplayMember = "Value";
comboGamut.ValueMember = "Key";
comboGamut.SelectedValue = (SplendidGamut)AppConfig.Get("gamut", (int)VisualControl.GetDefaultGamut());
comboGamut.SelectedValueChanged += ComboGamut_SelectedValueChanged;
comboGamut.Visible = true;
}
public void CycleVisualMode(int delta)
{
if (comboVisual.Items.Count < 1) return;
if (delta > 0)
{
if (comboVisual.SelectedIndex < comboVisual.Items.Count - 1)
comboVisual.SelectedIndex += 1;
else
comboVisual.SelectedIndex = 0;
}
else
{
if (comboVisual.SelectedIndex > 0)
comboVisual.SelectedIndex -= 1;
else
comboVisual.SelectedIndex = comboVisual.Items.Count - 1;
}
Program.toast.RunToast(comboVisual.GetItemText(comboVisual.SelectedItem), ToastIcon.BrightnessUp);
}
private async void ButtonInstallColorProfile_Click(object? sender, EventArgs e)
{
await ColorProfileHelper.InstallProfile();
InitVisual();
}
private void ComboGamut_SelectedValueChanged(object? sender, EventArgs e)
{
VisualControl.SetGamut((int)comboGamut.SelectedValue);
}
private void ComboVisual_SelectedValueChanged(object? sender, EventArgs e)
{
VisualControl.SetVisual((SplendidCommand)comboVisual.SelectedValue, (int)comboColorTemp.SelectedValue);
VisualiseDisabled();
}
public void VisualiseBrightness()
{
Invoke(delegate
{
sliderGammaIgnore = true;
sliderGamma.Value = VisualControl.GetBrightness();
labelGamma.Text = sliderGamma.Value + "%";
sliderGammaIgnore = false;
});
}
public void VisualiseAmdOled(bool status = false)
{
Invoke(delegate
{
buttonAmdOled.Visible = status;
});
}
public void VisualiseArmoury(bool status = false)
{
Invoke(delegate
{
buttonArmoury.Visible = status;
});
}
public void VisualiseDisabled()
{
comboGamut.Enabled = comboColorTemp.Enabled = (SplendidCommand)AppConfig.Get("visual") != SplendidCommand.Disabled;
}
public void VisualiseGamut()
{
Invoke(delegate
{
if (comboGamut.Items.Count > 0) comboGamut.SelectedIndex = 0;
});
}
private void SliderGamma_ValueChanged(object? sender, EventArgs e)
{
if (sliderGammaIgnore) return;
VisualControl.SetBrightness(sliderGamma.Value);
}
private void ButtonOverlay_Click(object? sender, EventArgs e)
{
KeyboardHook.KeyKeyKeyPress(Keys.LControlKey, Keys.LShiftKey, Keys.O);
}
private void ButtonHandheld_Click(object? sender, EventArgs e)
{
if (handheldForm == null || handheldForm.Text == "")
{
handheldForm = new Handheld();
AddOwnedForm(handheldForm);
}
if (handheldForm.Visible)
{
handheldForm.Close();
}
else
{
//handheldForm.FormPosition();
handheldForm.Show();
}
}
private void ButtonFPS_Click(object? sender, EventArgs e)
{
allyControl.ToggleFPSLimit();
}
private void ButtonBacklight_Click(object? sender, EventArgs e)
{
allyControl.ToggleBacklight();
}
private void ButtonControllerMode_Click(object? sender, EventArgs e)
{
allyControl.ToggleMode();
}
public void VisualiseAlly(bool visible = false)
{
if (!visible) return;
panelAlly.Visible = true;
panelKeyboardTitle.Visible = false;
panelKeyboard.Padding = new Paddin 10BC8 g(panelKeyboard.Padding.Left, 0, panelKeyboard.Padding.Right, panelKeyboard.Padding.Bottom);
tableAMD.Visible = true;
}
public void VisualiseController(ControllerMode mode)
{
switch (mode)
{
case ControllerMode.Gamepad:
buttonControllerMode.Text = "Gamepad";
break;
case ControllerMode.Mouse:
buttonControllerMode.Text = "Mouse";
break;
case ControllerMode.Skip:
buttonControllerMode.Text = "Skip";
break;
default:
buttonControllerMode.Text = "Auto";
break;
}
}
public void VisualiseBacklight(int backlight)
{
buttonBacklight.Text = Math.Round((double)backlight * 33.33).ToString() + "%";
}
public void VisualiseFPSLimit(int limit)
{
buttonFPS.Text = "FPS Limit " + ((limit > 0 && limit <= 120) ? limit : "OFF");
}
public void VisualiseAutoTDP(bool status)
{
Logger.WriteLine($"Auto TDP: {status}");
buttonAutoTDP.Activated = status;
}
private void SettingsForm_Focused(object? sender, EventArgs e)
{
if (activateCheck)
{
buttonEnergySaver.Visible = PowerNative.GetBatterySaverStatus();
buttonAmdOled.Visible = AmdDisplay.IsOledPowerOptimization();
activateCheck = false;
}
}
private void SettingsForm_LostFocus(object? sender, EventArgs e)
{
lastLostFocus = DateTimeOffset.Now.ToUnixTimeMilliseconds();
}
private void ButtonBatteryFull_Click(object? sender, EventArgs e)
{
BatteryControl.ToggleBatteryLimitFull();
}
private void ButtonBatteryFull_MouseLeave(object? sender, EventArgs e)
{
batteryFullMouseOver = false;
RefreshSensors(true);
}
private void ButtonBatteryFull_MouseEnter(object? sender, EventArgs e)
{
batteryFullMouseOver = true;
labelCharge.Text = Properties.Strings.BatteryLimitFull;
}
private void SettingsForm_Resize(object? sender, EventArgs e)
{
Left = Screen.FromControl(this).WorkingArea.Width - 10 - Width;
Top = Screen.FromControl(this).WorkingArea.Height - 10 - Height;
}
private void PanelBattery_MouseEnter(object? sender, EventArgs e)
{
batteryMouseOver = true;
ShowBatteryWear();
}
private void PanelBattery_MouseLeave(object? sender, EventArgs e)
{
batteryMouseOver = false;
RefreshSensors(true);
}
private void ShowBatteryWear()
{
//Refresh again only after 15 Minutes since the last refresh
if (lastBatteryRefresh == 0 || Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastBatteryRefresh) > 15 * 60_000)
{
lastBatteryRefresh = DateTimeOffset.Now.ToUnixTimeMilliseconds();
HardwareControl.RefreshBatteryHealth();
}
if (HardwareControl.batteryHealth != -1)
{
labelCharge.Text = Properties.Strings.BatteryHealth + ": " + Math.Round(HardwareControl.batteryHealth, 1) + "%";
}
}
private void SettingsForm_VisibleChanged(object? sender, EventArgs e)
{
sensorTimer.Enabled = this.Visible;
if (this.Visible)
{
ScreenControl.InitScreen();
VisualizeXGM();
buttonEnergySaver.Visible = PowerNative.GetBatterySaverStatus();
Task.Run((Action)RefreshPeripheralsBattery);
updateControl.CheckForUpdates();
}
}
private void RefreshPeripheralsBattery()
{
PeripheralsProvider.RefreshBatteryForAllDevices(true);
}
private void ButtonUpdates_Click(object? sender, EventArgs e)
{
if (updatesForm == null || updatesForm.Text == "")
{
updatesForm = new Updates();
AddOwnedForm(updatesForm);
}
if (updatesForm.Visible)
{
updatesForm.Close();
}
else
{
updatesForm.Show();
}
}
public void VisualiseMatrixPicture(string image)
{
if (matrixForm == null || matrixForm.Text == "") return;
matrixForm.VisualiseMatrix(image);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == NativeMethods.WM_POWERBROADCAST && m.WParam == (IntPtr)NativeMethods.PBT_POWERSETTINGCHANGE)
{
var settings = (NativeMethods.POWERBROADCAST_SETTING)m.GetLParam(typeof(NativeMethods.POWERBROADCAST_SETTING));
if (settings.PowerSetting == NativeMethods.PowerSettingGuid.LIDSWITCH_STATE_CHANGE)
{
switch (settings.Data)
{
case 0:
Logger.WriteLine("Lid Closed");
InputDispatcher.lidClose = AniMatrixControl.lidClose = true;
Aura.ApplyBrightness(0, "Lid");
matrixControl.SetLidMode();
break;
case 1:
Logger.WriteLine("Lid Open");
InputDispatcher.InitFNLock();
InputDispatcher.lidClose = AniMatrixControl.lidClose = false;
Aura.ApplyBrightness(InputDispatcher.GetBacklight(), "Lid");
matrixControl.SetLidMode();
break;
}
}
else
{
switch (settings.Data)
{
case 0:
Logger.WriteLine("Monitor Power Off");
Aura.SleepBrightness();
Program.modeControl.SleepReset();
break;
case 1:
Logger.WriteLine("Monitor Power On");
if (!Program.SetAutoModes(wakeup: true)) BatteryControl.AutoBattery();
break;
case 2:
Logger.WriteLine("Monitor Dimmed");
break;
}
}
m.Result = (IntPtr)1;
}
if (m.Msg == Program.WM_TASKBARCREATED)
{
Logger.WriteLine("Taskbar created, re-creating tray icon");
if (Program.trayIcon is not null) Program.trayIcon.Visible = true;
}
try
{
base.WndProc(ref m);
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
public void SetContextMenu()
{
var currentMode = Modes.GetCurrent();
foreach (ToolStripItem item in contextMenuStrip.Items.Cast<ToolStripItem>().ToList())
{
if (item is ToolStripMenuItem menuItem) menuItem.Dispose();
}
contextMenuStrip.Items.Clear();
contextMenuStrip.ShowCheckMargin = true;
contextMenuStrip.ImageScalingSize = new Size(16, 16);
contextMenuStrip.ShowImageMargin = false;
Padding padding = new Padding(5, 5, 5, 5);
var title = new ToolStripMenuItem(Properties.Strings.PerformanceMode);
title.Margin = padding;
title.Enabled = false;
contextMenuStrip.Items.Add(title);
foreach (var mode in Modes.GetDictonary())
{
var menuMode = new ToolStripMenuItem(mode.Value);
menuMode.Tag = mode.Key;
menuMode.Click += (sender, args) => { Program.modeControl.SetPerformanceMode(mode.Key); };
menuMode.Margin = padding;
menuMode.Checked = (mode.Key == currentMode);
contextMenuStrip.Items.Add(menuMode);
}
contextMenuStrip.Items.Add("-");
if (isGpuSection)
{
var titleGPU = new ToolStripMenuItem(Properties.Strings.GPUMode);
titleGPU.Margin = padding;
titleGPU.Enabled = false;
contextMenuStrip.Items.Add(titleGPU);
menuEco = new ToolStripMenuItem(Properties.Strings.EcoMode);
menuEco.Click += ButtonEco_Click;
menuEco.Margin = padding;
contextMenuStrip.Items.Add(menuEco);
menuStandard = new ToolStripMenuItem(Properties.Strings.StandardMode);
menuStandard.Click += ButtonStandard_Click;
menuStandard.Margin = padding;
contextMenuStrip.Items.Add(menuStandard);
menuUltimate = new ToolStripMenuItem(Properties.Strings.UltimateMode);
menuUltimate.Click += ButtonUltimate_Click;
menuUltimate.Margin = padding;
contextMenuStrip.Items.Add(menuUltimate);
menuOptimized = new ToolStripMenuItem(Properties.Strings.Optimized);
menuOptimized.Click += ButtonOptimized_Click;
menuOptimized.Margin = padding;
contextMenuStrip.Items.Add(menuOptimized);
contextMenuStrip.Items.Add("-");
}
var quit = new ToolStripMenuItem(Properties.Strings.Quit);
quit.Click += ButtonQuit_Click;
quit.Margin = padding;
contextMenuStrip.Items.Add(quit);
//contextMenuStrip.ShowCheckMargin = true;
contextMenuStrip.Renderer = new CustomMenuRenderer();
InitContextMenuTheme();
if (Program.trayIcon is not null) Program.trayIcon.ContextMenuStrip = contextMenuStrip;
}
public void InitContextMenuTheme()
{
if (contextMenuStrip is not null)
{
contextMenuStrip.BackColor = this.BackColor;
contextMenuStrip.ForeColor = this.ForeColor;
}
donateControl?.ApplyTheme();
}
private void ButtonXGM_Click(object? sender, EventArgs e)
{
gpuControl.ToggleXGM();
}
public void SetVersionLabel(string label, bool update = false)
{
if (InvokeRequired)
Invoke(delegate
{
labelVersion.Text = label;
if (update) labelVersion.ForeColor = colorTurbo;
});
else
{
labelVersion.Text = label;
if (update) labelVersion.ForeColor = colorTurbo;
}
}
private void LabelVersion_Click(object? sender, EventArgs e)
{
updateControl.Update();
}
private static void OnTimedEvent(Object? source, ElapsedEventArgs? e)
{
Program.settingsForm.RefreshSensors();
}
private void ButtonFHD_MouseHover(object? sender, EventArgs e)
{
labelTipScreen.Text = "Switch to " + ((buttonFHD.Text == "FHD") ? "UHD" : "FHD") + " Mode";
}
private void Button120Hz_MouseHover(object? sender, EventArgs e)
{
labelTipScreen.Text = Properties.Strings.MaxRefreshTooltip;
}
private void Button60Hz_MouseHover(object? sender, EventArgs e)
{
labelTipScreen.Text = Properties.Strings.MinRefreshTooltip.Replace("60", ScreenControl.MIN_RATE.ToString());
}
private void ButtonScreen_MouseLeave(object? sender, EventArgs e)
{
labelTipScreen.Text = "";
}
private void ButtonScreenAuto_MouseHover(object? sender, EventArgs e)
{
labelTipScreen.Text = Properties.Strings.AutoRefreshTooltip.Replace("60", ScreenControl.MIN_RATE.ToString());
}
private void ButtonUltimate_MouseHover(object? sender, EventArgs e)
{
labelTipGPU.Text = Properties.Strings.UltimateGPUTooltip;
}
private void ButtonStandard_MouseHover(object? sender, EventArgs e)
{
labelTipGPU.Text = Properties.Strings.StandardGPUTooltip;
}
private void ButtonEco_MouseHover(object? sender, EventArgs e)
{
labelTipGPU.Text = Properties.Strings.EcoGPUTooltip;
}
private void ButtonOptimized_MouseHover(object? sender, EventArgs e)
{
labelTipGPU.Text = Properties.Strings.OptimizedGPUTooltip;
}
private void ButtonGPU_MouseLeave(object? sender, EventArgs e)
{
labelTipGPU.Text = "";
}
private void ButtonXGM_MouseMove(object? sender, MouseEventArgs e)
{
if (sender is null) return;
TableLayoutPanel table = (TableLayoutPanel)sender;
if (!buttonXGM.Visible) return;
labelTipGPU.Text = buttonXGM.Bounds.Contains(table.PointToClient(Cursor.Position)) ?
"XGMobile toggle works only in Standard mode" : "";
}
private void ButtonScreenAuto_Click(object? sender, EventArgs e)
{
ScreenControl.SetAutoRefresh(1);
ScreenControl.AutoScreen();
}
private void CheckStartup_CheckedChanged(object? sender, EventArgs e)
{
if (sender is null) return;
CheckBox chk = (CheckBox)sender;
if (chk.Checked)
Startup.Schedule();
else
Startup.UnSchedule();
}
private void CheckMatrix_CheckedChanged(object? sender, EventArgs e)
{
AppConfig.Set("matrix_auto", checkMatrix.Checked ? 1 : 0);
matrixControl.SetBatteryAuto();
0