Skip to content

Commit

Permalink
apply aero glass on win 7/8/8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
xupefei committed May 16, 2017
1 parent fd080f8 commit 13d6edd
Show file tree
Hide file tree
Showing 22 changed files with 565 additions and 69 deletions.
67 changes: 0 additions & 67 deletions QuickLook/Helpers/AeroGlassHelper.cs

This file was deleted.

59 changes: 59 additions & 0 deletions QuickLook/Helpers/BlurLibrary/BlurWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Windows;

namespace QuickLook.Helpers.BlurLibrary
{
public static class BlurWindow
{
private static readonly IWindowBlurController BlurController;

static BlurWindow()
{
BlurController = Helpers.GetWindowControllerForOs(OsHelper.GetOsType());
}

/// <summary>
/// Current blur state
/// </summary>
public static bool Enabled => BlurController.Enabled;

/// <summary>
/// Checks if blur can be enabled.
/// </summary>
public static bool CanBeEnabled => BlurController.CanBeEnabled;

private static void EnableWindowBlur(IntPtr hwnd)
{
if (!CanBeEnabled)
return;

BlurController.EnableBlur(hwnd);
}

/// <summary>
/// Enable blur for window
/// </summary>
/// <param name="window">Window object</param>
public static void EnableWindowBlur(Window window)
{
EnableWindowBlur(Helpers.GetWindowHandle(window));
}

private static void DisableWindowBlur(IntPtr hwnd)
{
if (!CanBeEnabled)
return;

BlurController.DisableBlur(hwnd);
}

/// <summary>
/// Disable blur for window
/// </summary>
/// <param name="window">Window object</param>
public static void DisableWindowBlur(Window window)
{
DisableWindowBlur(Helpers.GetWindowHandle(window));
}
}
}
36 changes: 36 additions & 0 deletions QuickLook/Helpers/BlurLibrary/Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Windows;
using System.Windows.Interop;
using QuickLook.Helpers.BlurLibrary.PlatformsImpl;

namespace QuickLook.Helpers.BlurLibrary
{
internal static class Helpers
{
internal static IWindowBlurController GetWindowControllerForOs(OsType osType)
{
switch (osType)
{
case OsType.WindowsVista:
return new WindowsVistaWindowBlurController();
case OsType.Windows7:
return new Windows7WindowBlurController();
case OsType.Windows8:
return new Windows8WindowBlurController();
case OsType.Windows81:
return new Windows81WindowBlurController();
case OsType.Windows10:
return new Windows10WindowBlurController();
case OsType.Other:
return new OsNotSupportedWindowBlurController();
default:
return new OsNotSupportedWindowBlurController();
}
}

internal static IntPtr GetWindowHandle(Window window)
{
return new WindowInteropHelper(window).Handle;
}
}
}
31 changes: 31 additions & 0 deletions QuickLook/Helpers/BlurLibrary/IWindowBlurController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;

namespace QuickLook.Helpers.BlurLibrary
{
internal interface IWindowBlurController
{
/// <summary>
/// Current blur state
/// </summary>
bool Enabled { get; }

/// <summary>
/// Checks if blur can be enabled.
/// </summary>
bool CanBeEnabled { get; }

/// <summary>
/// Enable blur for window
/// </summary>
/// <param name="hwnd">Pointer to Window</param>
/// <exception cref="NotImplementedException">Throws when blur is not supported.</exception>
void EnableBlur(IntPtr hwnd);

/// <summary>
/// Disable blur for window
/// </summary>
/// <param name="hwnd">Pointer to Window</param>
/// <exception cref="NotImplementedException">Throws when blur is not supported.</exception>
void DisableBlur(IntPtr hwnd);
}
}
9 changes: 9 additions & 0 deletions QuickLook/Helpers/BlurLibrary/NativeThings/NativeMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Security;

