Some OSD notifications

This commit is contained in:
Serge
2023-05-20 21:51:02 +02:00
parent 09e6676b7c
commit 9f56959c67
10 changed files with 115 additions and 35 deletions

View File

@@ -1,6 +1,5 @@
using Microsoft.Win32; using Microsoft.Win32;
using NAudio.CoreAudioApi; using NAudio.CoreAudioApi;
using OSD;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Management; using System.Management;
@@ -265,7 +264,7 @@ namespace GHelper
var commDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications); var commDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications);
bool muteStatus = !commDevice.AudioEndpointVolume.Mute; bool muteStatus = !commDevice.AudioEndpointVolume.Mute;
commDevice.AudioEndpointVolume.Mute = muteStatus; commDevice.AudioEndpointVolume.Mute = muteStatus;
settingsForm.BeginInvoke(settingsForm.RunToast, muteStatus ? "Mic Muted" : "Mic Unmuted"); settingsForm.BeginInvoke(settingsForm.RunToast, muteStatus ? "Muted" : "Unmuted", ToastIcon.Microphone);
} }
break; break;
@@ -324,25 +323,25 @@ namespace GHelper
brightness = Math.Max(0, brightness - 1); brightness = Math.Max(0, brightness - 1);
config.setConfig("keyboard_brightness", brightness); config.setConfig("keyboard_brightness", brightness);
AsusUSB.ApplyBrightness(brightness); AsusUSB.ApplyBrightness(brightness);
settingsForm.BeginInvoke(settingsForm.RunToast, "Backlight -"); settingsForm.BeginInvoke(settingsForm.RunToast, "Down", ToastIcon.Backlight);
break; break;
case 196: // FN+F3 case 196: // FN+F3
brightness = Math.Min(3, brightness + 1); brightness = Math.Min(3, brightness + 1);
config.setConfig("keyboard_brightness", brightness); config.setConfig("keyboard_brightness", brightness);
AsusUSB.ApplyBrightness(brightness); AsusUSB.ApplyBrightness(brightness);
settingsForm.BeginInvoke(settingsForm.RunToast, "Backlight +"); settingsForm.BeginInvoke(settingsForm.RunToast, "Up", ToastIcon.Backlight);
break; break;
case 16: // FN+F7 case 16: // FN+F7
ScreenBrightness.Adjust(-10); ScreenBrightness.Adjust(-10);
settingsForm.BeginInvoke(settingsForm.RunToast, "Brightness -"); settingsForm.BeginInvoke(settingsForm.RunToast, "Down", ToastIcon.Brightness);
break; break;
case 32: // FN+F8 case 32: // FN+F8
ScreenBrightness.Adjust(+10); ScreenBrightness.Adjust(+10);
settingsForm.BeginInvoke(settingsForm.RunToast, "Brightness +"); settingsForm.BeginInvoke(settingsForm.RunToast, "Up", ToastIcon.Brightness);
break; break;
case 107: // FN+F10 case 107: // FN+F10
AsusUSB.TouchpadToggle(); AsusUSB.TouchpadToggle();
settingsForm.BeginInvoke(settingsForm.RunToast, "Touchpad"); settingsForm.BeginInvoke(settingsForm.RunToast, "Toggle", ToastIcon.Touchpad);
break; break;
case 108: // FN+F11 case 108: // FN+F11
Application.SetSuspendState(PowerState.Suspend, true, true); Application.SetSuspendState(PowerState.Suspend, true, true);

View File

