Skip to content

Commit

Permalink
overlay next to systray
Browse files Browse the repository at this point in the history
  • Loading branch information
bengnomino committed Mar 23, 2024
1 parent 943718c commit 6d82591
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 166 deletions.
13 changes: 10 additions & 3 deletions HideVolumeOSD.sln
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32929.386
# Visual Studio Version 17
VisualStudioVersion = 17.9.34714.143
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HideVolumeOSDApp", "HideVolumeOSD\HideVolumeOSDApp.csproj", "{F317AF2E-9704-4A2A-BDAE-B4662ED9483B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F317AF2E-9704-4A2A-BDAE-B4662ED9483B}.Debug|Any CPU.ActiveCfg = Debug|x86
{F317AF2E-9704-4A2A-BDAE-B4662ED9483B}.Debug|x64.ActiveCfg = Debug|x64
{F317AF2E-9704-4A2A-BDAE-B4662ED9483B}.Debug|x64.Build.0 = Debug|x64
{F317AF2E-9704-4A2A-BDAE-B4662ED9483B}.Debug|x86.ActiveCfg = Debug|x86
{F317AF2E-9704-4A2A-BDAE-B4662ED9483B}.Debug|x86.Build.0 = Debug|x86
{F317AF2E-9704-4A2A-BDAE-B4662ED9483B}.Release|Any CPU.ActiveCfg = Release|x86
{F317AF2E-9704-4A2A-BDAE-B4662ED9483B}.Release|Any CPU.ActiveCfg = Release|x64
{F317AF2E-9704-4A2A-BDAE-B4662ED9483B}.Release|Any CPU.Build.0 = Release|x64
{F317AF2E-9704-4A2A-BDAE-B4662ED9483B}.Release|x64.ActiveCfg = Release|x64
{F317AF2E-9704-4A2A-BDAE-B4662ED9483B}.Release|x64.Build.0 = Release|x64
{F317AF2E-9704-4A2A-BDAE-B4662ED9483B}.Release|x86.ActiveCfg = Release|x86
{F317AF2E-9704-4A2A-BDAE-B4662ED9483B}.Release|x86.Build.0 = Release|x86
EndGlobalSection
Expand Down
2 changes: 1 addition & 1 deletion HideVolumeOSD/AboutBox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 76 additions & 28 deletions HideVolumeOSD/HideVolumeOSDLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
using System.ComponentModel;

namespace HideVolumeOSD
{
Expand Down Expand Up @@ -63,7 +65,7 @@ private struct RECT
public int bottom;
}

[DllImport("Shell32.dll", SetLastError = true)]
[DllImport("Shell32.dll", SetLastError = true)]
private static extern Int32 Shell_NotifyIconGetRect([In] ref NOTIFYICONIDENTIFIER identifier, [Out] out RECT iconLocation);

NotifyIcon notifyIcon;
Expand All @@ -82,8 +84,47 @@ public HideVolumeOSDLib(NotifyIcon ni)
this.notifyIcon = ni;
}
}
public static Rectangle GetTaskbarPosition()
{
var data = new APPBARDATA();
data.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(data);
IntPtr retval = SHAppBarMessage(ABM_GETTASKBARPOS, ref data);
if (retval == IntPtr.Zero) throw new Win32Exception("Please re-install Windows");
return new Rectangle(data.rc.left, data.rc.top,
data.rc.right - data.rc.left, data.rc.bottom - data.rc.top);

}
private const int ABM_GETTASKBARPOS = 5;
[System.Runtime.InteropServices.DllImport("shell32.dll")]
private static extern IntPtr SHAppBarMessage(int msg, ref APPBARDATA data);
private struct APPBARDATA
{
public int cbSize;
public IntPtr hWnd;
public int uCallbackMessage;
public int uEdge;
public RECT rc;
public IntPtr lParam;
}

public void Init()
public const int TaskbarWidthCheckTrigger = 250;

static public AnchorStyles GetTaskbarAnchorStyle()
{
var coordonates = GetTaskbarPosition();
if (coordonates.Left == 0 && coordonates.Top == 0)
if (coordonates.Width > TaskbarWidthCheckTrigger)
return AnchorStyles.Top;
else
return AnchorStyles.Left;
else
if (coordonates.Width > TaskbarWidthCheckTrigger)
return AnchorStyles.Bottom;
else
return AnchorStyles.Right;
}

