mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Context menu
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using WinFormsSliderBar;
|
using WinFormsSliderBar;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using System.Windows.Forms.DataVisualization.Charting;
|
using System.Windows.Forms.DataVisualization.Charting;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
public static class ControlHelper
|
public static class ControlHelper
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace GHelper
|
|||||||
{"screenshot", Properties.Strings.PrintScreen},
|
{"screenshot", Properties.Strings.PrintScreen},
|
||||||
{"play", Properties.Strings.PlayPause},
|
{"play", Properties.Strings.PlayPause},
|
||||||
{"aura", Properties.Strings.ToggleAura},
|
{"aura", Properties.Strings.ToggleAura},
|
||||||
{"ghelper", Properties.Strings.OpenGHelper},
|
{"performance", Properties.Strings.PerformanceMode},
|
||||||
{"screen", Properties.Strings.ToggleScreen},
|
{"screen", Properties.Strings.ToggleScreen},
|
||||||
{"miniled", Properties.Strings.ToggleMiniled},
|
{"miniled", Properties.Strings.ToggleMiniled},
|
||||||
{"custom", Properties.Strings.Custom}
|
{"custom", Properties.Strings.Custom}
|
||||||
@@ -22,7 +22,7 @@ namespace GHelper
|
|||||||
private void SetKeyCombo(ComboBox combo, TextBox txbox, string name)
|
private void SetKeyCombo(ComboBox combo, TextBox txbox, string name)
|
||||||
{
|
{
|
||||||
if (name == "m4")
|
if (name == "m4")
|
||||||
customActions[""] = Properties.Strings.PerformanceMode;
|
customActions[""] = Properties.Strings.OpenGHelper;
|
||||||
|
|
||||||
if (name == "fnf4")
|
if (name == "fnf4")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ namespace GHelper
|
|||||||
|
|
||||||
//labelInfo.MaximumSize = new Size(280, 0);
|
//labelInfo.MaximumSize = new Size(280, 0);
|
||||||
labelInfo.Text = Properties.Strings.PPTExperimental;
|
labelInfo.Text = Properties.Strings.PPTExperimental;
|
||||||
|
labelFansResult.Visible = false;
|
||||||
|
|
||||||
InitFans();
|
InitFans();
|
||||||
InitPower();
|
InitPower();
|
||||||
@@ -283,7 +284,7 @@ namespace GHelper
|
|||||||
public void LabelFansResult(string text)
|
public void LabelFansResult(string text)
|
||||||
{
|
{
|
||||||
labelFansResult.Text = text;
|
labelFansResult.Text = text;
|
||||||
labelFansResult.Visible = (text.Length == 0);
|
labelFansResult.Visible = (text.Length > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Fans_FormClosing(object? sender, FormClosingEventArgs e)
|
private void Fans_FormClosing(object? sender, FormClosingEventArgs e)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
||||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||||
<AssemblyVersion>0.56</AssemblyVersion>
|
<AssemblyVersion>0.57</AssemblyVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
|||||||
@@ -3,11 +3,44 @@ using System.Diagnostics;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Management;
|
using System.Management;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
|
using System.Windows.Forms;
|
||||||
using Tools;
|
using Tools;
|
||||||
|
|
||||||
namespace GHelper
|
namespace GHelper
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class CustomContextMenu : ContextMenuStrip
|
||||||
|
{
|
||||||
|
[DllImport("dwmapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||||
|
private static extern long DwmSetWindowAttribute(IntPtr hwnd,
|
||||||
|
DWMWINDOWATTRIBUTE attribute,
|
||||||
|
ref DWM_WINDOW_CORNER_PREFERENCE pvAttribute,
|
||||||
|
uint cbAttribute);
|
||||||
|
|
||||||
|
public CustomContextMenu()
|
||||||
|
{
|
||||||
|
var preference = DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_ROUNDSMALL; //change as you want
|
||||||
|
DwmSetWindowAttribute(Handle,
|
||||||
|
DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE,
|
||||||
|
ref preference,
|
||||||
|
sizeof(uint));
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum DWMWINDOWATTRIBUTE
|
||||||
|
{
|
||||||
|
DWMWA_WINDOW_CORNER_PREFERENCE = 33
|
||||||
|
}
|
||||||
|
public enum DWM_WINDOW_CORNER_PREFERENCE
|
||||||
|
{
|
||||||
|
DWMWA_DEFAULT = 0,
|
||||||
|
DWMWCP_DONOTROUND = 1,
|
||||||
|
DWMWCP_ROUND = 2,
|
||||||
|
DWMWCP_ROUNDSMALL = 3,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
public static NotifyIcon trayIcon = new NotifyIcon
|
public static NotifyIcon trayIcon = new NotifyIcon
|
||||||
@@ -145,7 +178,6 @@ namespace GHelper
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
|
static void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -173,7 +205,7 @@ namespace GHelper
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void SetAutoModes(bool monitor = true)
|
public static void SetAutoModes()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastAuto) < 3000) return;
|
if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastAuto) < 3000) return;
|
||||||
@@ -185,8 +217,7 @@ namespace GHelper
|
|||||||
settingsForm.SetBatteryChargeLimit(config.getConfig("charge_limit"));
|
settingsForm.SetBatteryChargeLimit(config.getConfig("charge_limit"));
|
||||||
settingsForm.AutoPerformance();
|
settingsForm.AutoPerformance();
|
||||||
|
|
||||||
bool switched = false;
|
bool switched = settingsForm.AutoGPUMode();
|
||||||
if (monitor) switched = settingsForm.AutoGPUMode();
|
|
||||||
|
|
||||||
if (!switched)
|
if (!switched)
|
||||||
{
|
{
|
||||||
@@ -253,7 +284,7 @@ namespace GHelper
|
|||||||
if (action is null || action.Length <= 1)
|
if (action is null || action.Length <= 1)
|
||||||
{
|
{
|
||||||
if (name == "m4")
|
if (name == "m4")
|
||||||
action = "performance";
|
action = "ghelper";
|
||||||
if (name == "fnf4")
|
if (name == "fnf4")
|
||||||
action = "aura";
|
action = "aura";
|
||||||
}
|
}
|
||||||
@@ -338,7 +369,7 @@ namespace GHelper
|
|||||||
|
|
||||||
static void TrayIcon_MouseClick(object? sender, MouseEventArgs e)
|
static void TrayIcon_MouseClick(object? sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
|
if (e.Button == MouseButtons.Left)
|
||||||
{
|
{
|
||||||
SettingsToggle();
|
SettingsToggle();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ namespace GHelper
|
|||||||
public partial class SettingsForm : RForm
|
public partial class SettingsForm : RForm
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private ContextMenuStrip contextMenuStrip = new CustomContextMenu();
|
||||||
|
private ToolStripMenuItem menuSilent, menuBalanced, menuTurbo;
|
||||||
|
|
||||||
public static System.Timers.Timer aTimer = default!;
|
public static System.Timers.Timer aTimer = default!;
|
||||||
public static Point trayPoint;
|
public static Point trayPoint;
|
||||||
|
|
||||||
@@ -140,6 +143,8 @@ namespace GHelper
|
|||||||
|
|
||||||
this.TopMost = Program.config.getConfig("topmost") == 1;
|
this.TopMost = Program.config.getConfig("topmost") == 1;
|
||||||
|
|
||||||
|
SetContextMenu();
|
||||||
|
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await Task.Delay(TimeSpan.FromSeconds(1));
|
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||||
@@ -147,6 +152,46 @@ namespace GHelper
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetContextMenu()
|
||||||
|
{
|
||||||
|
|
||||||
|
Padding padding = new Padding(5, 5, 5, 5);
|
||||||
|
|
||||||
|
var menuTitle = new ToolStripMenuItem(Properties.Strings.PerformanceMode);
|
||||||
|
menuTitle.Margin = padding;
|
||||||
|
menuTitle.Enabled = false;
|
||||||
|
contextMenuStrip.Items.Add(menuTitle);
|
||||||
|
|
||||||
|
menuSilent = new ToolStripMenuItem(Properties.Strings.Silent);
|
||||||
|
menuSilent.Click += ButtonSilent_Click;
|
||||||
|
menuSilent.Margin = padding;
|
||||||
|
contextMenuStrip.Items.Add(menuSilent);
|
||||||
|
|
||||||
|
menuBalanced = new ToolStripMenuItem(Properties.Strings.Balanced);
|
||||||
|
menuBalanced.Click += ButtonBalanced_Click;
|
||||||
|
menuBalanced.Margin = padding;
|
||||||
|
contextMenuStrip.Items.Add(menuBalanced);
|
||||||
|
|
||||||
|
menuTurbo = new ToolStripMenuItem(Properties.Strings.Turbo);
|
||||||
|
menuTurbo.Click += ButtonTurbo_Click;
|
||||||
|
menuTurbo.Checked = true;
|
||||||
|
menuTurbo.Margin = padding;
|
||||||
|
contextMenuStrip.Items.Add(menuTurbo);
|
||||||
|
|
||||||
|
contextMenuStrip.ShowCheckMargin = true;
|
||||||
|
contextMenuStrip.RenderMode = ToolStripRenderMode.System;
|
||||||
|
|
||||||
|
if (CheckSystemDarkModeStatus())
|
||||||
|
{
|
||||||
|
contextMenuStrip.BackColor = this.BackColor;
|
||||||
|
contextMenuStrip.ForeColor = this.ForeColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
Program.trayIcon.ContextMenuStrip = contextMenuStrip;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonXGM_Click(object? sender, EventArgs e)
|
private void ButtonXGM_Click(object? sender, EventArgs e)
|
||||||
@@ -291,7 +336,7 @@ namespace GHelper
|
|||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Logger.WriteLine("Monitor Power On");
|
Logger.WriteLine("Monitor Power On");
|
||||||
Program.SetAutoModes(false);
|
Program.SetAutoModes();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
Logger.WriteLine("Monitor Dimmed");
|
Logger.WriteLine("Monitor Dimmed");
|
||||||
@@ -1029,18 +1074,25 @@ namespace GHelper
|
|||||||
buttonBalanced.Activated = false;
|
buttonBalanced.Activated = false;
|
||||||
buttonTurbo.Activated = false;
|
buttonTurbo.Activated = false;
|
||||||
|
|
||||||
|
menuSilent.Checked = false;
|
||||||
|
menuBalanced.Checked = false;
|
||||||
|
menuTurbo.Checked = false;
|
||||||
|
|
||||||
switch (PerformanceMode)
|
switch (PerformanceMode)
|
||||||
{
|
{
|
||||||
case ASUSWmi.PerformanceSilent:
|
case ASUSWmi.PerformanceSilent:
|
||||||
buttonSilent.Activated = true;
|
buttonSilent.Activated = true;
|
||||||
|
menuSilent.Checked = true;
|
||||||
perfName = Properties.Strings.Silent;
|
perfName = Properties.Strings.Silent;
|
||||||
break;
|
break;
|
||||||
case ASUSWmi.PerformanceTurbo:
|
case ASUSWmi.PerformanceTurbo:
|
||||||
buttonTurbo.Activated = true;
|
buttonTurbo.Activated = true;
|
||||||
|
menuTurbo.Checked = true;
|
||||||
perfName = Properties.Strings.Turbo;
|
perfName = Properties.Strings.Turbo;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
buttonBalanced.Activated = true;
|
buttonBalanced.Activated = true;
|
||||||
|
menuBalanced.Checked = true;
|
||||||
PerformanceMode = ASUSWmi.PerformanceBalanced;
|
PerformanceMode = ASUSWmi.PerformanceBalanced;
|
||||||
perfName = Properties.Strings.Balanced;
|
perfName = Properties.Strings.Balanced;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user