namespace QuickLook.Helpers.BlurLibrary.NativeThings
{
[SuppressUnmanagedCodeSecurity]
internal static class NativeMethods
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Runtime.InteropServices;

namespace QuickLook.Helpers.BlurLibrary.NativeThings.Windows10
{
[StructLayout(LayoutKind.Sequential)]
internal struct AccentPolicy
{
public AccentState AccentState;
public int AccentFlags;
public int GradientColor;
public int AnimationId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// ReSharper disable InconsistentNaming

namespace QuickLook.Helpers.BlurLibrary.NativeThings.Windows10
{
internal enum AccentState
{
ACCENT_DISABLED = 0,
ACCENT_ENABLE_GRADIENT = 1,
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
ACCENT_ENABLE_BLURBEHIND = 3,
ACCENT_INVALID_STATE = 4
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Runtime.InteropServices;

// ReSharper disable once CheckNamespace

namespace QuickLook.Helpers.BlurLibrary.NativeThings.Windows10
{
internal static class NativeMethods
{
[DllImport("user32.dll")]
public static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace QuickLook.Helpers.BlurLibrary.NativeThings.Windows10
{
internal enum WindowCompositionAttribute
{
// ...
WCA_ACCENT_POLICY = 19
// ...
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Runtime.InteropServices;

namespace QuickLook.Helpers.BlurLibrary.NativeThings.Windows10
{
[StructLayout(LayoutKind.Sequential)]
internal struct WindowCompositionAttributeData
{
public WindowCompositionAttribute Attribute;
public IntPtr Data;
public int SizeOfData;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Runtime.InteropServices;

// ReSharper disable FieldCanBeMadeReadOnly.Global
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable InconsistentNaming
// ReSharper disable UnusedMember.Global
// ReSharper disable once CheckNamespace

namespace QuickLook.Helpers.BlurLibrary.NativeThings.WindowsVistaAnd7
{
internal static class NativeMethods
{
[Flags]
public enum DWM_BB
{
DWM_BB_ENABLE = 1,
DWM_BB_BLURREGION = 2,
DWM_BB_TRANSITIONONMAXIMIZED = 4
}

public const int WM_DWMCOMPOSITIONCHANGED = 0x031E;

[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern bool DwmIsCompositionEnabled();

[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmEnableBlurBehindWindow(IntPtr hwnd, ref DWM_BLURBEHIND blurBehind);

[DllImport("dwmapi.dll")]
public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMargins);

[StructLayout(LayoutKind.Sequential)]
public struct DWM_BLURBEHIND
{
public DWM_BB dwFlags;
public bool fEnable;
public IntPtr hRgnBlur;
public bool fTransitionOnMaximized;
}

[StructLayout(LayoutKind.Sequential)]
public struct MARGINS
{
public int cxLeftWidth;
public int cxRightWidth;
public int cyTopHeight;
public int cyBottomHeight;
}
}
}
32 changes: 32 additions & 0 deletions QuickLook/Helpers/BlurLibrary/OsHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;

namespace QuickLook.Helpers.BlurLibrary
{
internal static class OsHelper
{
public static OsType GetOsType()
{
if (Environment.OSVersion.Version.Major != 6 && Environment.OSVersion.Version.Major != 10)
return OsType.Other;

if (Environment.OSVersion.Version.Major != 6)
return Environment.OSVersion.Version.Major == 10
? OsType.Windows10
: OsType.Other;

switch (Environment.OSVersion.Version.Minor)
{
case 0:
return OsType.WindowsVista;
case 1:
return OsType.Windows7;
case 2:
return OsType.Windows8;
case 3:
return OsType.Windows81;
default:
return OsType.Other;
}
}
}
}
12 changes: 12 additions & 0 deletions QuickLook/Helpers/BlurLibrary/OsType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace QuickLook.Helpers.BlurLibrary
{
internal enum OsType
{
WindowsVista,
Windows7,
Windows8,
Windows81,
Windows10,
Other
}
}
Loading

0 comments on commit 13d6edd

Please sign in to comment.