Refactoring blur

1. Refactoring blur, see discussion in : 7f8bb80
2. Releated issue: #330
This commit is contained in:
bao-qian
2015-11-29 06:29:32 +00:00
parent a8c6a97579
commit 38791e50ea
17 changed files with 131 additions and 163 deletions

View File

@@ -88,75 +88,5 @@ namespace Wox.Helper
public int Right;
public int Bottom;
}
#region Blur Handling
/*
Found on https://github.com/riverar/sample-win10-aeroglass
*/
public enum AccentState
{
ACCENT_DISABLED = 0,
ACCENT_ENABLE_GRADIENT = 1,
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
ACCENT_ENABLE_BLURBEHIND = 3,
ACCENT_INVALID_STATE = 4
}
[StructLayout(LayoutKind.Sequential)]
internal struct AccentPolicy
{
public AccentState AccentState;
public int AccentFlags;
public int GradientColor;
public int AnimationId;
}
[StructLayout(LayoutKind.Sequential)]
internal struct WindowCompositionAttributeData
{
public WindowCompositionAttribute Attribute;
public IntPtr Data;
public int SizeOfData;
}
internal enum WindowCompositionAttribute
{
WCA_ACCENT_POLICY = 19
}
[DllImport("user32.dll")]
private static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
/// <summary>
/// Sets the blur for a window via SetWindowCompositionAttribute
/// </summary>
/// <param name="wind">window to blur</param>
/// <param name="status">true/false - on or off correspondingly</param>
public static void SetBlurForWindow(Window wind, bool status)
{
SetWindowAccent(wind, status ? AccentState.ACCENT_ENABLE_BLURBEHIND : AccentState.ACCENT_DISABLED);
}
private static void SetWindowAccent(Window wind, AccentState themeAccentMode)
{
var windowHelper = new WindowInteropHelper(wind);
var accent = new AccentPolicy();
accent.AccentState = themeAccentMode;
var accentStructSize = Marshal.SizeOf(accent);
var accentPtr = Marshal.AllocHGlobal(accentStructSize);
Marshal.StructureToPtr(accent, accentPtr, false);
var data = new WindowCompositionAttributeData();
data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY;
data.SizeOfData = accentStructSize;
data.Data = accentPtr;
SetWindowCompositionAttribute(windowHelper.Handle, ref data);
Marshal.FreeHGlobal(accentPtr);
}
#endregion
}
}