Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenTao committed Apr 26, 2018
2 parents 4b06afe + b6081d7 commit 587e607
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 70 deletions.
2 changes: 1 addition & 1 deletion EarTrumpet.UWP/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap desktop">
<Identity Name="40459File-New-Project.EarTrumpet" ProcessorArchitecture="x86" Publisher="CN=6099D0EF-9374-47ED-BDFE-A82136831235" Version="1.5.2.0" />
<Identity Name="40459File-New-Project.EarTrumpet" ProcessorArchitecture="x86" Publisher="CN=6099D0EF-9374-47ED-BDFE-A82136831235" Version="1.5.3.0" />
<Properties>
<DisplayName>EarTrumpet</DisplayName>
<PublisherDisplayName>File-New-Project</PublisherDisplayName>
Expand Down
15 changes: 12 additions & 3 deletions EarTrumpet/Extensions/BlurWindowExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ internal struct AccentPolicy
{
public AccentState AccentState;
public AccentFlags AccentFlags;
public int GradientColor;
public int AnimationId;
public uint GradientColor;
public uint AnimationId;
}

[Flags]
Expand Down Expand Up @@ -55,18 +55,21 @@ internal enum AccentState
ACCENT_ENABLE_GRADIENT = 1,
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
ACCENT_ENABLE_BLURBEHIND = 3,
ACCENT_ENABLE_ACRYLICBLURBEHIND = 4, // RS4
ACCENT_INVALID_STATE = 4
}
}

private static bool _isRunningOnRs4OrHigher = Environment.OSVersion.Version.Build >= 17134;

public static void EnableBlur(this Window window)
{
if (SystemParameters.HighContrast)
{
return; // Blur is not useful in high contrast mode
}

SetAccentPolicy(window, Interop.AccentState.ACCENT_ENABLE_BLURBEHIND);
SetAccentPolicy(window, (_isRunningOnRs4OrHigher ? Interop.AccentState.ACCENT_ENABLE_ACRYLICBLURBEHIND : Interop.AccentState.ACCENT_ENABLE_BLURBEHIND));
}

public static void DisableBlur(this Window window)
Expand All @@ -82,6 +85,12 @@ private static void SetAccentPolicy(Window window, Interop.AccentState accentSta
accent.AccentState = accentState;
accent.AccentFlags = GetAccentFlagsForTaskbarPosition();

if (_isRunningOnRs4OrHigher)
{
// A B G R
accent.GradientColor = 0x2A_00_00_00;
}

var accentStructSize = Marshal.SizeOf(accent);

var accentPtr = Marshal.AllocHGlobal(accentStructSize);
Expand Down
4 changes: 2 additions & 2 deletions EarTrumpet/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.5.1.0")]
[assembly: AssemblyFileVersion("1.5.1.0")]
[assembly: AssemblyVersion("1.5.3.0")]
[assembly: AssemblyFileVersion("1.5.3.0")]
[assembly: ComVisible(false)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
25 changes: 24 additions & 1 deletion EarTrumpet/Services/EarTrumpetAudioDeviceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Timers;

namespace EarTrumpet.Services
{
Expand Down Expand Up @@ -37,6 +38,14 @@ static class Interop
public static extern int RegisterVolumeChangeCallback(IEarTrumpetVolumeCallback callback);
}

private bool _dropEvents = false;
private readonly Timer _dropEventsTimer;

private void DropEventsTimerElapsed(object sender, ElapsedEventArgs e)
{
_dropEvents = false;
}

public sealed class MasterVolumeChangedArgs
{
public float Volume { get; set; }
Expand All @@ -46,6 +55,12 @@ public sealed class MasterVolumeChangedArgs

public EarTrumpetAudioDeviceService()
{
_dropEventsTimer = new Timer(TimeSpan.FromSeconds(3).TotalMilliseconds)
{
AutoReset = false
};
_dropEventsTimer.Elapsed += DropEventsTimerElapsed;

Interop.RegisterVolumeChangeCallback(this);
}

Expand Down Expand Up @@ -83,8 +98,13 @@ public float GetAudioDeviceVolume(string deviceId)

return volume;
}

public void SetAudioDeviceVolume(string deviceId, float volume)
{
_dropEvents = true;
_dropEventsTimer.Stop();
_dropEventsTimer.Start();

Interop.SetAudioDeviceVolume(deviceId, volume);
}

Expand All @@ -105,7 +125,10 @@ public void OnVolumeChanged(float volume)

protected virtual void OnMasterVolumeChanged(MasterVolumeChangedArgs args)
{
MasterVolumeChanged?.Invoke(this, args);
if (!_dropEvents)
{
MasterVolumeChanged?.Invoke(this, args);
}
}
}
}
60 changes: 2 additions & 58 deletions EarTrumpet/Services/TaskbarService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,10 @@ public sealed class TaskbarService