@@ -70,16 +70,6 @@ namespace GHelper.Properties {
} }
} }
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap everything_is_fine_itsfine {
get {
object obj = ResourceManager.GetObject("everything-is-fine-itsfine", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary> /// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap. /// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary> /// </summary>
@@ -100,6 +90,16 @@ namespace GHelper.Properties {
} }
} }
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap icons8_brightness_96 {
get {
object obj = ResourceManager.GetObject("icons8_brightness_96", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary> /// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap. /// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary> /// </summary>
@@ -230,6 +230,16 @@ namespace GHelper.Properties {
} }
} }
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap icons8_microphone_96 {
get {
object obj = ResourceManager.GetObject("icons8_microphone_96", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary> /// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap. /// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary> /// </summary>
@@ -330,6 +340,26 @@ namespace GHelper.Properties {
} }
} }
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap icons8_sunset_96 {
get {
object obj = ResourceManager.GetObject("icons8_sunset_96", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap icons8_touchpad_96 {
get {
object obj = ResourceManager.GetObject("icons8_touchpad_96", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary> /// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap. /// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary> /// </summary>

View File

@@ -133,9 +133,6 @@
<data name="icons8-fiat-500-48" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="icons8-fiat-500-48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-fiat-500-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\icons8-fiat-500-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="icons8-project-management-48 (1)" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-project-management-48 (1).png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-bicycle-48 (1)" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="icons8-bicycle-48 (1)" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-bicycle-48 (1).png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\icons8-bicycle-48 (1).png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
@@ -205,13 +202,25 @@
<data name="icons8-speed-48" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="icons8-speed-48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-speed-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\icons8-speed-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="everything-is-fine-itsfine" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\itsfine.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-help-64" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="icons8-help-64" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-help-64.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\icons8-help-64.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="icons8_video_48" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="icons8_video_48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-video-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\icons8-video-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="icons8-project-management-48 (1)" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-project-management-48 (1).png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8_brightness_96" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-brightness-96.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8_sunset_96" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-sunset-96.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8_microphone_96" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-microphone-96.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8_touchpad_96" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-touchpad-96.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root> </root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 784 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 B

View File

@@ -152,9 +152,9 @@ namespace GHelper
} }
public void RunToast(string text) public void RunToast(string text, ToastIcon? icon = null)
{ {
toast.RunToast(text); toast.RunToast(text, icon);
} }
public void SetContextMenu() public void SetContextMenu()

View File

@@ -1,4 +1,5 @@
using System.Diagnostics; using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using OSD; using OSD;
@@ -42,10 +43,20 @@ namespace GHelper
} }
} }
public enum ToastIcon
{
Brightness,
Backlight,
Touchpad,
Microphone
}
public class ToastForm : OSDNativeForm public class ToastForm : OSDNativeForm
{ {
protected static string toastText = "Balanced"; protected static string toastText = "Balanced";
protected static ToastIcon? toastIcon = null;
protected static System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); protected static System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
public ToastForm() public ToastForm()
@@ -64,18 +75,49 @@ namespace GHelper
format.LineAlignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center;
format.Alignment = StringAlignment.Center; format.Alignment = StringAlignment.Center;
Bitmap? icon = null;
switch (toastIcon)
{
case ToastIcon.Brightness:
icon = Properties.Resources.icons8_brightness_96;
break;
case ToastIcon.Backlight:
icon = Properties.Resources.icons8_sunset_96;
break;
case ToastIcon.Microphone:
icon = Properties.Resources.icons8_microphone_96;
break;
case ToastIcon.Touchpad:
icon = Properties.Resources.icons8_touchpad_96;
break;
}
int shiftX = 0;
if (icon is not null)
{
e.Graphics.DrawImage(icon, 18, 18, 64, 64);
shiftX = 40;
}
e.Graphics.DrawString(toastText, e.Graphics.DrawString(toastText,
new Font("Segoe UI", 16f, FontStyle.Bold), new Font("Segoe UI", 36f, FontStyle.Bold, GraphicsUnit.Pixel),
new SolidBrush(Color.White), new SolidBrush(Color.White),
new PointF(this.Bound.Width/2, this.Bound.Height / 2), new PointF(this.Bound.Width / 2 + shiftX, this.Bound.Height / 2),
format); format);
} }
public void RunToast(string text) public void RunToast(string text, ToastIcon? icon = null)
{ {
Hide(); Hide();
timer.Stop();
toastText = text; toastText = text;
toastIcon = icon;
Screen screen1 = Screen.FromHandle(base.Handle); Screen screen1 = Screen.FromHandle(base.Handle);
Width = 300; Width = 300;
@@ -84,15 +126,15 @@ namespace GHelper
Y = screen1.Bounds.Height - 300 - this.Height; Y = screen1.Bounds.Height - 300 - this.Height;
Show(); Show();
timer.Start();
timer.Enabled = true;
} }
private void timer_Tick(object? sender, EventArgs e) private void timer_Tick(object? sender, EventArgs e)
{ {
Debug.WriteLine("Toast end"); Debug.WriteLine("Toast end");
timer.Enabled = false;
Hide(); Hide();
timer.Stop();
} }
} }
} }