public void Init()
{
hWndInject = FindOSDWindow(true);

Expand Down Expand Up @@ -317,38 +358,30 @@ public void ShowMessage(String message, ToolTipIcon icon)
}
}

public void showVolumeWindow(bool bShow)
public void showVolumeWindow(bool bShow)
{
if (bShow)
{
RECT rect = new RECT();

bool bOverIcon = false;
RECT rcDesktop = new RECT();
SystemParametersInfo(SPI_GETWORKAREA, IntPtr.Zero, out rcDesktop, IntPtr.Zero);

if (Shell_NotifyIconGetRect(ref notifyIconIdentifier, out rect) != 0 || Settings.Default.VolumeDisplayNearClock)
{
RECT rcDesktop = new RECT();
SystemParametersInfo(SPI_GETWORKAREA, IntPtr.Zero, out rcDesktop, IntPtr.Zero);
int cx = GetSystemMetrics(SM_CXSCREEN);
int cy = GetSystemMetrics(SM_CYSCREEN);

int cx = GetSystemMetrics(SM_CXSCREEN);
int cy = GetSystemMetrics(SM_CYSCREEN);
int taskBarHeight = cy - rcDesktop.bottom;

int taskBarHeight = cy - rcDesktop.bottom;
rect.left = (int)(cx - taskBarHeight * 1.8);
rect.right = cx;

rect.left = (int)(cx - taskBarHeight * 1.8);
rect.right = cx;
rect.top = rcDesktop.bottom;
rect.bottom = cy;

rect.top = rcDesktop.bottom;
rect.bottom = cy;
}
else
{
bOverIcon = true;
}

int height = rect.bottom - rect.top;
int height = 60;

switch (Settings.Default.VolumeDisplaySize)
switch (Settings.Default.VolumeDisplaySize)
{
case 0:

Expand All @@ -366,15 +399,30 @@ public void showVolumeWindow(bool bShow)
break;
}

int width = (int)(height * 1.8);
int width = (int)(height * 1.8);

volumePopup.Show();
volumePopup.Show();
volumePopup.Size = new Size(width, height);

if (bOverIcon)
volumePopup.Location = new Point(rect.left + (rect.right - rect.left) / 2 - width / 2, rect.top + (rect.bottom - rect.top) / 2 - height / 2);
else
volumePopup.Location = new Point(rect.right - width - Settings.Default.VolumeDisplayOffset, rect.top + (rect.bottom - rect.top) / 2 - height / 2);
var anchor = GetTaskbarAnchorStyle();
var area = SystemInformation.WorkingArea;
var padding = 10;

switch (anchor)
{
case AnchorStyles.Top:
volumePopup.Location = new Point(area.Left + area.Width - width - padding, area.Top + padding);
break;
case AnchorStyles.Bottom:
volumePopup.Location = new Point(area.Left + area.Width - width - padding, area.Top + area.Height - height - padding);
break;
case AnchorStyles.Left:
volumePopup.Location = new Point(area.Left + padding, area.Top + padding);
break;
case AnchorStyles.Right:
volumePopup.Location = new Point(area.Left + area.Width - width - padding, area.Top + padding);
break;
}
}
else
{
Expand Down
36 changes: 6 additions & 30 deletions HideVolumeOSD/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions HideVolumeOSD/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,16 @@
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="VolumeInSystemTray" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="VolumeHideDelay" Type="System.Int32" Scope="User">
<Value Profile="(Default)">600</Value>
</Setting>
<Setting Name="VolumeDisplaySize" Type="System.Int32" Scope="User">
<Value Profile="(Default)">1</Value>
</Setting>
<Setting Name="VolumeDisplayNearClock" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="VolumeDisplayLight" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="VolumeDisplayOffset" Type="System.Int32" Scope="User">
<Value Profile="(Default)">32</Value>
</Setting>
</Settings>
</SettingsFile>
Loading

0 comments on commit 6d82591

Please sign in to comment.