public static TaskbarState GetWinTaskbarState()
{
APPBARDATA ABD = new APPBARDATA();
TaskbarState retState = new TaskbarState();
var hwnd = User32.FindWindow(ClassName, null);

ABD.cbSize = Marshal.SizeOf(ABD);
ABD.uEdge = 0;
ABD.hWnd = hwnd;
ABD.lParam = 1;

User32.GetWindowRect(hwnd, out RECT scaledTaskbarRect);

var taskbarNonDPIAwareSize = Shell32.SHAppBarMessage((int)ABMsg.ABM_GETTASKBARPOS, ref ABD);

var scalingAmount = (double)(scaledTaskbarRect.bottom - scaledTaskbarRect.top) / (ABD.rc.bottom - ABD.rc.top);

retState.TaskbarSize = default(RECT);
retState.TaskbarSize.top = (int)(ABD.rc.top * scalingAmount);
retState.TaskbarSize.bottom = (int)(ABD.rc.bottom * scalingAmount);
retState.TaskbarSize.left = (int)(ABD.rc.left * scalingAmount);
retState.TaskbarSize.right = (int)(ABD.rc.right * scalingAmount);
User32.GetWindowRect(hwnd, out retState.TaskbarSize);

var screen = Screen.AllScreens.FirstOrDefault(x => x.Bounds.Contains(
new Rectangle(
Expand All @@ -56,7 +40,7 @@ public static TaskbarState GetWinTaskbarState()
}

return retState;
}
}
}

public static class User32
Expand All @@ -77,46 +61,6 @@ public struct RECT
public int bottom;
}

public static class Shell32
{
[DllImport("shell32.dll")]
public static extern IntPtr SHAppBarMessage(uint dwMessage, [In] ref APPBARDATA pData);
}

[StructLayout(LayoutKind.Sequential)]
public struct APPBARDATA
{
public int cbSize; // initialize this field using: Marshal.SizeOf(typeof(APPBARDATA));
public IntPtr hWnd;
public uint uCallbackMessage;
public uint uEdge;
public RECT rc;
public int lParam;
}

public enum ABMsg
{
ABM_NEW = 0,
ABM_REMOVE,
ABM_QUERYPOS,
ABM_SETPOS,
ABM_GETSTATE,
ABM_GETTASKBARPOS,
ABM_ACTIVATE,
ABM_GETAUTOHIDEBAR,
ABM_SETAUTOHIDEBAR,
ABM_WINDOWPOSCHANGED,
ABM_SETSTATE
}

public enum ABEdge
{
ABE_LEFT = 0,
ABE_TOP = 1,
ABE_RIGHT = 2,
ABE_BOTTOM = 3
}

[StructLayout(LayoutKind.Sequential)]
public struct TaskbarState
{
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
![Ear Trumpet Screenshot](https://raw.githubusercontent.com/File-New-Project/EarTrumpet/dev/Graphics/screenshot.png)

## Supported operating systems ##
- Windows 10
- Windows 10 November Update
- Windows 10 Anniversary Update
- Windows 10 Creators Update
- Windows 10 Fall Creators Update
- Windows 10 1507
- Windows 10 1511 (November Update)
- Windows 10 1607 (Anniversary Update)
- Windows 10 1703 (Creators Update)
- Windows 10 1709 (Fall Creators Update)
- Windows 10 1803

## Known issues ##
- Skype appears to have multiple audio sessions but only one is active ([#42](https://github.com/File-New-Project/EarTrumpet/issues/42))
- Netflix audio control is inconsistent ([#34](https://github.com/File-New-Project/EarTrumpet/issues/34))
- SoundCloud audio cannot be adjusted ([#178](https://github.com/File-New-Project/EarTrumpet/issues/178))

## Credits ##
- David Golden (@GoldenTao)
- Rafael Rivera (@WithinRafael)
- Dave Amenta (@davux)
- [Contributors](https://github.com/File-New-Project/EarTrumpet/graphs/contributors)

0 comments on commit 587e607

Please sign in to comment.